justinemter / pseudo-channel

This is a python based cli-app using the python-plex-api to control a plex-client and act like a real TV channel with show scheduling, commercial breaks, movie nights, etc. "Home-Brewed TV Channel(s) for Hackers"
GNU General Public License v3.0
130 stars 18 forks source link

Database update eliminates certain shows #68

Closed mutto233 closed 6 years ago

mutto233 commented 6 years ago

I am having a problem with my database seemingly neglecting to include certain episodes of a show (lets call it "Show A"). Looking at the database, in the "show" category it is there with all information, but in the "episodes" category it is nowhere to be seen.

However, if I run the python script with the -u command and manually break the code when "Show A" has finished uploading, a search of the database returns not only the "show" but the "episode" category has been populated. You can even run 2 or 3 more shows after completing "Show A" with no problems. However, going back to populating the full database you encounter this problem.

mutto233 commented 6 years ago

I believe I have actually found the issue to this problem. Wanted to post it here just in case others run into the problem.

The show in question did not name its episodes uniquely, all seasons had "Episode 1" or "Episode 2" as their listed name on theTVDB. The problem with this lies in the way the database is formed.

When being created, the SQL database is formed with a "REPLACE INTO" command, with a Unique ID based on episode title. Therefore, whenever "Episode 1" is created for all seasons, it simply overwrites the previous "Episode 1" since to the database they are the same.

I am looking into a quick fix to the problem, possibly just deleting the .db every time and creating a new one so I can run "INSERT INTO" instead, but I would love someone more familiar with the database structure to offer another way possibly.

mutto233 commented 6 years ago

I believe I have found a way to work around this issue, and once again wanted to post for completeness.

I have modified the PseudoChannelDatabase.py file to change the unique identifier from the title of the episode to its plex media id. Considering these should all, by definition, be unique, there is little chance of an overlap here.

You can find the revised file here. PseudoChannelDatabase.zip

If some others could test this out too and let me know how it goes, that would be great.

mutto233 commented 6 years ago

After running this for a while, I noticed there was an issue where "Episode 1"-named shows were only ever playing the first episode. Sure enough, there is another associated bug with the "lastplayedTitle" here, where it only ever senses the first show with an episode named "Episode 1". This is fixed in a similar manner to the first problem; the last played episode's plexmediaID is stored instead of its title. This should work a lot smoother I believe.

However, since the last played title is stored differently, expect to update your database FROM SCRATCH to remove the old titles.

Here is the new file; you can also find it on my fork of the project: PseudoChannelDatabase.zip

justinemter commented 6 years ago

@mutto233 I'm really happy you forked the project. The episode title issue has been a problem for a while. Before, we would just rename all the episodes in Plex to be unique (i.e. "Season 1 Episode 1"). Your solution makes much more sense. I'm happy you're jumping into the deep the end with all this.