[37] fixed #1903 episode and mapper operations

pull/1912/head
meisnate12 9 months ago
parent 029fa3cd93
commit 39c7975fe1

@ -35,6 +35,8 @@ Fixed `trakt_userlist`
Fixed an issue where sometimes the resolution default overlay would be off center Fixed an issue where sometimes the resolution default overlay would be off center
Fixed multiple issues with playlist deletion. Thanks @benbou8231! Fixed multiple issues with playlist deletion. Thanks @benbou8231!
Fixed an issue where dynamic collection errors would sometimes appear before the title of the Dynamic Collection. Fixed an issue where dynamic collection errors would sometimes appear before the title of the Dynamic Collection.
Fix IMDb Null issue Fixed IMDb Null issue
Fixed mapper operations not working without a mass update operation
Fixed episode rating mass update operations
Various other Minor Fixes Various other Minor Fixes

@ -1 +1 @@
1.20.0-develop36 1.20.0-develop37

@ -412,9 +412,9 @@ class Operations:
continue continue
if self.library.mass_genre_update or self.library.genre_mapper: if self.library.mass_genre_update or self.library.genre_mapper:
new_genres = []
extra_option = None
if self.library.mass_genre_update: if self.library.mass_genre_update:
new_genres = []
extra_option = None
for option in self.library.mass_genre_update: for option in self.library.mass_genre_update:
if option in ["lock", "unlock", "remove", "reset"]: if option in ["lock", "unlock", "remove", "reset"]:
extra_option = option extra_option = option
@ -441,42 +441,42 @@ class Operations:
except Failed: except Failed:
continue continue
item_genres = [g.tag for g in item.genres] item_genres = [g.tag for g in item.genres]
if not new_genres and extra_option not in ["remove", "reset"]: if not new_genres and extra_option not in ["remove", "reset"]:
new_genres = item_genres new_genres = item_genres
if self.library.genre_mapper: if self.library.genre_mapper:
mapped_genres = [] mapped_genres = []
for genre in new_genres: for genre in new_genres:
if genre in self.library.genre_mapper: if genre in self.library.genre_mapper:
if self.library.genre_mapper[genre]: if self.library.genre_mapper[genre]:
mapped_genres.append(self.library.genre_mapper[genre]) mapped_genres.append(self.library.genre_mapper[genre])
else: else:
mapped_genres.append(genre) mapped_genres.append(genre)
new_genres = mapped_genres new_genres = mapped_genres
_add = list(set(new_genres) - set(item_genres)) _add = list(set(new_genres) - set(item_genres))
_remove = list(set(item_genres) - set(new_genres)) _remove = list(set(item_genres) - set(new_genres))
for genre_list, edit_type in [(_add, "add"), (_remove, "remove")]: for genre_list, edit_type in [(_add, "add"), (_remove, "remove")]:
if genre_list: if genre_list:
for g in genre_list: for g in genre_list:
if g not in genre_edits[edit_type]: if g not in genre_edits[edit_type]:
genre_edits[edit_type][g] = [] genre_edits[edit_type][g] = []
genre_edits[edit_type][g].append(item.ratingKey) genre_edits[edit_type][g].append(item.ratingKey)
item_edits += f"\n{edit_type.capitalize()} Genres (Batched) | {', '.join(genre_list)}" item_edits += f"\n{edit_type.capitalize()} Genres (Batched) | {', '.join(genre_list)}"
if extra_option in ["unlock", "reset"] and ("genre" in locked_fields or _add or _remove): if extra_option in ["unlock", "reset"] and ("genre" in locked_fields or _add or _remove):
if "genre" not in unlock_edits: if "genre" not in unlock_edits:
unlock_edits["genre"] = [] unlock_edits["genre"] = []
unlock_edits["genre"].append(item.ratingKey) unlock_edits["genre"].append(item.ratingKey)
item_edits += "\nUnlock Genre (Batched)" item_edits += "\nUnlock Genre (Batched)"
elif extra_option in ["lock", "remove"] and "genre" not in locked_fields and not _add and not _remove: elif extra_option in ["lock", "remove"] and "genre" not in locked_fields and not _add and not _remove:
if "genre" not in lock_edits: if "genre" not in lock_edits:
lock_edits["genre"] = [] lock_edits["genre"] = []
lock_edits["genre"].append(item.ratingKey) lock_edits["genre"].append(item.ratingKey)
item_edits += "\nLock Genre (Batched)" item_edits += "\nLock Genre (Batched)"
if self.library.mass_content_rating_update or self.library.content_rating_mapper: if self.library.mass_content_rating_update or self.library.content_rating_mapper:
new_rating = None
extra_option = None
if self.library.mass_content_rating_update: if self.library.mass_content_rating_update:
new_rating = None
extra_option = None
for option in self.library.mass_content_rating_update: for option in self.library.mass_content_rating_update:
if option in ["lock", "unlock", "remove", "reset"]: if option in ["lock", "unlock", "remove", "reset"]:
extra_option = option extra_option = option
@ -516,50 +516,50 @@ class Operations:
except Failed: except Failed:
continue continue
is_none = False is_none = False
do_lock = False
do_unlock = False
current_rating = item.contentRating
if not new_rating:
new_rating = current_rating
if self.library.content_rating_mapper:
if new_rating in self.library.content_rating_mapper:
new_rating = self.library.content_rating_mapper[new_rating]
if not new_rating:
is_none = True
if extra_option == "reset":
if current_rating:
if "contentRating" not in reset_edits:
reset_edits["contentRating"] = []
reset_edits["contentRating"].append(item.ratingKey)
item_edits += "\nReset Content Rating (Batched)"
elif "contentRating" in locked_fields:
do_unlock = True
elif extra_option == "remove" or is_none:
if current_rating:
if "contentRating" not in remove_edits:
remove_edits["contentRating"] = []
remove_edits["contentRating"].append(item.ratingKey)
item_edits += "\nRemove Content Rating (Batched)"
elif "contentRating" not in locked_fields:
do_lock = True
elif new_rating and new_rating != current_rating:
if new_rating not in content_edits:
content_edits[new_rating] = []
content_edits[new_rating].append(item.ratingKey)
item_edits += f"\nUpdate Content Rating (Batched) | {new_rating}"
do_lock = False do_lock = False
do_unlock = False
current_rating = item.contentRating if extra_option == "lock" or do_lock:
if not new_rating: if "contentRating" not in lock_edits:
new_rating = current_rating lock_edits["contentRating"] = []
if self.library.content_rating_mapper: lock_edits["contentRating"].append(item.ratingKey)
if new_rating in self.library.content_rating_mapper: item_edits += "\nLock Content Rating (Batched)"
new_rating = self.library.content_rating_mapper[new_rating] elif extra_option == "unlock" or do_unlock:
if not new_rating: if "contentRating" not in unlock_edits:
is_none = True unlock_edits["contentRating"] = []
if extra_option == "reset": unlock_edits["contentRating"].append(item.ratingKey)
if current_rating: item_edits += "\nUnlock Content Rating (Batched)"
if "contentRating" not in reset_edits:
reset_edits["contentRating"] = []
reset_edits["contentRating"].append(item.ratingKey)
item_edits += "\nReset Content Rating (Batched)"
elif "contentRating" in locked_fields:
do_unlock = True
elif extra_option == "remove" or is_none:
if current_rating:
if "contentRating" not in remove_edits:
remove_edits["contentRating"] = []
remove_edits["contentRating"].append(item.ratingKey)
item_edits += "\nRemove Content Rating (Batched)"
elif "contentRating" not in locked_fields:
do_lock = True
elif new_rating and new_rating != current_rating:
if new_rating not in content_edits:
content_edits[new_rating] = []
content_edits[new_rating].append(item.ratingKey)
item_edits += f"\nUpdate Content Rating (Batched) | {new_rating}"
do_lock = False
if extra_option == "lock" or do_lock:
if "contentRating" not in lock_edits:
lock_edits["contentRating"] = []
lock_edits["contentRating"].append(item.ratingKey)
item_edits += "\nLock Content Rating (Batched)"
elif extra_option == "unlock" or do_unlock:
if "contentRating" not in unlock_edits:
unlock_edits["contentRating"] = []
unlock_edits["contentRating"].append(item.ratingKey)
item_edits += "\nUnlock Content Rating (Batched)"
if self.library.mass_original_title_update: if self.library.mass_original_title_update:
current_original = item.originalTitle current_original = item.originalTitle
@ -802,7 +802,7 @@ class Operations:
if any([x is not None for x, _ in episode_ops]): if any([x is not None for x, _ in episode_ops]):
if any([x == "imdb" for x, _ in episode_ops]) and not imdb_id: if any(["imdb" in x for x, _ in episode_ops]) and not imdb_id:
logger.info(f"No IMDb ID for Guid: {item.guid}") logger.info(f"No IMDb ID for Guid: {item.guid}")
for ep in item.episodes(): for ep in item.episodes():
@ -816,49 +816,59 @@ class Operations:
for attribute, item_attr in episode_ops: for attribute, item_attr in episode_ops:
if attribute: if attribute:
current = getattr(ep, item_attr) current = getattr(ep, item_attr)
if attribute == "remove" and current is not None: for option in attribute:
if item_attr not in ep_remove_edits: if option in ["lock", "remove"]:
ep_remove_edits[item_attr] = [] if option == "remove" and current:
ep_remove_edits[item_attr].append(ep) if item_attr not in ep_remove_edits:
item_edits += f"\nRemove {name_display[item_attr]} (Batched)" ep_remove_edits[item_attr] = []
elif attribute == "reset" and current is not None: ep_remove_edits[item_attr].append(ep.ratingKey)
if item_attr not in ep_reset_edits: item_edits += f"\nRemove {name_display[item_attr]} (Batched)"
ep_reset_edits[item_attr] = [] elif item_attr not in locked_fields:
ep_reset_edits[item_attr].append(ep) if item_attr not in ep_lock_edits:
item_edits += f"\nReset {name_display[item_attr]} (Batched)" ep_lock_edits[item_attr] = []
elif attribute in ["unlock", "reset"] and item_attr in episode_locked_fields: ep_lock_edits[item_attr].append(ep.ratingKey)
if item_attr not in ep_unlock_edits: item_edits += f"\nLock {name_display[item_attr]} (Batched)"
ep_unlock_edits[item_attr] = [] break
ep_unlock_edits[item_attr].append(ep) elif option in ["unlock", "reset"]:
item_edits += f"\nUnlock {name_display[item_attr]} (Batched)" if option == "reset" and current:
elif attribute in ["lock", "remove"] and item_attr not in episode_locked_fields: if item_attr not in ep_reset_edits:
if item_attr not in ep_lock_edits: ep_reset_edits[item_attr] = []
ep_lock_edits[item_attr] = [] ep_reset_edits[item_attr].append(ep.ratingKey)
ep_lock_edits[item_attr].append(ep) item_edits += f"\nReset {name_display[item_attr]} (Batched)"
item_edits += f"\nLock {name_display[item_attr]} (Batched)" elif item_attr in locked_fields:
elif attribute not in ["lock", "unlock", "remove", "reset"]: if item_attr not in ep_unlock_edits:
try: ep_unlock_edits[item_attr] = []
tmdb_item = tmdb_obj() ep_unlock_edits[item_attr].append(ep.ratingKey)
except Failed: item_edits += f"\nUnlock {name_display[item_attr]} (Batched)"
tmdb_item = None break
found_rating = None
if tmdb_item and attribute == "tmdb":
try:
found_rating = self.config.TMDb.get_episode(tmdb_item.tmdb_id, ep.seasonNumber, ep.episodeNumber).vote_average # noqa
except Failed as er:
logger.error(er)
elif imdb_id and attribute == "imdb":
found_rating = self.config.IMDb.get_episode_rating(imdb_id, ep.seasonNumber, ep.episodeNumber)
if found_rating and float(found_rating) > 0:
found_rating = f"{float(found_rating):.1f}"
if str(current) != found_rating:
if found_rating not in ep_rating_edits[item_attr]:
ep_rating_edits[item_attr][found_rating] = []
ep_rating_edits[item_attr][found_rating].append(ep)
item_edits += f"\nUpdate {name_display[item_attr]} (Batched) | {found_rating}"
else: else:
logger.info(f"No {name_display[item_attr]} Found") try:
try:
tmdb_item = tmdb_obj()
except Failed:
tmdb_item = None
found_rating = None
if tmdb_item and attribute == "tmdb":
try:
found_rating = self.config.TMDb.get_episode(tmdb_item.tmdb_id, ep.seasonNumber, ep.episodeNumber).vote_average # noqa
except Failed as er:
logger.error(er)
elif imdb_id and attribute == "imdb":
found_rating = self.config.IMDb.get_episode_rating(imdb_id, ep.seasonNumber, ep.episodeNumber)
else:
found_rating = option
if not found_rating:
logger.info(f"No {option} {name_display[item_attr]} Found")
raise Failed
found_rating = f"{float(found_rating):.1f}"
if str(current) != found_rating:
if found_rating not in ep_rating_edits[item_attr]:
ep_rating_edits[item_attr][found_rating] = []
ep_rating_edits[item_attr][found_rating].append(ep.ratingKey)
item_edits += f"\nUpdate {name_display[item_attr]} (Batched) | {found_rating}"
break
except Failed:
continue
if len(item_edits) > 0: if len(item_edits) > 0:
logger.info(f"Item Edits:{item_edits}") logger.info(f"Item Edits:{item_edits}")

Loading…
Cancel
Save