Jellyfin/Emby: Simplify get watched

Shouldn't need to do library type checks as that is handed in the
get libraries function and then used with the sync libraries name
check

Signed-off-by: Luis Garcia <git@luigi311.com>
This commit is contained in:
Luis Garcia
2025-03-07 23:26:10 +00:00
parent 93d9471333
commit d98b7c3e09

View File

@@ -248,7 +248,7 @@ class JellyfinEmby:
self, self,
user_name: str, user_name: str,
user_id: str, user_id: str,
library_type: Literal["Movie", "Series", "Episode"], library_type: Literal["movies", "tvshows"],
library_id: str, library_id: str,
library_title: str, library_title: str,
) -> LibraryData: ) -> LibraryData:
@@ -260,7 +260,7 @@ class JellyfinEmby:
watched = LibraryData(title=library_title) watched = LibraryData(title=library_title)
# Movies # Movies
if library_type == "Movie": if library_type == "movies":
movie_items = [] movie_items = []
watched_items = self.query( watched_items = self.query(
f"/Users/{user_id}/Items" f"/Users/{user_id}/Items"
@@ -297,7 +297,7 @@ class JellyfinEmby:
watched.movies.append(get_mediaitem(self.server_type, movie)) watched.movies.append(get_mediaitem(self.server_type, movie))
# TV Shows # TV Shows
if library_type in ["Series", "Episode"]: if library_type == "tvshows":
# Retrieve a list of watched TV shows # Retrieve a list of watched TV shows
all_shows = self.query( all_shows = self.query(
f"/Users/{user_id}/Items" f"/Users/{user_id}/Items"
@@ -398,46 +398,25 @@ class JellyfinEmby:
users_watched: dict[str, UserData] = {} users_watched: dict[str, UserData] = {}
for user_name, user_id in users.items(): for user_name, user_id in users.items():
libraries = []
all_libraries = self.query(f"/Users/{user_id}/Views", "get") all_libraries = self.query(f"/Users/{user_id}/Views", "get")
for library in all_libraries["Items"]: if not all_libraries or not isinstance(all_libraries, dict):
library_id = library["Id"] logger.debug(
library_title = library["Name"] f"{self.server_type}: Failed to get all libraries for {user_name}"
)
if library_title not in sync_libraries:
continue continue
identifiers: dict[str, str] = { for library in all_libraries.get("Items", []):
"library_id": library_id, if library.get("Name") not in sync_libraries:
"library_title": library_title,
}
libraries.append(
self.query(
f"/Users/{user_id}/Items"
+ f"?ParentId={library_id}&Filters=IsPlayed&Recursive=True&excludeItemTypes=Folder&limit=100",
"get",
identifiers=identifiers,
)
)
for library in libraries:
if len(library["Items"]) == 0:
continue continue
library_id: str = library["Identifiers"]["library_id"] library_id = library.get("Id")
library_title: str = library["Identifiers"]["library_title"] library_title = library.get("Name")
library_type = library.get("CollectionType")
# Get all library types excluding "Folder" if not library_id or not library_title or not library_type:
types = set( logger.debug(
[ f"{self.server_type}: Failed to get library data for {user_name} {library_title}"
x["Type"]
for x in library["Items"]
if x["Type"] in ["Movie", "Series", "Episode"]
]
) )
for library_type in types:
# Get watched for user # Get watched for user
library_data = self.get_user_library_watched( library_data = self.get_user_library_watched(
user_name, user_name,