Make Your Own Home TV Station That Only Plays What You Want

Make Your Own Home TV Station That Only Plays What You Want
This post contains affiliate links, which means I earn money from purchases. This never affects the price that you pay but helps with costs to keep the site up and running.

I want to start by saying that this project isn’t specific to The Office. It will work for any TV show or movies you want to use.

As the biggest fan of The Office in the world, my use case is The Office. The first 7 seasons are the greatest show of all time!

I can’t have a conversation without thinking of a reference to The Office because of a random word they used. It’s a real problem when I’m at work or in other professional settings.

My wife and I have taken a vacation to Scranton, PA just to see the places and businesses that the show was based on. I even started TheDundies.com because other quote sites weren’t good enough. We really love The Office.

We have been paying $13.99 per month to Netflix for the last million years so that we could play The Office 24 hours a day, 7 days a week.

If we are not busy, we actually watch the show. My wife and I find something new with every rewatch. When we are busy doing something else, it is almost always just playing in the background. Im 100% certain that this is the case with many fans of The Office.

On January 1st of 2021, Netflix removed The Office from its library in the United States. It has moved to a new NBC streaming service named Peacock.

Netflix had a few minor annoyances but it was always there and the quality was good. Now I needed a replacement…

One option was to buy the DVD set, but who wants to swap out 38 DVDs just to get through the whole series? Not me.

It would be a lot easier if ripping DVDs protected by DRM wasn’t illegal. I could build something super cool if I just had the files for every episode.

The rest of this article will cover what I would do if it were legal to use something like MakeMKV or Handbrake to rip the content from DRM protected DVDs that you owned.

Feel free to use my code and tutorial for your own home movies or videos that are not protected by DRM.


How To Build Your Own Home TV Station

One of the things I dislike about watching a series on Netflix (or other streaming services) is the “Are You Still Watching?” prompt. It’s annoying. I decided I didn’t want to do that so I made a small list of requirements for this project.

  • Use media from USB drive or NAS.
  • Infinitely loop all files in a certain directory.
  • Start playing as soon as it turns on.
  • Ability to add files to directory and they are added to playlist on the next loop.
  • Easy to deploy to every TV in my house.

Parts Used For This Project

Here is a list of all the parts you’ll need if you want to build one of these for your non-DRM protected video files.

Part/LinkComment
Raspberry Pi 4 4GBThis kit comes with an SD card, power supply and a micro HDMI to HDMI cable for connecting to your TV. You don’t need the 4GB version but it’s only a few bucks more than the 2GB version. Occasionally it goes on sale for the same price. It’s worth buying for the extra RAM but definitely not needed. I have mine running on an old Raspberry Pi 3b.
SanDisk 256GB USB Type-C Flash DriveThe size is really up to you. It depends what videos you are putting on your home TV station but this size worked for me. This part is also optional if you already have a network attached storage device.

Getting Started

These instructions assume that you already have Raspberry Pi OS installed on the SD card and that you have a USB drive or NAS configured as external storage.

Now that you are all setup, it’s time to run some commands to install what I’ve named PinfiniTV.


Installing PinfiniTV

Pi + Infinite Loop + TV = PinfiniTV

If you just want me to do the work for you, SSH to the Raspberry Pi and copy/paste the following command into your terminal as root.

This will install PinfiniTV for you. The install script is located at https://github.com/tynick/PinfiniTV/blob/master/install.sh. You should check it out.

wget -q -O -  https://raw.githubusercontent.com/tynick/PinfiniTV/master/install.sh | bash

I’m going to quickly run through how to manually install PinfiniTV. The script will do all this for you but it’s subject to changes and fixes so check the repository for the most current version.

Here are the manual install instructions to be run as the root user.

First we set the git repo url and the location we want to install PinfiniTV to.

GIT_URL='https://github.com/tynick/PinfiniTV.git'
INSTALL_PATH='/root/PinfiniTV'

Now we install our dependencies and PinfiniTV.

apt-get update -y && apt-get install -y git omxplayer || exit 1
git clone "${GIT_URL}" "${INSTALL_PATH}"

The last step of the install is to add a cron job to start the player when we boot. Then reboot to get the show started.

