ZeroQI / YouTube-Agent.bundle

Plex Metadata Agent for Movies and TV Series libraries
452 stars 43 forks source link

Inaccurate video thumbnails and watch state #68

Closed jasonwaters closed 3 years ago

jasonwaters commented 3 years ago

Thank you for building this Plex Agent, it's really great! I have been using it for a couple months now and I have a couple issues I'd love to see corrected. Let me explain how I am using it to give you a full picture of my use case.

I have two libraries within my Plex instance:

Observation

For the channels where videos are not deleted (YouTube Kids), just new ones added, the metadata, thumbnails and watch state are consistently correct and new videos get the next sequential episode number.

For the channels where videos are frequently deleted after watching (YouTube Adults), the thumbnails are frequently incorrect and do not correlate with the actual video. Also, newly downloaded videos are flagged as already watched in Plex. My guess is that this is due to the way YouTube-Agent is assigning episode numbers. Since I am downloading videos from a channel and not a playlist, they are organized in channel folders.

For example, youtube-dl would download videos from this url https://www.youtube.com/c/BehindtheBrand/videos and organize the media a folder like this:

Here is what I think what is happening:

  1. I watch a video on plex.
  2. After watching the video I delete it using the Plex UI.
  3. Later that day some automation downloads new videos for the channel to that folder.
  4. YouTube-Agent scans the folder and sees new video files. But one deleted as well. So it does it's best effort to re-assign episode numbers by order of the files.
  5. But these episode numbers aren't reliable because what used to be episode 1 shifted to a different file, so thumbnails and watch status is inaccurate.

Proposed Solution

It would be nice if an episode number could be derived from the youtube video upload date. For instance, if the timestamp could be used for the episode number, then it would be very unlikely for any two video files of the same channel to receive the same episode number at any time -- even if files are deleted or added later.

I am not sure if Plex has a maximum value for episode number, but if so that could be a problem for this strategy. One other idea is to calculate an episode based on the (video upload timestamp) minus the timestamp for January 1 of the year the video was uploaded. This would give smaller episode numbers and lock them to one particular season (the year).

I looked at the code a bit, and it seems possible to implement what I propose, but I have no experience developing, troubleshooting and debugging Plex Plugins. So I wanted to raise the question to you to see if it seems feasible and if is something you'd consider adding to the Plugin.

Cheers

ZeroQI commented 3 years ago

The episode is chosen by the ASS scanner

If another episode gets given the same episode number, thumbnail and watch status will be the one of the former video since the episodes were deleted but not their metadata, you need to "Clean Bundles" after each deletion

Clean Bundles

In the web interface click on the three dots … next to the word “Libraries” and from the drop down menu choose “Clean bundles.”

As a side note, this was added [not by me] https://github.com/ZeroQI/Absolute-Series-Scanner/pull/284 to sort ordering by date perfectly You could set to True SW_YOUTUBE_DATE in ASS line 155 [SW_YOUTUBE_DATE = False] https://github.com/ZeroQI/Absolute-Series-Scanner/blob/master/Scanners/Series/Absolute%20Series%20Scanner.py Then change the naming template to begin all filenames with yyyymmdd - *

If 4 episodes are released the same day, wouldn't that push down the episode number you would have assigned for the next day? We could just use the video release number this year but eps will have gaps, also the full video list XML will need downloading at every scan... Again, clean bundles after deleting content should solve the issue. closing

jasonwaters commented 3 years ago

@ZeroQI thanks for commenting, it was just enough information for me to add the logic myself. I forked ASS scanner and added a small bit of code to number episodes based on the date in the filename along with the modified time of the file. This produces a deterministic number that will always guarantee a unique episode number -- works great for my purposes.

If you or anyone else who may find this issue would like to see what I did, here's the code:

https://github.com/jasonwaters/Absolute-Series-Scanner/blob/master/Scanners/Series/Absolute%20Series%20Scanner.py#L982

jasonwaters commented 3 years ago

Here's a screenshot that shows what the episode numbering ends up looking like. They are large numbers, but I care more about the unique ascending nature of them.

screenshot-2021-02-25-114855@2x

ZeroQI commented 3 years ago

This one is tricky to please everybody