Use generate_library_guids_dict instead of library type
parent
de619de923
commit
a3f3db8f4e
|
|
@ -80,13 +80,12 @@ def check_skip_logic(library_title, library_type, blacklist_library, whitelist_l
|
||||||
return skip_reason
|
return skip_reason
|
||||||
|
|
||||||
|
|
||||||
def generate_library_guids_dict(user_list: dict, generate_output: int):
|
def generate_library_guids_dict(user_list: dict):
|
||||||
# if generate_output is 0 then only generate shows, if 1 then only generate episodes, if 2 then generate movies, if 3 then generate shows and episodes
|
|
||||||
show_output_dict = {}
|
show_output_dict = {}
|
||||||
episode_output_dict = {}
|
episode_output_dict = {}
|
||||||
movies_output_dict = {}
|
movies_output_dict = {}
|
||||||
|
|
||||||
if generate_output in (0, 3):
|
try:
|
||||||
show_output_keys = user_list.keys()
|
show_output_keys = user_list.keys()
|
||||||
show_output_keys = ([ dict(x) for x in list(show_output_keys) ])
|
show_output_keys = ([ dict(x) for x in list(show_output_keys) ])
|
||||||
for show_key in show_output_keys:
|
for show_key in show_output_keys:
|
||||||
|
|
@ -101,8 +100,10 @@ def generate_library_guids_dict(user_list: dict, generate_output: int):
|
||||||
show_output_dict[provider_key.lower()].append(show_location)
|
show_output_dict[provider_key.lower()].append(show_location)
|
||||||
else:
|
else:
|
||||||
show_output_dict[provider_key.lower()].append(provider_value.lower())
|
show_output_dict[provider_key.lower()].append(provider_value.lower())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if generate_output in (1, 3):
|
try:
|
||||||
for show in user_list:
|
for show in user_list:
|
||||||
for season in user_list[show]:
|
for season in user_list[show]:
|
||||||
for episode in user_list[show][season]:
|
for episode in user_list[show][season]:
|
||||||
|
|
@ -114,8 +115,10 @@ def generate_library_guids_dict(user_list: dict, generate_output: int):
|
||||||
episode_output_dict[episode_key.lower()].append(episode_location)
|
episode_output_dict[episode_key.lower()].append(episode_location)
|
||||||
else:
|
else:
|
||||||
episode_output_dict[episode_key.lower()].append(episode_value.lower())
|
episode_output_dict[episode_key.lower()].append(episode_value.lower())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if generate_output == 2:
|
try:
|
||||||
for movie in user_list:
|
for movie in user_list:
|
||||||
for movie_key, movie_value in movie.items():
|
for movie_key, movie_value in movie.items():
|
||||||
if movie_key.lower() not in movies_output_dict:
|
if movie_key.lower() not in movies_output_dict:
|
||||||
|
|
@ -125,6 +128,8 @@ def generate_library_guids_dict(user_list: dict, generate_output: int):
|
||||||
movies_output_dict[movie_key.lower()].append(movie_location)
|
movies_output_dict[movie_key.lower()].append(movie_location)
|
||||||
else:
|
else:
|
||||||
movies_output_dict[movie_key.lower()].append(movie_value.lower())
|
movies_output_dict[movie_key.lower()].append(movie_value.lower())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return show_output_dict, episode_output_dict, movies_output_dict
|
return show_output_dict, episode_output_dict, movies_output_dict
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,13 +165,11 @@ class Jellyfin():
|
||||||
def update_user_watched(self, user_name, 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_name} 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")
|
videos_shows_ids, videos_episodes_ids, videos_movies_ids = generate_library_guids_dict(videos)
|
||||||
library_type = library_search["Items"][0]["Type"]
|
|
||||||
|
|
||||||
# Movies
|
logger(f"Jellyfin: mark list\nShows: {videos_shows_ids}\nEpisodes: {videos_episodes_ids}\nMovies: {videos_movies_ids}", 1)
|
||||||
if library_type == "Movie":
|
|
||||||
_, _, videos_movies_ids = generate_library_guids_dict(videos, 2)
|
|
||||||
|
|
||||||
|
if videos_movies_ids:
|
||||||
jellyfin_search = self.query(f"/Users/{user_id}/Items?SortBy=SortName&SortOrder=Ascending&Recursive=false&ParentId={library_id}&isPlayed=false&Fields=ItemCounts,ProviderIds,MediaSources", "get")
|
jellyfin_search = self.query(f"/Users/{user_id}/Items?SortBy=SortName&SortOrder=Ascending&Recursive=false&ParentId={library_id}&isPlayed=false&Fields=ItemCounts,ProviderIds,MediaSources", "get")
|
||||||
for jellyfin_video in jellyfin_search["Items"]:
|
for jellyfin_video in jellyfin_search["Items"]:
|
||||||
movie_found = False
|
movie_found = False
|
||||||
|
|
@ -200,11 +198,7 @@ class Jellyfin():
|
||||||
|
|
||||||
|
|
||||||
# TV Shows
|
# TV Shows
|
||||||
if library_type == "Episode":
|
if videos_shows_ids and videos_episodes_ids:
|
||||||
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"]]
|
||||||
|
|
||||||
|
|
@ -232,14 +226,14 @@ class Jellyfin():
|
||||||
|
|
||||||
if "MediaSources" in jellyfin_episode:
|
if "MediaSources" in jellyfin_episode:
|
||||||
for episode_location in jellyfin_episode["MediaSources"]:
|
for episode_location in jellyfin_episode["MediaSources"]:
|
||||||
if episode_location["Path"].split("/")[-1] in videos_episode_ids["locations"]:
|
if episode_location["Path"].split("/")[-1] in videos_episodes_ids["locations"]:
|
||||||
episode_found = True
|
episode_found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if not episode_found:
|
if not episode_found:
|
||||||
for episode_provider_source, episode_provider_id in jellyfin_episode["ProviderIds"].items():
|
for episode_provider_source, episode_provider_id in jellyfin_episode["ProviderIds"].items():
|
||||||
if episode_provider_source.lower() in videos_episode_ids:
|
if episode_provider_source.lower() in videos_episodes_ids:
|
||||||
if episode_provider_id.lower() in videos_episode_ids[episode_provider_source.lower()]:
|
if episode_provider_id.lower() in videos_episodes_ids[episode_provider_source.lower()]:
|
||||||
episode_found = True
|
episode_found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -256,7 +250,7 @@ class Jellyfin():
|
||||||
else:
|
else:
|
||||||
logger(f"Jellyfin: Skipping show {jellyfin_show['Name']} as it is not in mark list for {user_name}", 1)
|
logger(f"Jellyfin: Skipping show {jellyfin_show['Name']} as it is not in mark list for {user_name}", 1)
|
||||||
else:
|
else:
|
||||||
logger(f"Jellyfin: Library {library} is not a TV Show or Movie, skipping", 2)
|
logger(f"Jellyfin: Library {library} is not a TV Show or Movie, skipping\n{library_search}", 2)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger(f"Jellyfin: Error updating watched for {user_name} in library {library}", 2)
|
logger(f"Jellyfin: Error updating watched for {user_name} in library {library}", 2)
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ def cleanup_watched(watched_list_1, watched_list_2, user_mapping=None, library_m
|
||||||
|
|
||||||
# Movies
|
# Movies
|
||||||
if isinstance(watched_list_1[user_1][library_1], list):
|
if isinstance(watched_list_1[user_1][library_1], list):
|
||||||
_, _, movies_watched_list_2_keys_dict = generate_library_guids_dict(watched_list_2[user_2][library_2], 2)
|
_, _, movies_watched_list_2_keys_dict = generate_library_guids_dict(watched_list_2[user_2][library_2])
|
||||||
for movie in watched_list_1[user_1][library_1]:
|
for movie in watched_list_1[user_1][library_1]:
|
||||||
movie_found = False
|
movie_found = False
|
||||||
for movie_key, movie_value in movie.items():
|
for movie_key, movie_value in movie.items():
|
||||||
|
|
@ -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
|
||||||
_, episode_watched_list_2_keys_dict, _ = generate_library_guids_dict(watched_list_2[user_2][library_2], 1)
|
_, episode_watched_list_2_keys_dict, _ = generate_library_guids_dict(watched_list_2[user_2][library_2])
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
||||||
19
src/plex.py
19
src/plex.py
|
|
@ -162,10 +162,11 @@ class Plex:
|
||||||
def update_user_watched (self, user, user_plex, library, videos, dryrun):
|
def update_user_watched (self, user, user_plex, library, videos, dryrun):
|
||||||
try:
|
try:
|
||||||
logger(f"Plex: Updating watched for {user.title} in library {library}", 1)
|
logger(f"Plex: Updating watched for {user.title} in library {library}", 1)
|
||||||
library_videos = user_plex.library.section(library)
|
videos_shows_ids, videos_episodes_ids, videos_movies_ids = generate_library_guids_dict(videos)
|
||||||
|
logger(f"Plex: mark list\nShows: {videos_shows_ids}\nEpisodes: {videos_episodes_ids}\nMovies: {videos_movies_ids}", 1)
|
||||||
|
|
||||||
if library_videos.type == "movie":
|
library_videos = user_plex.library.section(library)
|
||||||
_, _, videos_movies_ids = generate_library_guids_dict(videos, 2)
|
if videos_movies_ids:
|
||||||
for movies_search in library_videos.search(unwatched=True):
|
for movies_search in library_videos.search(unwatched=True):
|
||||||
movie_found = False
|
movie_found = False
|
||||||
for movie_location in movies_search.locations:
|
for movie_location in movies_search.locations:
|
||||||
|
|
@ -193,9 +194,7 @@ class Plex:
|
||||||
logger(f"Dryrun {msg}", 0)
|
logger(f"Dryrun {msg}", 0)
|
||||||
|
|
||||||
|
|
||||||
elif library_videos.type == "show":
|
if videos_shows_ids and videos_episodes_ids:
|
||||||
videos_shows_ids, videos_episode_ids, _ = generate_library_guids_dict(videos, 3)
|
|
||||||
|
|
||||||
for show_search in library_videos.search(unwatched=True):
|
for show_search in library_videos.search(unwatched=True):
|
||||||
show_found = False
|
show_found = False
|
||||||
for show_location in show_search.locations:
|
for show_location in show_search.locations:
|
||||||
|
|
@ -219,7 +218,7 @@ class Plex:
|
||||||
episode_found = False
|
episode_found = False
|
||||||
|
|
||||||
for episode_location in episode_search.locations:
|
for episode_location in episode_search.locations:
|
||||||
if episode_location.split("/")[-1] in videos_episode_ids["locations"]:
|
if episode_location.split("/")[-1] in videos_episodes_ids["locations"]:
|
||||||
episode_found = True
|
episode_found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -228,9 +227,9 @@ class Plex:
|
||||||
episode_guid_source = re.search(r'(.*)://', episode_guid.id).group(1).lower()
|
episode_guid_source = re.search(r'(.*)://', episode_guid.id).group(1).lower()
|
||||||
episode_guid_id = re.search(r'://(.*)', episode_guid.id).group(1)
|
episode_guid_id = re.search(r'://(.*)', episode_guid.id).group(1)
|
||||||
|
|
||||||
# If episode provider source and episode provider id are in videos_episode_ids exactly, then the episode is in the list
|
# If episode provider source and episode provider id are in videos_episodes_ids exactly, then the episode is in the list
|
||||||
if episode_guid_source in videos_episode_ids.keys():
|
if episode_guid_source in videos_episodes_ids.keys():
|
||||||
if episode_guid_id in videos_episode_ids[episode_guid_source]:
|
if episode_guid_id in videos_episodes_ids[episode_guid_source]:
|
||||||
episode_found = True
|
episode_found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue