[22] fix genre_mapper and content_rating_mapper

pull/782/head
meisnate12 3 years ago
parent 48ca18d4ce
commit edb752a403

@ -1 +1 @@
1.16.1-develop21 1.16.1-develop22

@ -584,8 +584,10 @@ def library_operations(config, library):
else: else:
raise Failed raise Failed
if library.mass_genre_update: if library.mass_genre_update or library.genre_mapper:
try: try:
new_genres = []
if library.mass_genre_update:
if tmdb_item and library.mass_genre_update == "tmdb": if tmdb_item and library.mass_genre_update == "tmdb":
new_genres = tmdb_item.genres new_genres = tmdb_item.genres
elif omdb_item and library.mass_genre_update == "omdb": elif omdb_item and library.mass_genre_update == "omdb":
@ -596,6 +598,19 @@ def library_operations(config, library):
new_genres = anidb_item.genres new_genres = anidb_item.genres
else: else:
raise Failed raise Failed
if not new_genres:
logger.info(f"{item.title[:25]:<25} | No Genres Found")
if library.genre_mapper:
if not new_genres:
new_genres = [g.tag for g in item.genres]
mapped_genres = []
for genre in new_genres:
if genre in library.genre_mapper:
if library.genre_mapper[genre]:
mapped_genres.append(library.genre_mapper[genre])
else:
mapped_genres.append(genre)
new_genres = mapped_genres
library.edit_tags("genre", item, sync_tags=new_genres) library.edit_tags("genre", item, sync_tags=new_genres)
except Failed: except Failed:
pass pass
@ -619,8 +634,10 @@ def library_operations(config, library):
logger.info(f"{item.title[:25]:<25} | Critic Rating | {new_rating}") logger.info(f"{item.title[:25]:<25} | Critic Rating | {new_rating}")
except Failed: except Failed:
pass pass
if library.mass_content_rating_update: if library.mass_content_rating_update or library.content_rating_mapper:
try: try:
new_rating = None
if library.mass_content_rating_update:
if omdb_item and library.mass_content_rating_update == "omdb": if omdb_item and library.mass_content_rating_update == "omdb":
new_rating = omdb_item.content_rating new_rating = omdb_item.content_rating
elif mdb_item and library.mass_content_rating_update == "mdb": elif mdb_item and library.mass_content_rating_update == "mdb":
@ -631,7 +648,12 @@ def library_operations(config, library):
raise Failed raise Failed
if new_rating is None: if new_rating is None:
logger.info(f"{item.title[:25]:<25} | No Content Rating Found") logger.info(f"{item.title[:25]:<25} | No Content Rating Found")
elif str(item.rating) != str(new_rating): if library.content_rating_mapper:
if new_rating is None:
new_rating = item.contentRating
if new_rating in library.content_rating_mapper:
new_rating = library.content_rating_mapper[new_rating]
if str(item.contentRating) != str(new_rating):
library.edit_query(item, {"contentRating.value": new_rating, "contentRating.locked": 1}) library.edit_query(item, {"contentRating.value": new_rating, "contentRating.locked": 1})
logger.info(f"{item.title[:25]:<25} | Content Rating | {new_rating}") logger.info(f"{item.title[:25]:<25} | Content Rating | {new_rating}")
except Failed: except Failed:
@ -658,25 +680,6 @@ def library_operations(config, library):
except Failed: except Failed:
pass pass
if library.genre_mapper or library.content_rating_mapper:
try:
library.reload(item)
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
if library.Radarr and library.radarr_add_all_existing: if library.Radarr and library.radarr_add_all_existing:
try: try:
library.Radarr.add_tmdb(radarr_adds) library.Radarr.add_tmdb(radarr_adds)

Loading…
Cancel
Save