echo '@reboot root /root/PinfiniTV/run.sh' > /etc/cron.d/pinfinitv

With that cron job in place, you can now reboot your Raspberry Pi. The videos should begin auto playing as soon as it has finished booting.

reboot

How PinfiniTV Works

PinfiniTV is a pretty simple bash script right now. If it becomes popular I am happy to continue expanding it.

You can locate the most current version of the PinfiniTV run script at https://github.com/tynick/PinfiniTV/blob/master/run.sh.

#!/bin/bash

# base directory where all videos are stored
# this could be a USB drive, SD card or even a NAS
# videos will be sorted alphabetically 
VIDEO_DIRECTORY='/mnt/mydisk/'

# list the file types you want played here. separated by pipes. not case sensitive
FILE_TYPES='mkv|mp4'

chk_video_dir()
{
    [[ -f "${VIDEO_DIRECTORY}" ]] || echo ""${VIDEO_DIRECTORY}" does not exist"
}

get_playlist() 
{ 
    # get recursive list of files in video directory
    playlist=$(find "${VIDEO_DIRECTORY}" -type f | sort -n)
    # filter out the file types we don't want
    playlist=$(echo "${playlist}" | grep -Ei "^.*\.($FILE_TYPES)$")
    echo "${playlist}"
}

# start looping through the videos
while :
do
    # get new playlist after old has played
    # this allows you do add new videos without stopping the service
    playlist=$(get_playlist)
    for video in $(echo "${playlist}") 
    do
        echo "${video}"
	# still playing with these settings but they seem to work for my TV
	# you may have to adjust for your setup
        omxplayer --display 5 -p -o hdmi --win "0 0 1920 1080" "${video}"
    done
done

I’ll break down the entire application as it sits.

It’s very important that you have your USB or NAS mounted at the right location. If your videos don’t start playing automatically after a reboot, this is a good place to start troubleshooting.

# base directory where all videos are stored
# this could be a USB drive, SD card or even a NAS
# videos will be sorted alphabetically 
VIDEO_DIRECTORY=/mnt/mydisk/

Change this based on what your video file types are. Mine are .mkv and .mp4 so I use 'mkv|mp4'

# list the file types you want played here. separated by pipes. not case sensitive
FILE_TYPES='mkv|mp4'

Next we have a 2 functions that we use in the script.

The first function chk_video_dir checks to make sure the video directory exists. If it doesn’t we exit.

The second builds a playlist based on what you have in the VIDEO_DIRECTORY.

The playlist will build your playlist in alphabetical order. Your episodes should be titled with the number of the episode at the beginning. For instance 01-The_Pilot.mkv. Episodes should be kept in directories for their own season. If your series has 4 seasons, you’d have directories named S1, S2, S3, and S4. This will play your TV series in chronological order.

The get_playlist function supports multiple shows. Keep each show in it’s own directory. It will play every episode of every season of the show, and then move onto the next show in alphabetical order.

chk_video_dir()
{
    [[ -f "${VIDEO_DIRECTORY}" ]] || echo ""${VIDEO_DIRECTORY}" does not exist"
}

get_playlist() 
{ 
    # get recursive list of files in video directory
    playlist=$(find "${VIDEO_DIRECTORY}" -type f | sort -n)
    # filter out the file types we don't want
    playlist=$(echo "${playlist}" | grep -Ei "^.*\.($FILE_TYPES)$")
    echo "${playlist}"
}

The next and last portion of the script is there all the work happens. It loops through every video in your playlist and plays them until completion. When it’s finished it will build a new playlist and start over.

# start looping through the videos
while :
do
    # get new playlist after old has played
    # this allows you do add new videos without stopping the service
    playlist=$(get_playlist)
    for video in $(echo "${playlist}") 
    do
        echo "${video}"
	# still playing with these settings but they seem to work for my TV
	# you may have to adjust for your setup
        omxplayer --display 5 -p -o hdmi --win "0 0 1920 1080" "${video}"
    done
done

Conclusion

Please open an issue on Github if you have any issues or feature requests. Be as specific as possible in your description.

That’s it! Enjoy your new home TV station with PinfiniTV.

Follow me on Twitter or subscribe to my mailing list below to be notified when I post a new article.