# Solostation Retrospective

6 min read
Table of Contents

Two years ago, I found a video floating around the web of probably the most amazing Raspberry Pi project that I’ve ever seen. This guy took a Pi 4B, an external 2TB hard drive, a screen from an old iPad 2, and an Apple iMac remote (Front Row anyone?), creating his own custom cable TV station. This included 5-10 channels that had tons of content, commercials, station idents, and special local access programming that he curated himself. Christmas commercials played when you got around Christmas time, movie marathons were fun surprises, and there were even Pay-Per-View channels! It was truly a work of art that I wanted to see if I could recreate myself.

So I set out by buying a Pi 4B, 2TB SSD, and a 15” portable monitor. Equipped with Python, I set out to try and make the exact same thing … or so I thought. My goal was to create my own spin of this project and make it 100% offline (after the first run of course) so that it can run anywhere. Here is a retrospect on this project 2 years in the making and where I stopped working on it.

Going beyond a beginner in PythonLink to heading

As an IT Administrator, I have done quite a bit with PowerShell and dabbled with Python enough to know some basic things. But this project has taught me more about Python, SQL and JSON more than any other project I’ve ever worked on. Everything from getting very cozy with dictionaries, converting object types, and creating custom classes; I did a lot of researching, a lot of trail and error.

One thing that I learned is about how time works in Python with the ‘datetime’ module. My goal with this project was to have content start at the top or bottom of the hour, depending on content length and type. Sitcoms would play, say at 1PM, with commercial breaks, followed by the next item scheduled for 1:30PM . But how do you handle the time and the schedule? Enter timedeltas. When dealing with time, you HAVE to keep everything lined up and in the same format. Did you measure a block of time in minutes or seconds? Which one makes more sense to use and work with? It was a little bit of a chore to keep up with it all and make sure everything worked. Tons of debug logs later and I finally mastered it … I think?

I also worked with TVDB’s free API to pull down show, season and episode information, storing it in local JSON files so that I wouldn’t have to make calls every time I ran the script.

Commercial BreaksLink to heading

This is something that I really wanted to work but never could get just right. The concept is that I would take my ripped content (from my physical DVD collection), have a SQL database with the episode information and when chapter breaks would occur, down to the second. The scheduler would choose an episode, get the episode information from the SQL database, and monitor during playback for when chapters would change, thus playing back a pre-selected list of commercials and going on to the next chapter of that episode. Whew! This sounds like it would work, although complicated, and it did … to an extent.

The problem is that media players, like MPV, can either playback content on the spot directly or in a playlist format. You can’t create a playlist that can take action when the chapter switches, so you have to create a “monitor” or “watcher” that watches for that chapter change and react accordingly. MPV does have a built-in observer for chapter changes, but it’s not reliable in my testing. Also, some of my media doesn’t even have chapters!

I also found that this method of injecting commercials when chapters changed caused the time schedule to always be inaccurate. Other issues resulted because of the time not being exact.

I then pivoted to allowing an episode or movie to play, then play commercials until the next time block. The issue with this method is that in order for this to work and there to be no “dead air time”, you have to have individual commercial files that fit every scenario and amount of time. For example, if you have 8 seconds until the next block, you may or may not have a commercial file to fill in that gap. How do you account for those 8 seconds if you don’t have a commercial file? See where I’m going with this? Heck, I even tried to see if there was a way to dynamically create video files to fill in these spots, but the Pi doesn’t do this very well due to computing power.

I Want My MTVLink to heading

One fun concept from the original video is that this guy recreated the MTV of the 80s and 90s, playing mainly music videos (yes, even with the song info in the bottom left), fun MTV shows like HeadBangers Ball and MTV News, and lots of Beavis and Butthead. I started to do this by finding a YouTube playlist of music videos, downloading them with YT-DLP, processing each one into a SQL database, and then using the MPV on-screen text overlay for the first and last 5 seconds of the music video. This actually worked and really wasn’t that hard to implement!

Fail, Rebuild, Fail, RepeatLink to heading

As I mentioned, I’ve spent the last 2 years, on and off, trying new approaches to reach my goal. I ran into many, many issues, solved quite a few of them, but there are just some that I could not resolve.

Just getting commercials from YouTube and breaking them up into individual video files is such a process that I haven’t had time for. Trying a new concept or method to find that you broke 10 other things. Trying to get seasonal commercials to play more often during the holidays. Developing a “weight” system for your media, pushing the scheduler to choose specific things like playing Die Hard more often around Christmas. All of these issues I just couldn’t solve.

Maybe the project was a little too much for me to take on. Maybe I just haven’t figured out the right way to put all of this together and make it work.

Earlier this week, I took a little time to build a very simplified version of this project: use MPV to build a playlist, consisting of a random amount of commercials, followed by either an episode or movie. All you have to do is power on the Pi and enjoy, thanks to DietPi headless (no Desktop Environment) and .bashrc. Nothing crazy, no SQL, no JSON, just straight Python. And it only took me part of a day due to what I’ve learned. You can see “Version 4” of Solostation on my Github if you’d like to see the code. You can also see the mess of “Version 3” (the complicated version) if you check out my repo.

So What Now?Link to heading

There will come a time where I will take a fresh attempt at creating this project, but not today. I didn’t even get to design and build an enclosure! And maybe that’s something I do when the new year rolls around, we will just have to see.

My avatar

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.


More Posts

Comments