blacktwin / JBOPS

Just a Bunch Of Plex Scripts
1.64k stars 305 forks source link

Issue - mediamanager.py 'unwatched' not working as expected #392

Open wales opened 11 months ago

wales commented 11 months ago

Describe the bug

media_manager.py behaving inconsistently when using the unwatched flag.

Initially, running against Film library appeared to work, e.g running..

python3 media_manager.py --libraries Films --select unwatched --date 30 --action show

..would list an output, however running it against TV would report no Series to remove, despite there being entries in Tautilli

And now, bizarrely, running the command against either Films or TV produces nothing to remove:

python3 media_manager.py --libraries Films --select unwatched --date 30 --action show
Checking library: 'Films' watch statuses...
0 item(s) have been found.

Screenshot of items in Films:

image

Using the lastPlayed flag works as intended, but obviously doesn't pick up the unwatched items.

blacktwin commented 6 months ago

I'm not able to reproduce any issue with Shows or Movies 🤷. You might need to walk through the code to see where the error is happening. Set some debug points where the is filtering through the library.

dama-de commented 6 months ago

There is a problem that the unwatched_work function aborts as soon as one page had no unwatched items. To prevent that, I pulled the filtering out of get_library_media_info like this:

diff --git a/utility/media_manager.py b/utility/media_manager.py
--- a/utility/media_manager.py  (revision e097a07ca55bbb9f60d726f550dfa3ac2358ba56)
+++ b/utility/media_manager.py  (date 1705844138305)
@@ -384,16 +384,16 @@
     while True:

         # Getting all watched history for userFrom
-        tt_history = tautulli_server.get_library_media_info(section_id=sectionID,
-                                                     start=start, length=count, unwatched=True, date=date)
+        tt_history = tautulli_server.get_library_media_info(section_id=sectionID, start=start, length=count)

         if all([tt_history]):
             start += count
             for item in tt_history:
-                _meta = tautulli_server.get_metadata(item['rating_key'])
-                if _meta:  # rating_key that no longer exists on the Plex server will return blank metadata
-                    metadata = Metadata(_meta)
-                    unwatched_lst.append(metadata)
+                if item['play_count'] is None and float(item['added_at']) < date: 
+                    _meta = tautulli_server.get_metadata(item['rating_key'])
+                    if _meta:  # rating_key that no longer exists on the Plex server will return blank metadata
+                        metadata = Metadata(_meta)
+                        unwatched_lst.append(metadata)
             continue
         elif not all([tt_history]):
             break