[7] Resolve content_rating_mapper issues

This commit is contained in:
YozoraXCII 2022-03-13 20:44:42 +00:00 committed by meisnate12
parent c281ad9ed8
commit 18e7c84469
4 changed files with 33 additions and 11 deletions

View file

@ -1 +1 @@
1.16.1-develop6
1.16.1-develop7

View file

@ -593,6 +593,7 @@ class ConfigFile:
"name": str(lib["library_name"]) if lib and "library_name" in lib and lib["library_name"] else str(library_name),
"tmdb_collections": None,
"genre_mapper": None,
"content_rating_mapper": None,
"radarr_remove_by_tag": None,
"sonarr_remove_by_tag": None,
"mass_collection_mode": None,
@ -735,6 +736,20 @@ class ConfigFile:
params["genre_mapper"][old_genre] = new_genre
else:
logger.error("Config Error: genre_mapper is blank")
if "content_rating_mapper" in lib["operations"]:
if lib["operations"]["content_rating_mapper"] and isinstance(lib["operations"]["content_rating_mapper"], dict):
params["content_rating_mapper"] = {}
for new_rating, old_ratings in lib["operations"]["content_rating_mapper"].items():
if old_ratings is None:
params["content_rating_mapper"][new_rating] = old_ratings
else:
for old_rating in util.get_list(old_ratings):
if old_rating == new_rating:
logger.error("Config Error: Content Ratings cannot be mapped to themselves")
else:
params["content_rating_mapper"][old_rating] = new_rating
else:
logger.error("Config Error: content_rating_mapper is blank")
if "genre_collections" in lib["operations"]:
params["genre_collections"] = {
"exclude_genres": [],

View file

@ -83,6 +83,7 @@ class Library(ABC):
self.tmdb_collections = params["tmdb_collections"]
self.genre_collections = params["genre_collections"]
self.genre_mapper = params["genre_mapper"]
self.content_rating_mapper = params["content_rating_mapper"]
self.error_webhooks = params["error_webhooks"]
self.changes_webhooks = params["changes_webhooks"]
self.split_duplicates = params["split_duplicates"] # TODO: Here or just in Plex?
@ -94,7 +95,7 @@ class Library(ABC):
self.items_library_operation = True if self.assets_for_all or self.mass_genre_update or self.mass_audience_rating_update \
or self.mass_critic_rating_update or self.mass_content_rating_update or self.mass_trakt_rating_update \
or self.genre_mapper or self.tmdb_collections or self.radarr_add_all_existing or self.sonarr_add_all_existing else False
or self.genre_mapper or self.content_rating_mapper or self.tmdb_collections or self.radarr_add_all_existing or self.sonarr_add_all_existing else False
self.library_operation = True if self.items_library_operation or self.delete_unmanaged_collections or self.delete_collections_with_less \
or self.radarr_remove_by_tag or self.sonarr_remove_by_tag or self.mass_collection_mode \
or self.genre_collections or self.show_unmanaged or self.metadata_backup or self.update_blank_track_titles else False

View file

@ -418,6 +418,7 @@ def library_operations(config, library):
logger.debug(f"TMDb Collections: {library.tmdb_collections}")
logger.debug(f"Genre Collections: {library.genre_collections}")
logger.debug(f"Genre Mapper: {library.genre_mapper}")
logger.debug(f"Content Rating Mapper: {library.content_rating_mapper}")
logger.debug(f"Metadata Backup: {library.metadata_backup}")
logger.debug(f"Item Operation: {library.items_library_operation}")
logger.debug("")
@ -613,17 +614,22 @@ def library_operations(config, library):
except Failed:
pass
if library.genre_mapper:
if library.genre_mapper or library.content_rating_mapper:
try:
adds = []
deletes = []
library.reload(item)
for genre in item.genres:
if genre.tag in library.genre_mapper:
deletes.append(genre.tag)
if library.genre_mapper[genre.tag]:
adds.append(library.genre_mapper[genre.tag])
library.edit_tags("genre", item, add_tags=adds, remove_tags=deletes)
if library.genre_mapper:
adds = []
deletes = []
for genre in item.genres:
if genre.tag in library.genre_mapper:
deletes.append(genre.tag)
if library.genre_mapper[genre.tag]:
adds.append(library.genre_mapper[genre.tag])
library.edit_tags("genre", item, add_tags=adds, remove_tags=deletes)
if library.content_rating_mapper:
if item.contentRating in library.content_rating_mapper:
library.edit_query(item, {"contentRating.value": library.content_rating_mapper[item.contentRating], "contentRating.locked": 1})
logger.info(f"{item.title[:25]:<25} | Content Rating | {library.content_rating_mapper[item.contentRating]}")
except Failed:
pass