Jellyfin: Remove episode filter as it doesnt exist in jellyfin

pull/174/head
Luis Garcia 2024-06-02 22:07:58 -06:00
parent 7119956ec7
commit 1a7178e32d
2 changed files with 66 additions and 73 deletions

View File

@ -184,7 +184,7 @@ class JellyfinEmby:
response = self.query(query_string, "get") response = self.query(query_string, "get")
if response: if response:
return f"{response['ServerName']}: {response['Version']}" return f"{self.server_type} {response['ServerName']}: {response['Version']}"
else: else:
return None return None
@ -229,38 +229,42 @@ class JellyfinEmby:
f"/Users/{user_id}/Items" f"/Users/{user_id}/Items"
+ f"?ParentId={library_id}&Filters=IsPlayed&IncludeItemTypes=Movie&Recursive=True&Fields=ItemCounts,ProviderIds,MediaSources", + f"?ParentId={library_id}&Filters=IsPlayed&IncludeItemTypes=Movie&Recursive=True&Fields=ItemCounts,ProviderIds,MediaSources",
"get", "get",
) ).get("Items", [])
in_progress = self.query( in_progress = self.query(
f"/Users/{user_id}/Items" f"/Users/{user_id}/Items"
+ f"?ParentId={library_id}&Filters=IsResumable&IncludeItemTypes=Movie&Recursive=True&Fields=ItemCounts,ProviderIds,MediaSources", + f"?ParentId={library_id}&Filters=IsResumable&IncludeItemTypes=Movie&Recursive=True&Fields=ItemCounts,ProviderIds,MediaSources",
"get", "get",
) ).get("Items", [])
for movie in watched["Items"] + in_progress["Items"]: for movie in watched + in_progress:
if "MediaSources" in movie and movie["MediaSources"] != {}: # Skip if theres no user data which means the movie has not been watched
if "UserData" not in movie: if "UserData" not in movie:
continue continue
# Skip if not watched or watched less than a minute # Skip if theres no media tied to the movie
if ( if "MediaSources" not in movie or movie["MediaSources"] == {}:
movie["UserData"]["Played"] == True continue
or movie["UserData"]["PlaybackPositionTicks"] > 600000000
):
logger(
f"{self.server_type}: Adding {movie.get('Name')} to {user_name} watched list",
3,
)
# Get the movie's GUIDs # Skip if not watched or watched less than a minute
movie_guids = get_guids(self.server_type, movie) if (
movie["UserData"]["Played"] == True
or movie["UserData"]["PlaybackPositionTicks"] > 600000000
):
logger(
f"{self.server_type}: Adding {movie.get('Name')} to {user_name} watched list",
3,
)
# Append the movie dictionary to the list for the given user and library # Get the movie's GUIDs
user_watched[user_name][library_title].append(movie_guids) movie_guids = get_guids(self.server_type, movie)
logger(
f"{self.server_type}: Added {movie_guids} to {user_name} watched list", # Append the movie dictionary to the list for the given user and library
3, user_watched[user_name][library_title].append(movie_guids)
) logger(
f"{self.server_type}: Added {movie_guids} to {user_name} watched list",
3,
)
# TV Shows # TV Shows
if library_type in ["Series", "Episode"]: if library_type in ["Series", "Episode"]:
@ -272,21 +276,18 @@ class JellyfinEmby:
f"/Users/{user_id}/Items" f"/Users/{user_id}/Items"
+ f"?ParentId={library_id}&isPlaceHolder=false&IncludeItemTypes=Series&Recursive=True&Fields=ProviderIds,Path,RecursiveItemCount", + f"?ParentId={library_id}&isPlaceHolder=false&IncludeItemTypes=Series&Recursive=True&Fields=ProviderIds,Path,RecursiveItemCount",
"get", "get",
) ).get("Items", [])
# Filter the list of shows to only include those that have been partially or fully watched # Filter the list of shows to only include those that have been partially or fully watched
watched_shows_filtered = [] watched_shows_filtered = []
for show in watched_shows["Items"]: for show in watched_shows:
if not "UserData" in show: if "UserData" not in show:
continue continue
if "PlayedPercentage" in show["UserData"]: if "PlayedPercentage" in show["UserData"]:
if show["UserData"]["PlayedPercentage"] > 0: if show["UserData"]["PlayedPercentage"] > 0:
watched_shows_filtered.append(show) watched_shows_filtered.append(show)
# Create a list of tasks to retrieve the episodes
watched_episodes = []
# Retrieve the watched/partially watched list of episodes of each watched show # Retrieve the watched/partially watched list of episodes of each watched show
for show in watched_shows_filtered: for show in watched_shows_filtered:
logger( logger(
@ -308,54 +309,46 @@ class JellyfinEmby:
show_guids = frozenset(show_guids.items()) show_guids = frozenset(show_guids.items())
watched_task = self.query( show_episodes = self.query(
f"/Shows/{show['Id']}/Episodes" f"/Shows/{show['Id']}/Episodes"
+ f"?userId={user_id}&isPlaceHolder=false&Filters=IsPlayed&Fields=ProviderIds,MediaSources", + f"?userId={user_id}&isPlaceHolder=false&Fields=ProviderIds,MediaSources",
"get", "get",
) ).get("Items", [])
in_progress_task = self.query( # Iterate through the episodes
f"/Shows/{show['Id']}/Episodes" # Create a list to store the episodes
+ f"?userId={user_id}&isPlaceHolder=false&Filters=IsResumable&Fields=ProviderIds,MediaSources", mark_episodes_list = []
"get", for episode in show_episodes:
) if "UserData" not in episode:
watched_episodes.append(watched_task) continue
watched_episodes.append(in_progress_task)
# Iterate through the watched episodes if (
for episodes in watched_episodes: "MediaSources" not in episode
# If has any watched episodes or episode["MediaSources"] == {}
if len(episodes["Items"]) > 0: ):
# Create a list to store the episodes continue
episodes_list = []
for episode in episodes["Items"]:
if (
"MediaSources" in episode
and episode["MediaSources"] != {}
):
# If watched or watched more than a minute
if (
episode["UserData"]["Played"] == True
or episode["UserData"]["PlaybackPositionTicks"]
> 600000000
):
episode_guids = get_guids(
self.server_type, episode
)
episodes_list.append(episode_guids)
# Add the show dictionary to the user's watched list # If watched or watched more than a minute
if show_guids not in user_watched[user_name][library_title]: if (
user_watched[user_name][library_title][show_guids] = [] episode["UserData"]["Played"] == True
or episode["UserData"]["PlaybackPositionTicks"] > 600000000
):
episode_guids = get_guids(self.server_type, episode)
mark_episodes_list.append(episode_guids)
user_watched[user_name][library_title][ if mark_episodes_list:
show_guids # Add the show dictionary to the user's watched list
] = episodes_list if show_guids not in user_watched[user_name][library_title]:
for episode in episodes_list: user_watched[user_name][library_title][show_guids] = []
logger(
f"{self.server_type}: Added {episode} to {user_name} {show_display_name} watched list", user_watched[user_name][library_title][
1, show_guids
) ] = mark_episodes_list
for episode in mark_episodes_list:
logger(
f"{self.server_type}: Added {episode} to {user_name} {show_display_name} watched list",
1,
)
logger( logger(
f"{self.server_type}: Got watched for {user_name} in library {library_title}", f"{self.server_type}: Got watched for {user_name} in library {library_title}",

View File

@ -452,7 +452,7 @@ class Plex:
raise Exception(e) raise Exception(e)
def info(self) -> str: def info(self) -> str:
return f"{self.plex.friendlyName}: {self.plex.version}" return f"Plex {self.plex.friendlyName}: {self.plex.version}"
def get_users(self): def get_users(self):
try: try: