From 713be6970cd6f2ba6f25feb5547cee1afb9463a5 Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Fri, 5 Apr 2024 00:26:24 -0600 Subject: [PATCH 1/8] Jellyfin: Fix error status code --- src/jellyfin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jellyfin.py b/src/jellyfin.py index 23bdbb9..b6e2e82 100644 --- a/src/jellyfin.py +++ b/src/jellyfin.py @@ -132,7 +132,7 @@ def query(self, query, query_type, session=None, identifiers=None): ) if response.status_code != 200: raise Exception( - f"Query failed with status {response.status} {response.reason}" + f"Query failed with status {response.status_code} {response.reason}" ) results = response.json() @@ -142,7 +142,7 @@ def query(self, query, query_type, session=None, identifiers=None): ) if response.status_code != 200: raise Exception( - f"Query failed with status {response.status} {response.reason}" + f"Query failed with status {response.status_code} {response.reason}" ) results = response.json() From 803d248cb8b894209bb258d96314b88b6572e33c Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Fri, 5 Apr 2024 00:47:09 -0600 Subject: [PATCH 2/8] Jellyfin: Skip if UserData is not avaliable --- src/jellyfin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jellyfin.py b/src/jellyfin.py index b6e2e82..6b20555 100644 --- a/src/jellyfin.py +++ b/src/jellyfin.py @@ -221,6 +221,9 @@ def get_user_library_watched( for movie in watched["Items"] + in_progress["Items"]: if "MediaSources" in movie and movie["MediaSources"] != {}: + if "UserData" not in movie: + continue + # Skip if not watched or watched less than a minute if ( movie["UserData"]["Played"] == True @@ -256,6 +259,9 @@ def get_user_library_watched( # Filter the list of shows to only include those that have been partially or fully watched watched_shows_filtered = [] for show in watched_shows["Items"]: + if not "UserData" in show: + continue + if "PlayedPercentage" in show["UserData"]: if show["UserData"]["PlayedPercentage"] > 0: watched_shows_filtered.append(show) @@ -613,7 +619,7 @@ def update_user_watched( else: logger( f"Jellyfin: Skipping movie {jellyfin_video.get('Name')} as it is not in mark list for {user_name}", - 1, + 3, ) # TV Shows From e6fbf746d89288594596bd7466d442459f3336ba Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Sun, 14 Apr 2024 17:06:07 -0600 Subject: [PATCH 3/8] CI: Increase wait --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5cd5990..289bc98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: docker-compose -f JellyPlex-Watched-CI/plex/docker-compose.yml up -d docker-compose -f JellyPlex-Watched-CI/jellyfin/docker-compose.yml up -d # Wait for containers to start - sleep 5 + sleep 10 docker-compose -f JellyPlex-Watched-CI/plex/docker-compose.yml logs docker-compose -f JellyPlex-Watched-CI/jellyfin/docker-compose.yml logs From dcd4ac1d36ee530b403fbbb40898780c298491fd Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Sun, 14 Apr 2024 17:06:29 -0600 Subject: [PATCH 4/8] Gitignore: expand .env --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3093d0a..84d832d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -**.env +**.env* *.prof # Byte-compiled / optimized / DLL files From 402c28674251a67e1f68cf1728354671dc46fc7c Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Sun, 14 Apr 2024 17:06:37 -0600 Subject: [PATCH 5/8] Plex: format --- src/plex.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/plex.py b/src/plex.py index 548b5d6..4ed1bc4 100644 --- a/src/plex.py +++ b/src/plex.py @@ -66,9 +66,11 @@ def extract_guids_from_item(item: Union[Movie, Show, Episode]) -> Dict[str, str] def get_guids(item: Union[Movie, Episode], completed=True): return { "title": item.title, - "locations": tuple([location.split("/")[-1] for location in item.locations]) - if generate_locations - else tuple(), + "locations": ( + tuple([location.split("/")[-1] for location in item.locations]) + if generate_locations + else tuple() + ), "status": { "completed": completed, "time": item.viewOffset, @@ -84,11 +86,11 @@ def get_user_library_watched_show(show, process_episodes, threads=None): ( { "title": show.title, - "locations": tuple( - [location.split("/")[-1] for location in show.locations] - ) - if generate_locations - else tuple(), + "locations": ( + tuple([location.split("/")[-1] for location in show.locations]) + if generate_locations + else tuple() + ), } | extract_guids_from_item(show) ).items() # Merge the metadata and guid dictionaries From 9b38729b95ab1b5a051778cfc778ddba81b0e0ae Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Sun, 14 Apr 2024 17:08:49 -0600 Subject: [PATCH 6/8] Watched: Use get for season Use get to avoid KeyError if season doesnt exist. --- src/watched.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/watched.py b/src/watched.py index 57f020d..4d4f7cc 100644 --- a/src/watched.py +++ b/src/watched.py @@ -248,7 +248,7 @@ def filter_episode_watched_list_2_keys_dict( # Iterate through episode_watched_list_2_keys_dict["season"] and find the indecies that match season for season_index, season_value in enumerate( - episode_watched_list_2_keys_dict["season"] + episode_watched_list_2_keys_dict.get("season") ): if season_value == season: season_indecies.append(season_index) From ae71ca09404f2fb31ef6c3a29edc286898a3658f Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Sun, 14 Apr 2024 17:44:31 -0600 Subject: [PATCH 7/8] Jellyfin/Plex: Log when guid items are missing --- src/jellyfin.py | 23 +++++++++++++++++------ src/plex.py | 13 +++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/jellyfin.py b/src/jellyfin.py index 6b20555..cbdeb7a 100644 --- a/src/jellyfin.py +++ b/src/jellyfin.py @@ -25,23 +25,34 @@ def get_guids(item): - guids = {"title": item["Name"]} + if item.get("Name"): + guids = {"title": item.get("Name")} + else: + logger(f"Jellyfin: Name not found in {item.get('Id')}", 1) + guids = {"title": None} if "ProviderIds" in item: guids.update({k.lower(): v for k, v in item["ProviderIds"].items()}) + else: + logger(f"Jellyfin: ProviderIds not found in {item.get('Name')}", 1) if "MediaSources" in item: guids["locations"] = tuple( [x["Path"].split("/")[-1] for x in item["MediaSources"] if "Path" in x] ) else: + logger(f"Jellyfin: MediaSources not found in {item.get('Name')}", 1) guids["locations"] = tuple() - guids["status"] = { - "completed": item["UserData"]["Played"], - # Convert ticks to milliseconds to match Plex - "time": floor(item["UserData"]["PlaybackPositionTicks"] / 10000), - } + if "UserData" in item: + guids["status"] = { + "completed": item["UserData"]["Played"], + # Convert ticks to milliseconds to match Plex + "time": floor(item["UserData"]["PlaybackPositionTicks"] / 10000), + } + else: + logger(f"Jellyfin: UserData not found in {item.get('Name')}", 1) + guids["status"] = {} return guids diff --git a/src/plex.py b/src/plex.py index 4ed1bc4..e5da617 100644 --- a/src/plex.py +++ b/src/plex.py @@ -64,6 +64,19 @@ def extract_guids_from_item(item: Union[Movie, Show, Episode]) -> Dict[str, str] def get_guids(item: Union[Movie, Episode], completed=True): + if not item.locations: + logger( + f"Plex: {item.title} has no locations", + 1, + ) + + if not item.guids: + logger( + f"Plex: {item.title} has no guids", + 1, + ) + + return { "title": item.title, "locations": ( From 5b1933cb088fe69e5fe3cbb27021e66dce549b1c Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Mon, 15 Apr 2024 15:03:18 -0600 Subject: [PATCH 8/8] format --- src/jellyfin.py | 4 ++-- src/plex.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/jellyfin.py b/src/jellyfin.py index cbdeb7a..cfa0243 100644 --- a/src/jellyfin.py +++ b/src/jellyfin.py @@ -234,7 +234,7 @@ def get_user_library_watched( if "MediaSources" in movie and movie["MediaSources"] != {}: if "UserData" not in movie: continue - + # Skip if not watched or watched less than a minute if ( movie["UserData"]["Played"] == True @@ -272,7 +272,7 @@ def get_user_library_watched( for show in watched_shows["Items"]: if not "UserData" in show: continue - + if "PlayedPercentage" in show["UserData"]: if show["UserData"]["PlayedPercentage"] > 0: watched_shows_filtered.append(show) diff --git a/src/plex.py b/src/plex.py index e5da617..e891809 100644 --- a/src/plex.py +++ b/src/plex.py @@ -69,13 +69,12 @@ def get_guids(item: Union[Movie, Episode], completed=True): f"Plex: {item.title} has no locations", 1, ) - + if not item.guids: logger( f"Plex: {item.title} has no guids", 1, - ) - + ) return { "title": item.title,