Add more logging, fix username in jellyfin mark.
This commit is contained in:
@@ -162,9 +162,9 @@ class Jellyfin():
|
|||||||
logger(f"Jellyfin: Failed to get watched, Error: {e}", 2)
|
logger(f"Jellyfin: Failed to get watched, Error: {e}", 2)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
def update_user_watched(self, user, user_id, library, library_id, videos, dryrun):
|
def update_user_watched(self, user_name, user_id, library, library_id, videos, dryrun):
|
||||||
try:
|
try:
|
||||||
logger(f"Jellyfin: Updating watched for {user} in library {library}", 1)
|
logger(f"Jellyfin: Updating watched for {user_name} in library {library}", 1)
|
||||||
library_search = self.query(f"/Users/{user_id}/Items?SortBy=SortName&SortOrder=Ascending&Recursive=true&ParentId={library_id}&limit=1", "get")
|
library_search = self.query(f"/Users/{user_id}/Items?SortBy=SortName&SortOrder=Ascending&Recursive=true&ParentId={library_id}&limit=1", "get")
|
||||||
library_type = library_search["Items"][0]["Type"]
|
library_type = library_search["Items"][0]["Type"]
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ class Jellyfin():
|
|||||||
|
|
||||||
if movie_found:
|
if movie_found:
|
||||||
jellyfin_video_id = jellyfin_video["Id"]
|
jellyfin_video_id = jellyfin_video["Id"]
|
||||||
msg = f"{jellyfin_video['Name']} as watched for {user} in {library} for Jellyfin"
|
msg = f"{jellyfin_video['Name']} as watched for {user_name} in {library} for Jellyfin"
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
logger(f"Marking {msg}", 0)
|
logger(f"Marking {msg}", 0)
|
||||||
self.query(f"/Users/{user_id}/PlayedItems/{jellyfin_video_id}", "post")
|
self.query(f"/Users/{user_id}/PlayedItems/{jellyfin_video_id}", "post")
|
||||||
@@ -203,15 +203,14 @@ class Jellyfin():
|
|||||||
if library_type == "Episode":
|
if library_type == "Episode":
|
||||||
videos_shows_ids, videos_episode_ids, _ = generate_library_guids_dict(videos, 3)
|
videos_shows_ids, videos_episode_ids, _ = generate_library_guids_dict(videos, 3)
|
||||||
|
|
||||||
|
logger(f"Jellyfin: shows to mark {videos_shows_ids}\nepisodes to mark {videos_episode_ids}", 1)
|
||||||
|
|
||||||
jellyfin_search = self.query(f"/Users/{user_id}/Items?SortBy=SortName&SortOrder=Ascending&Recursive=false&ParentId={library_id}&isPlayed=false&Fields=ItemCounts,ProviderIds,Path", "get")
|
jellyfin_search = self.query(f"/Users/{user_id}/Items?SortBy=SortName&SortOrder=Ascending&Recursive=false&ParentId={library_id}&isPlayed=false&Fields=ItemCounts,ProviderIds,Path", "get")
|
||||||
jellyfin_shows = [x for x in jellyfin_search["Items"]]
|
jellyfin_shows = [x for x in jellyfin_search["Items"]]
|
||||||
|
|
||||||
for jellyfin_show in jellyfin_shows:
|
for jellyfin_show in jellyfin_shows:
|
||||||
show_found = False
|
show_found = False
|
||||||
|
|
||||||
if jellyfin_show["Name"] == "The 13 Ghosts of Scooby-Doo":
|
|
||||||
print(jellyfin_show)
|
|
||||||
|
|
||||||
if "Path" in jellyfin_show:
|
if "Path" in jellyfin_show:
|
||||||
if jellyfin_show["Path"].split("/")[-1] in videos_shows_ids["locations"]:
|
if jellyfin_show["Path"].split("/")[-1] in videos_shows_ids["locations"]:
|
||||||
show_found = True
|
show_found = True
|
||||||
@@ -224,6 +223,7 @@ class Jellyfin():
|
|||||||
break
|
break
|
||||||
|
|
||||||
if show_found:
|
if show_found:
|
||||||
|
logger(f"Jellyfin: Updating watched for {user_name} in library {library} for show {jellyfin_show['Name']}", 1)
|
||||||
jellyfin_show_id = jellyfin_show["Id"]
|
jellyfin_show_id = jellyfin_show["Id"]
|
||||||
jellyfin_episodes = self.query(f"/Shows/{jellyfin_show_id}/Episodes?userId={user_id}&Fields=ItemCounts,ProviderIds,MediaSources", "get")
|
jellyfin_episodes = self.query(f"/Shows/{jellyfin_show_id}/Episodes?userId={user_id}&Fields=ItemCounts,ProviderIds,MediaSources", "get")
|
||||||
|
|
||||||
@@ -245,15 +245,21 @@ class Jellyfin():
|
|||||||
|
|
||||||
if episode_found:
|
if episode_found:
|
||||||
jellyfin_episode_id = jellyfin_episode["Id"]
|
jellyfin_episode_id = jellyfin_episode["Id"]
|
||||||
msg = f"{jellyfin_episode['SeriesName']} {jellyfin_episode['SeasonName']} Episode {jellyfin_episode['IndexNumber']} {jellyfin_episode['Name']} as watched for {user} in {library} for Jellyfin"
|
msg = f"{jellyfin_episode['SeriesName']} {jellyfin_episode['SeasonName']} Episode {jellyfin_episode['IndexNumber']} {jellyfin_episode['Name']} as watched for {user_name} in {library} for Jellyfin"
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
logger(f"Marked {msg}", 0)
|
logger(f"Marked {msg}", 0)
|
||||||
self.query(f"/Users/{user_id}/PlayedItems/{jellyfin_episode_id}", "post")
|
self.query(f"/Users/{user_id}/PlayedItems/{jellyfin_episode_id}", "post")
|
||||||
else:
|
else:
|
||||||
logger(f"Dryrun {msg}", 0)
|
logger(f"Dryrun {msg}", 0)
|
||||||
|
else:
|
||||||
|
logger(f"Jellyfin: Skipping episode {jellyfin_episode['SeriesName']} {jellyfin_episode['SeasonName']} Episode {jellyfin_episode['IndexNumber']} {jellyfin_episode['Name']} as it is not in mark list for {user_name}", 1)
|
||||||
|
else:
|
||||||
|
logger(f"Jellyfin: Skipping show {jellyfin_show['Name']} as it is not in mark list for {user_name}", 1)
|
||||||
|
else:
|
||||||
|
logger(f"Jellyfin: Library {library} is not a TV Show or Movie, skipping", 2)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger(f"Jellyfin: Error updating watched for {user} in library {library}", 2)
|
logger(f"Jellyfin: Error updating watched for {user_name} in library {library}", 2)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
|
|
||||||
@@ -261,7 +267,9 @@ class Jellyfin():
|
|||||||
try:
|
try:
|
||||||
args = []
|
args = []
|
||||||
for user, libraries in watched_list.items():
|
for user, libraries in watched_list.items():
|
||||||
|
logger(f"Jellyfin: Updating for entry {user}, {libraries}", 1)
|
||||||
user_other = None
|
user_other = None
|
||||||
|
user_name = None
|
||||||
if user_mapping:
|
if user_mapping:
|
||||||
if user in user_mapping.keys():
|
if user in user_mapping.keys():
|
||||||
user_other = user_mapping[user]
|
user_other = user_mapping[user]
|
||||||
@@ -272,9 +280,11 @@ class Jellyfin():
|
|||||||
for key in self.users.keys():
|
for key in self.users.keys():
|
||||||
if user.lower() == key.lower():
|
if user.lower() == key.lower():
|
||||||
user_id = self.users[key]
|
user_id = self.users[key]
|
||||||
|
user_name = key
|
||||||
break
|
break
|
||||||
elif user_other and user_other.lower() == key.lower():
|
elif user_other and user_other.lower() == key.lower():
|
||||||
user_id = self.users[key]
|
user_id = self.users[key]
|
||||||
|
user_name = key
|
||||||
break
|
break
|
||||||
|
|
||||||
if not user_id:
|
if not user_id:
|
||||||
@@ -311,7 +321,7 @@ class Jellyfin():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if library_id:
|
if library_id:
|
||||||
args.append([self.update_user_watched, user, user_id, library, library_id, videos, dryrun])
|
args.append([self.update_user_watched, user_name, user_id, library, library_id, videos, dryrun])
|
||||||
|
|
||||||
future_thread_executor(args)
|
future_thread_executor(args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ def cleanup_watched(watched_list_1, watched_list_2, user_mapping=None, library_m
|
|||||||
# TV Shows
|
# TV Shows
|
||||||
elif isinstance(watched_list_1[user_1][library_1], dict):
|
elif isinstance(watched_list_1[user_1][library_1], dict):
|
||||||
# Generate full list of provider ids for episodes in watch_list_2 to easily compare if they exist in watch_list_1
|
# Generate full list of provider ids for episodes in watch_list_2 to easily compare if they exist in watch_list_1
|
||||||
show_watched_list_2_keys_dict, episode_watched_list_2_keys_dict, _ = generate_library_guids_dict(watched_list_2[user_2][library_2], 3)
|
_, episode_watched_list_2_keys_dict, _ = generate_library_guids_dict(watched_list_2[user_2][library_2], 1)
|
||||||
|
|
||||||
for show_key_1 in watched_list_1[user_1][library_1].keys():
|
for show_key_1 in watched_list_1[user_1][library_1].keys():
|
||||||
show_key_dict = dict(show_key_1)
|
show_key_dict = dict(show_key_1)
|
||||||
@@ -85,14 +85,14 @@ def cleanup_watched(watched_list_1, watched_list_2, user_mapping=None, library_m
|
|||||||
|
|
||||||
if episode_found:
|
if episode_found:
|
||||||
if episode in modified_watched_list_1[user_1][library_1][show_key_1][season]:
|
if episode in modified_watched_list_1[user_1][library_1][show_key_1][season]:
|
||||||
logger(f"Removing {show_key_dict['title']} {episode} from {library_1}", 3)
|
logger(f"Removing {episode} from {show_key_dict['title']}", 3)
|
||||||
modified_watched_list_1[user_1][library_1][show_key_1][season].remove(episode)
|
modified_watched_list_1[user_1][library_1][show_key_1][season].remove(episode)
|
||||||
break
|
break
|
||||||
|
|
||||||
# Remove empty seasons
|
# Remove empty seasons
|
||||||
if len(modified_watched_list_1[user_1][library_1][show_key_1][season]) == 0:
|
if len(modified_watched_list_1[user_1][library_1][show_key_1][season]) == 0:
|
||||||
if season in modified_watched_list_1[user_1][library_1][show_key_1]:
|
if season in modified_watched_list_1[user_1][library_1][show_key_1]:
|
||||||
logger(f"Removing {season} from {library_1} because it is empty", 3)
|
logger(f"Removing {season} from {show_key_dict['title']} because it is empty", 3)
|
||||||
del modified_watched_list_1[user_1][library_1][show_key_1][season]
|
del modified_watched_list_1[user_1][library_1][show_key_1][season]
|
||||||
|
|
||||||
# If the show is empty, remove the show
|
# If the show is empty, remove the show
|
||||||
|
|||||||
26
src/plex.py
26
src/plex.py
@@ -185,13 +185,12 @@ class Plex:
|
|||||||
break
|
break
|
||||||
|
|
||||||
if movie_found:
|
if movie_found:
|
||||||
if movies_search.viewCount == 0:
|
msg = f"{movies_search.title} as watched for {user.title} in {library} for Plex"
|
||||||
msg = f"{movies_search.title} as watched for {user.title} in {library} for Plex"
|
if not dryrun:
|
||||||
if not dryrun:
|
logger(f"Marked {msg}", 0)
|
||||||
logger(f"Marked {msg}", 0)
|
movies_search.markWatched()
|
||||||
movies_search.markWatched()
|
else:
|
||||||
else:
|
logger(f"Dryrun {msg}", 0)
|
||||||
logger(f"Dryrun {msg}", 0)
|
|
||||||
|
|
||||||
|
|
||||||
elif library_videos.type == "show":
|
elif library_videos.type == "show":
|
||||||
@@ -236,13 +235,12 @@ class Plex:
|
|||||||
break
|
break
|
||||||
|
|
||||||
if episode_found:
|
if episode_found:
|
||||||
if episode_search.viewCount == 0:
|
msg = f"{show_search.title} {episode_search.title} as watched for {user.title} in {library} for Plex"
|
||||||
msg = f"{show_search.title} {episode_search.title} as watched for {user.title} in {library} for Plex"
|
if not dryrun:
|
||||||
if not dryrun:
|
logger(f"Marked {msg}", 0)
|
||||||
logger(f"Marked {msg}", 0)
|
episode_search.markWatched()
|
||||||
episode_search.markWatched()
|
else:
|
||||||
else:
|
logger(f"Dryrun {msg}", 0)
|
||||||
logger(f"Dryrun {msg}", 0)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger(f"Plex: Failed to update watched for {user.title} in library {library}, Error: {e}", 2)
|
logger(f"Plex: Failed to update watched for {user.title} in library {library}, Error: {e}", 2)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|||||||
Reference in New Issue
Block a user