Cleanup
parent
ca84bbb19d
commit
4657097f6d
18
main.py
18
main.py
|
|
@ -37,7 +37,7 @@ def cleanup_watched(watched_list_1, watched_list_2, user_mapping=None, library_m
|
|||
else:
|
||||
logger(f"library {library_1} and {library_other} not found in watched list 2", 1)
|
||||
continue
|
||||
|
||||
|
||||
# Movies
|
||||
if isinstance(watched_list_1[user_1][library_1], list):
|
||||
for item in watched_list_1[user_1][library_1]:
|
||||
|
|
@ -49,13 +49,13 @@ def cleanup_watched(watched_list_1, watched_list_2, user_mapping=None, library_m
|
|||
logger(f"Removing {item} from {library_1}", 1)
|
||||
modified_watched_list_1[user_1][library_1].remove(item)
|
||||
|
||||
|
||||
|
||||
# TV Shows
|
||||
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)
|
||||
|
||||
for show_key_1, show_item_1 in watched_list_1[user_1][library_1].items():
|
||||
|
||||
for show_key_1 in watched_list_1[user_1][library_1].keys():
|
||||
show_key_dict = dict(show_key_1)
|
||||
for season in watched_list_1[user_1][library_1][show_key_1]:
|
||||
for episode in watched_list_1[user_1][library_1][show_key_1][season]:
|
||||
|
|
@ -66,7 +66,7 @@ def cleanup_watched(watched_list_1, watched_list_2, user_mapping=None, library_m
|
|||
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}", 1)
|
||||
modified_watched_list_1[user_1][library_1][show_key_1][season].remove(episode)
|
||||
|
||||
|
||||
# Remove empty seasons
|
||||
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]:
|
||||
|
|
@ -263,15 +263,15 @@ def main():
|
|||
|
||||
plex_watched = plex.get_plex_watched(plex_users, blacklist_library, whitelist_library, blacklist_library_type, whitelist_library_type, library_mapping)
|
||||
jellyfin_watched = jellyfin.get_jellyfin_watched(jellyfin_users, blacklist_library, whitelist_library, blacklist_library_type, whitelist_library_type, library_mapping)
|
||||
|
||||
|
||||
# clone watched so it isnt modified in the cleanup function so all duplicates are actually removed
|
||||
plex_watched_filtered = copy.deepcopy(plex_watched)
|
||||
jellyfin_watched_filtered = copy.deepcopy(jellyfin_watched)
|
||||
|
||||
logger(f"Cleaning Plex Watched", 1)
|
||||
logger("Cleaning Plex Watched", 1)
|
||||
plex_watched = cleanup_watched(plex_watched_filtered, jellyfin_watched_filtered, user_mapping, library_mapping)
|
||||
|
||||
logger(f"Cleaning Jellyfin Watched", 1)
|
||||
logger("Cleaning Jellyfin Watched", 1)
|
||||
jellyfin_watched = cleanup_watched(jellyfin_watched_filtered, plex_watched_filtered, user_mapping, library_mapping)
|
||||
|
||||
logger(f"plex_watched that needs to be synced to jellyfin:\n{plex_watched}", 1)
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ def generate_library_guids_dict(user_list: dict, generate_output: int):
|
|||
if provider_key.lower() not in show_output_dict:
|
||||
show_output_dict[provider_key.lower()] = []
|
||||
show_output_dict[provider_key.lower()].append(prvider_value.lower())
|
||||
|
||||
|
||||
if generate_output in (1, 3):
|
||||
for show in user_list:
|
||||
for season in user_list[show]:
|
||||
|
|
@ -101,7 +101,7 @@ def generate_library_guids_dict(user_list: dict, generate_output: int):
|
|||
if episode_key.lower() not in episode_output_dict:
|
||||
episode_output_dict[episode_key.lower()] = []
|
||||
episode_output_dict[episode_key.lower()].append(episode_value.lower())
|
||||
|
||||
|
||||
if generate_output == 2:
|
||||
for movie in user_list:
|
||||
for movie_key, movie_value in movie.items():
|
||||
|
|
|
|||
|
|
@ -186,12 +186,12 @@ class Jellyfin():
|
|||
# Movies
|
||||
if library_type == "Movie":
|
||||
_, _, videos_movies_ids = generate_library_guids_dict(videos, 2)
|
||||
|
||||
|
||||
jellyfin_search = self.query(f"/Users/{user_id}/Items?SortBy=SortName&SortOrder=Ascending&Recursive=false&ParentId={library_id}&isPlayed=false&Fields=ItemCounts,ProviderIds", "get")
|
||||
for jellyfin_video in jellyfin_search["Items"]:
|
||||
if str_to_bool(jellyfin_video["UserData"]["Played"]) == False:
|
||||
jellyfin_video_id = jellyfin_video["Id"]
|
||||
|
||||
|
||||
for movie_provider_source, movie_provider_id in jellyfin_video["ProviderIds"].items():
|
||||
if movie_provider_source.lower() in videos_movies_ids:
|
||||
if movie_provider_id.lower() in videos_movies_ids[movie_provider_source.lower()]:
|
||||
|
|
@ -206,7 +206,7 @@ class Jellyfin():
|
|||
# TV Shows
|
||||
if library_type == "Episode":
|
||||
videos_shows_ids, videos_episode_ids, _ = generate_library_guids_dict(videos, 3)
|
||||
|
||||
|
||||
jellyfin_search = self.query(f"/Users/{user_id}/Items?SortBy=SortName&SortOrder=Ascending&Recursive=false&ParentId={library_id}&isPlayed=false&Fields=ItemCounts,ProviderIds", "get")
|
||||
jellyfin_shows = [x for x in jellyfin_search["Items"]]
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ class Jellyfin():
|
|||
for jellyfin_episode in jellyfin_episodes["Items"]:
|
||||
if str_to_bool(jellyfin_episode["UserData"]["Played"]) == False:
|
||||
jellyfin_episode_id = jellyfin_episode["Id"]
|
||||
|
||||
|
||||
for episode_provider_source, episode_provider_id in jellyfin_episode["ProviderIds"].items():
|
||||
if episode_provider_source.lower() in videos_episode_ids:
|
||||
if episode_provider_id.lower() in videos_episode_ids[episode_provider_source.lower()]:
|
||||
|
|
@ -232,6 +232,6 @@ class Jellyfin():
|
|||
else:
|
||||
logger(f"Dryrun {msg}", 0)
|
||||
break
|
||||
|
||||
|
||||
if show_found:
|
||||
break
|
||||
|
|
|
|||
12
src/plex.py
12
src/plex.py
|
|
@ -1,4 +1,4 @@
|
|||
import re, os, time
|
||||
import re, os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from src.functions import logger, search_mapping, check_skip_logic, generate_library_guids_dict
|
||||
|
|
@ -86,7 +86,7 @@ class Plex:
|
|||
show_guid_id = re.search(r'://(.*)', show_guid.id).group(1)
|
||||
show_guids[show_guid_source] = show_guid_id
|
||||
show_guids = frozenset(show_guids.items())
|
||||
|
||||
|
||||
for season in show.seasons():
|
||||
episode_guids = []
|
||||
for episode in season.episodes():
|
||||
|
|
@ -202,7 +202,7 @@ class Plex:
|
|||
else:
|
||||
logger(f"Dryrun {msg}", 0)
|
||||
break
|
||||
|
||||
|
||||
|
||||
elif library_videos.type == "show":
|
||||
videos_shows_ids, videos_episode_ids, _ = generate_library_guids_dict(videos, 3)
|
||||
|
|
@ -221,7 +221,7 @@ class Plex:
|
|||
for episode_guid in episode_search.guids:
|
||||
episode_guid_source = re.search(r'(.*)://', episode_guid.id).group(1).lower()
|
||||
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_guid_source in videos_episode_ids.keys():
|
||||
if episode_guid_id in videos_episode_ids[episode_guid_source]:
|
||||
|
|
@ -233,6 +233,6 @@ class Plex:
|
|||
else:
|
||||
logger(f"Dryrun {msg}", 0)
|
||||
break
|
||||
|
||||
|
||||
if show_found:
|
||||
break
|
||||
break
|
||||
|
|
|
|||
Loading…
Reference in New Issue