Handle episode names are not unique
This commit is contained in:
@@ -97,7 +97,7 @@ def cleanup_watched(
|
||||
continue
|
||||
|
||||
(
|
||||
_,
|
||||
show_watched_list_2_keys_dict,
|
||||
episode_watched_list_2_keys_dict,
|
||||
movies_watched_list_2_keys_dict,
|
||||
) = generate_library_guids_dict(watched_list_2[user_2][library_2])
|
||||
@@ -123,11 +123,18 @@ def cleanup_watched(
|
||||
show_key_dict = dict(show_key_1)
|
||||
|
||||
for season in watched_list_1[user_1][library_1][show_key_1]:
|
||||
# Filter the episode_watched_list_2_keys_dict dictionary to handle cases
|
||||
# where episode location names are not unique such as S01E01.mkv
|
||||
filtered_episode_watched_list_2_keys_dict = (
|
||||
filter_episode_watched_list_2_keys_dict(
|
||||
episode_watched_list_2_keys_dict, show_key_dict, season
|
||||
)
|
||||
)
|
||||
for episode in watched_list_1[user_1][library_1][show_key_1][
|
||||
season
|
||||
]:
|
||||
episode_index = get_episode_index_in_dict(
|
||||
episode, episode_watched_list_2_keys_dict
|
||||
episode, filtered_episode_watched_list_2_keys_dict
|
||||
)
|
||||
if episode_index is not None:
|
||||
if check_remove_entry(
|
||||
@@ -223,6 +230,56 @@ def get_movie_index_in_dict(movie, movies_watched_list_2_keys_dict):
|
||||
return None
|
||||
|
||||
|
||||
def filter_episode_watched_list_2_keys_dict(
|
||||
episode_watched_list_2_keys_dict, show_key_dict, season
|
||||
):
|
||||
# Filter the episode_watched_list_2_keys_dict dictionary to only include values for the correct show and season
|
||||
filtered_episode_watched_list_2_keys_dict = {}
|
||||
show_indecies = []
|
||||
season_indecies = []
|
||||
|
||||
# Iterate through episode_watched_list_2_keys_dict["season"] and find the indecies that match season
|
||||
for season_index, season_value in enumerate(
|
||||
episode_watched_list_2_keys_dict["season"]
|
||||
):
|
||||
if season_value == season:
|
||||
season_indecies.append(season_index)
|
||||
|
||||
# Iterate through episode_watched_list_2_keys_dict["show"] and find the indecies that match show_key_dict
|
||||
for show_index, show_value in enumerate(episode_watched_list_2_keys_dict["show"]):
|
||||
# Iterate through the keys and values of the show_value dictionary and check if they match show_key_dict
|
||||
for show_key, show_key_value in show_value.items():
|
||||
if show_key == "locations":
|
||||
# Iterate through the locations in the show_value dictionary
|
||||
for location in show_key_value:
|
||||
# If the location is in the episode_watched_list_2_keys_dict dictionary, return index of the key
|
||||
if (
|
||||
contains_nested(location, show_key_dict["locations"])
|
||||
is not None
|
||||
):
|
||||
show_indecies.append(show_index)
|
||||
break
|
||||
else:
|
||||
if show_key in show_key_dict.keys():
|
||||
if show_key_value == show_key_dict[show_key]:
|
||||
show_indecies.append(show_index)
|
||||
break
|
||||
|
||||
# Find the intersection of the show_indecies and season_indecies lists
|
||||
indecies = list(set(show_indecies) & set(season_indecies))
|
||||
|
||||
# Create a copy of the dictionary with indecies that match the show and season and none that don't
|
||||
filtered_episode_watched_list_2_keys_dict = copy.deepcopy(
|
||||
episode_watched_list_2_keys_dict
|
||||
)
|
||||
for key, value in filtered_episode_watched_list_2_keys_dict.items():
|
||||
for index, item in enumerate(value):
|
||||
if index not in indecies:
|
||||
filtered_episode_watched_list_2_keys_dict[key][index] = None
|
||||
|
||||
return filtered_episode_watched_list_2_keys_dict
|
||||
|
||||
|
||||
def get_episode_index_in_dict(episode, episode_watched_list_2_keys_dict):
|
||||
# Iterate through the keys and values of the episode dictionary
|
||||
for episode_key, episode_value in episode.items():
|
||||
|
||||
Reference in New Issue
Block a user