[7] Resolve content_rating_mapper issues

pull/779/head
YozoraXCII 3 years ago committed by meisnate12
parent c281ad9ed8
commit 18e7c84469

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

@ -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), "name": str(lib["library_name"]) if lib and "library_name" in lib and lib["library_name"] else str(library_name),
"tmdb_collections": None, "tmdb_collections": None,
"genre_mapper": None, "genre_mapper": None,
"content_rating_mapper": None,
"radarr_remove_by_tag": None, "radarr_remove_by_tag": None,
"sonarr_remove_by_tag": None, "sonarr_remove_by_tag": None,
"mass_collection_mode": None, "mass_collection_mode": None,
@ -735,6 +736,20 @@ class ConfigFile:
params["genre_mapper"][old_genre] = new_genre params["genre_mapper"][old_genre] = new_genre
else: else:
logger.error("Config Error: genre_mapper is blank") 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"]: if "genre_collections" in lib["operations"]:
params["genre_collections"] = { params["genre_collections"] = {
"exclude_genres": [], "exclude_genres": [],

@ -83,6 +83,7 @@ class Library(ABC):
self.tmdb_collections = params["tmdb_collections"] self.tmdb_collections = params["tmdb_collections"]
self.genre_collections = params["genre_collections"] self.genre_collections = params["genre_collections"]
self.genre_mapper = params["genre_mapper"] self.genre_mapper = params["genre_mapper"]
self.content_rating_mapper = params["content_rating_mapper"]
self.error_webhooks = params["error_webhooks"] self.error_webhooks = params["error_webhooks"]
self.changes_webhooks = params["changes_webhooks"] self.changes_webhooks = params["changes_webhooks"]
self.split_duplicates = params["split_duplicates"] # TODO: Here or just in Plex? 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 \ 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.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 \ 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.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 or self.genre_collections or self.show_unmanaged or self.metadata_backup or self.update_blank_track_titles else False

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

Loading…
Cancel
Save