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,19 +229,23 @@ 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 theres no media tied to the movie
if "MediaSources" not in movie or movie["MediaSources"] == {}:
continue
# Skip if not watched or watched less than a minute # Skip if not watched or watched less than a minute
if ( if (
movie["UserData"]["Played"] == True movie["UserData"]["Played"] == True
@ -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,50 +309,42 @@ 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"
+ f"?userId={user_id}&isPlaceHolder=false&Filters=IsResumable&Fields=ProviderIds,MediaSources",
"get",
)
watched_episodes.append(watched_task)
watched_episodes.append(in_progress_task)
# Iterate through the watched episodes
for episodes in watched_episodes:
# If has any watched episodes
if len(episodes["Items"]) > 0:
# Create a list to store the episodes # Create a list to store the episodes
episodes_list = [] mark_episodes_list = []
for episode in episodes["Items"]: for episode in show_episodes:
if "UserData" not in episode:
continue
if ( if (
"MediaSources" in episode "MediaSources" not in episode
and episode["MediaSources"] != {} or episode["MediaSources"] == {}
): ):
continue
# If watched or watched more than a minute # If watched or watched more than a minute
if ( if (
episode["UserData"]["Played"] == True episode["UserData"]["Played"] == True
or episode["UserData"]["PlaybackPositionTicks"] or episode["UserData"]["PlaybackPositionTicks"] > 600000000
> 600000000
): ):
episode_guids = get_guids( episode_guids = get_guids(self.server_type, episode)
self.server_type, episode mark_episodes_list.append(episode_guids)
)
episodes_list.append(episode_guids)
if mark_episodes_list:
# Add the show dictionary to the user's watched list # Add the show dictionary to the user's watched list
if show_guids not in user_watched[user_name][library_title]: if show_guids not in user_watched[user_name][library_title]:
user_watched[user_name][library_title][show_guids] = [] user_watched[user_name][library_title][show_guids] = []
user_watched[user_name][library_title][ user_watched[user_name][library_title][
show_guids show_guids
] = episodes_list ] = mark_episodes_list
for episode in episodes_list: for episode in mark_episodes_list:
logger( logger(
f"{self.server_type}: Added {episode} to {user_name} {show_display_name} watched list", f"{self.server_type}: Added {episode} to {user_name} {show_display_name} watched list",
1, 1,

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: