It’s time for another update on Project One!
Simplify All The Things
When you write code, test it out and see that all things are working as intended, you might feel like your code is bloated, half of it is unnecessary. You tend to question your sanity and if you should find another way to write it. That’s how I’ve felt for the last few weeks. So I’ve decided to take a step back and look for things that could be done better and more efficiently.
One thing is that I have a real bad habit of is throwing in a lot of print statements for debugging and not removing them. I get into the whole “Oh I’ll need that later for testing X and Y”, but it always results in a ton of confusion and mess. I did remove all of the logging events because I was having an issue where Python would recognize my declaration of “DEBUG” over “INFO” when it came to importing other Python files, so I just yanked all that out for now. At this point, there really isn’t a need of doing fancy logging; either it works or it doesn’t. I can always throw in a few print statements and remove them when I’m done, which is what I’m doing now, trying to break the bad habit.
I’ve also “converted” everything from using double quotes to single quotes. Not only is it much easier/faster to write, but it helps with SQL queries. F-Strings have also become my friend over the last few weeks.
Finally, a huge change to Scheduling. I was originally building out all of the schedules in memory (Python only), but then I wanted to have a way to export them for faster playback if the script/Pi was restarted (why rebuild the schedule?). The last build that I did had each scheduled item converted to a dictionary and dumping itself out to appropriately JSON files. It worked but I knew that there had to be a better way, even if it was just consolidating the methods to which I was storing data. I finally broke down and built the scheduling around the one thing I didn’t really want to touch: SQL. SQL has always been a mystery to me and I’ve worked with it a little int he past, but it seems to . . . advanced for what I’m trying to do. Sure, all of the movies and episodes have their metadata in SQL DBs on the external hard drive, but the schedule?
Turns out that my code really slimmed down once I was able to get the schedule in and out of a SQL DB. Once loaded in its entirety into memory, I can then use Python to filter the schedule any way I want and do all the things.
If you are familiar with apps such as Ersatztv, it creates channels based on the idea of Collections: you manually choose the items you want on the channel or with a similar name. I have shamelessly “copied” this idea in the sense that a channel can have a Collection to only allow specific movie titles, genres, TV series names, etc. Think of it as a “whitelist” of sorts. A good example would be in creating a channel for the holidays coming up. I know that there are some movies that everyone watches around the holidays and you could probably name them all of right now! What I can do is create an entry in the Collections database file for this holiday channel, put in some keywords like “Christmas” and “Thanksgiving”. ProjectOne will then know to look for a Collection with this channel’s name and filter down the movie and TV episodes that contain these keywords. Pretty straight forward but it really helps to make sure that the proper content is being scheduled for the channel in question.
I’m debating on whether I want to include movie ratings in this or not. Since all the metadata comes from TheTVDB, I’ve noticed that most movies do not have ratings set properly, so most of my movie metadata is set to “N/A”.
Getting Close to Finished?
In all technicality, I have set the channels in stone and everything acts as it should. Schedules are made properly, the flow of one item to another works, and it serves the purpose I originally set. There are a few small things that I’m still working on to consider the code “finished”:
- Watchlist/Tracking - This is one I’ve struggled with, finding the best way to track what has been scheduled so we don’t always see the same hand full of episodes over and over. I’ve tried SQL and JSON methods but they always seem to not want to cooperate with my code for one reason or another. Maybe I can filter further since the schedule now resides in SQL?
- Logos - I honestly don’t know if I want to do this one or not. I’m leaning on implementing VLC’s Marquee to show the number and name of the channel for 3 seconds per channel change, but I do like the idea of showing a logo. The problem, again, is that all media has different resolutions, therefore different resolution logos would have to be made and code would have to adjust. Possibly not worth it.
- Cartoon and Music Channels - I have these two channels planned to implement but that requires that all of my media be encoded in the proper format. I’m wrapping up movies now and will focus on TV shows in the next few weeks. This also means that I need to start downloading any and everything I can from YouTube.
There are a few other items on my to-do list that I may hold for future updates. Getting to a real, first stable version of this package is the main goal right now.
Let’s Start Talking Hardware
I will start spending a lot more time in thinking about how I want to package this. Should I create a cable box style design for everything to sit in? Maybe even a smaller console like enclosure? Then, there comes the discussion of physical buttons, remote control, cables and cords. Lots to think about on this one, but I’m planning on sketching some design possibilities once coding is at a freeze.
Expect another update in 1-2 weeks!