Skip to content

Commit

Permalink
Jellyfin: Improve get watched movies
Browse files Browse the repository at this point in the history
Signed-off-by: Luigi311 <[email protected]>
  • Loading branch information
luigi311 committed Dec 12, 2023
1 parent 9950200 commit 246b123
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions src/jellyfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,40 +150,34 @@ async def process_movie_library(
# Initialize the user's movie library in the user_watched dictionary
user_watched[user_name][library_title] = []

movies_task = []
# Get the list of watched movies
watched = await self.query(
f"/Users/{user_id}/Items"
+ f"?ParentId={library_id}&Filters=IsPlayed&IncludeItemTypes=Movie&Recursive=True&Fields=ItemCounts,ProviderIds,MediaSources",
"get",
session,
movies_task.append(
self.query(
f"/Users/{user_id}/Items"
+ f"?ParentId={library_id}&Filters=IsPlayed&IncludeItemTypes=Movie&Recursive=True&Fields=ItemCounts,ProviderIds,MediaSources",
"get",
session,
)
)
# Get the list of in-progress movies
in_progress = await self.query(
f"/Users/{user_id}/Items"
+ f"?ParentId={library_id}&Filters=IsResumable&IncludeItemTypes=Movie&Recursive=True&Fields=ItemCounts,ProviderIds,MediaSources",
"get",
session,
movies_task.append(
self.query(
f"/Users/{user_id}/Items"
+ f"?ParentId={library_id}&Filters=IsResumable&IncludeItemTypes=Movie&Recursive=True&Fields=ItemCounts,ProviderIds,MediaSources",
"get",
session,
)
)

# Process the watched movies
await self.process_movies(
user_watched,
library_title,
watched["Items"],
user_name,
in_progress=False,
)
# Process the in-progress movies
await self.process_movies(
user_watched,
library_title,
in_progress["Items"],
user_name,
in_progress=True,
movies = await asyncio.gather(*movies_task)

await self.process_watched_movies(
user_watched, library_title, movies, user_name
)

async def process_movies(
self, user_watched, library_title, movies, user_name, in_progress=False
async def process_watched_movies(
self, user_watched, library_title, movies, user_name
):
# Iterate through the list of movies
for movie in movies:
Expand All @@ -193,13 +187,14 @@ async def process_movies(
f"Jellyfin: Adding {movie.get('Name')} to {user_name} watched list",
3,
)
# Get the movie's GUIDs
movie_guids = get_media_guids(movie)
# Check if the movie is in progress or fully watched
if (
not in_progress
movie["UserData"]["Played"]
or movie["UserData"]["PlaybackPositionTicks"] >= 600000000
):
# Get the movie's GUIDs
movie_guids = get_media_guids(movie)

# Append the movie dictionary to the user's watched list
user_watched[user_name][library_title].append(movie_guids)
logger(f"Jellyfin: Added {movie_guids} to {user_name} watched list", 3)
Expand Down

0 comments on commit 246b123

Please sign in to comment.