luigi311 / JellyPlex-Watched

Sync watched between jellyfin and plex locally
GNU General Public License v3.0
392 stars 19 forks source link

[BUG] KeyError: 'tmdb' in jellyfin.py #76

Closed seblu closed 1 year ago

seblu commented 1 year ago

Describe the bug Traceback when syncing a Plex server to a Jellyfin server.

To Reproduce Steps to reproduce the behavior:

  1. Follow baremetal install with venv (python 3.11)
  2. Add plex token and jellyfin token to .env
  3. Run python main.py

Expected behavior No traceback

Logs

[DEBUG]: Jellyfin: Skipping episode La Bande masquée as it is not in mark list for jean
[DEBUG]: Jellyfin: Skipping episode Minuit moins une as it is not in mark list for jean
Dryrun Roblochon : La Série Season 1 Episode 22 Chiche Donne tout as watched for jean in Séries for Jellyfin
[ERROR]: Jellyfin: Error updating watched for jean in library Séries, 'tmdb'
[ERROR]: Traceback (most recent call last):
  File "/home/jean/scm/JellyPlex-Watched/src/jellyfin.py", line 676, in update_user_watched
    in show[show_provider_source.lower()]
       ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'tmdb'

Average time: 140.85019239597023

Type:

Additional context

I'm able to reproduce against 5.0.0, 4.5.0 and main.

seblu commented 1 year ago

The traceback happen when the video variable has no tmdb key defined.

Here is a print of the video variable when it's happening

{'title': 'MyTitle', 'locations': ('MyTitle.avi',), 'status': {'completed': True, 'time': 0}}

I used "Fix Match" in Plex to update the video metadata, but it added only an imdb id.

{'imdb': 'tt13122460', 'title': 'MyTitle', 'locations': ('MyTitle.avi',), 'status': {'completed': True, 'time': 0}}
seblu commented 1 year ago

The errors happen for both series and movies. I had workaround the tracebacks with:

diff --git a/src/jellyfin.py b/src/jellyfin.py
index f17f445..8986e29 100644
--- a/src/jellyfin.py
+++ b/src/jellyfin.py
@@ -584,7 +584,7 @@ class Jellyfin:
                                         for video in videos:
                                             if (
                                                 movie_provider_id.lower()
-                                                in video[movie_provider_source.lower()]
+                                                in video.get(movie_provider_source.lower(), [])^M
                                             ):
                                                 movie_status = video["status"]
                                                 break
@@ -673,7 +673,7 @@ class Jellyfin:
                                             show = {k: v for k, v in show}
                                             if (
                                                 show_provider_id.lower()
-                                                in show[show_provider_source.lower()]
+                                                in show.get(show_provider_source.lower(), [])^M
                                             ):
                                                 for season in seasons.values():
                                                     for episode in season:
seblu commented 1 year ago

No more traceback so far. Thanks!