Jellyfin: Fix tv show searching for watched

This commit is contained in:
Luigi311
2023-02-25 18:27:01 -07:00
parent 4ac670e837
commit 218037200c

View File

@@ -1,4 +1,4 @@
import asyncio, aiohttp import asyncio, aiohttp, traceback
from src.functions import ( from src.functions import (
logger, logger,
search_mapping, search_mapping,
@@ -46,9 +46,14 @@ class Jellyfin:
) as response: ) as response:
results = await response.json() results = await response.json()
if type(results) is str:
logger(f"Jellyfin: Query {query_type} {query} {results}", 2)
raise Exception(results)
# append identifiers to results # append identifiers to results
if identifiers: if identifiers:
results["Identifiers"] = identifiers results["Identifiers"] = identifiers
return results return results
except Exception as e: except Exception as e:
@@ -148,7 +153,7 @@ class Jellyfin:
) )
# TV Shows # TV Shows
if library_type == "Series": if library_type in ["Series", "Episode"]:
# Initialize an empty dictionary for the given user and library # Initialize an empty dictionary for the given user and library
user_watched[user_name][library_title] = {} user_watched[user_name][library_title] = {}
@@ -184,6 +189,7 @@ class Jellyfin:
"show_guids": show_guids, "show_guids": show_guids,
"show_id": show["Id"], "show_id": show["Id"],
} }
season_task = asyncio.ensure_future( season_task = asyncio.ensure_future(
self.query( self.query(
f"/Shows/{show['Id']}/Seasons" f"/Shows/{show['Id']}/Seasons"
@@ -309,6 +315,8 @@ class Jellyfin:
f"Jellyfin: Failed to get watched for {user_name} in library {library_title}, Error: {e}", f"Jellyfin: Failed to get watched for {user_name} in library {library_title}, Error: {e}",
2, 2,
) )
logger(traceback.format_exc(), 2)
return {} return {}
async def get_users_watched( async def get_users_watched(
@@ -362,7 +370,7 @@ class Jellyfin:
[ [
x["Type"] x["Type"]
for x in watched["Items"] for x in watched["Items"]
if x["Type"] in ["Movie", "Series"] if x["Type"] in ["Movie", "Series", "Episode"]
] ]
) )
@@ -385,8 +393,14 @@ class Jellyfin:
# If there are multiple types in library raise error # If there are multiple types in library raise error
if types is None or len(types) < 1: if types is None or len(types) < 1:
all_types = set(
[
x["Type"]
for x in watched["Items"]
]
)
logger( logger(
f"Jellyfin: Skipping Library {library_title} not a single type: {types}", f"Jellyfin: Skipping Library {library_title} found types: {types}, all types: {all_types}",
1, 1,
) )
continue continue