[48] fix mass_* operations

pull/1052/head
meisnate12 2 years ago
parent 649fe4bbb5
commit 9130682cdb

@ -1 +1 @@
1.17.3-develop47 1.17.3-develop48

@ -812,66 +812,71 @@ class ConfigFile:
params["metadata_path"] = [("File", os.path.join(default_dir, f"{library_name}.yml"), lib_vars, None)] params["metadata_path"] = [("File", os.path.join(default_dir, f"{library_name}.yml"), lib_vars, None)]
else: else:
params["metadata_path"] = [] params["metadata_path"] = []
params["default_dir"] = default_dir except Failed as e:
logger.error(e)
params["skip_library"] = False params["default_dir"] = default_dir
if lib and "schedule" in lib and not self.requested_libraries and not self.ignore_schedules:
if not lib["schedule"]:
raise Failed(f"Config Error: schedule attribute is blank")
else:
logger.debug(f"Value: {lib['schedule']}")
try:
util.schedule_check("schedule", lib["schedule"], current_time, self.run_hour)
except NotScheduled:
params["skip_library"] = True
params["overlay_path"] = [] params["skip_library"] = False
params["remove_overlays"] = False if lib and "schedule" in lib and not self.requested_libraries and not self.ignore_schedules:
params["reapply_overlays"] = False if not lib["schedule"]:
params["reset_overlays"] = None logger.error(f"Config Error: schedule attribute is blank")
if lib and "overlay_path" in lib: else:
logger.debug(f"Value: {lib['schedule']}")
try: try:
if not lib["overlay_path"]: util.schedule_check("schedule", lib["schedule"], current_time, self.run_hour)
raise Failed("Config Error: overlay_path attribute is blank") except NotScheduled:
files = util.load_files(lib["overlay_path"], "overlay_path", lib_vars=lib_vars) params["skip_library"] = True
if not files:
logger.error("Config Error: No Paths Found for overlay_path") params["overlay_path"] = []
for file in util.get_list(lib["overlay_path"], split=False): params["remove_overlays"] = False
if isinstance(file, dict): params["reapply_overlays"] = False
if ("remove_overlays" in file and file["remove_overlays"] is True) \ params["reset_overlays"] = None
or ("remove_overlay" in file and file["remove_overlay"] is True) \ if lib and "overlay_path" in lib:
or ("revert_overlays" in file and file["revert_overlays"] is True): try:
params["remove_overlays"] = True if not lib["overlay_path"]:
if ("reapply_overlays" in file and file["reapply_overlays"] is True) \ raise Failed("Config Error: overlay_path attribute is blank")
or ("reapply_overlay" in file and file["reapply_overlay"] is True): files = util.load_files(lib["overlay_path"], "overlay_path", lib_vars=lib_vars)
params["reapply_overlays"] = True if not files:
if "reset_overlays" in file or "reset_overlay" in file: raise Failed("Config Error: No Paths Found for overlay_path")
attr = f"reset_overlay{'s' if 'reset_overlays' in file else ''}" for file in util.get_list(lib["overlay_path"], split=False):
if file[attr] and file[attr] in reset_overlay_options: if isinstance(file, dict):
params["reset_overlays"] = file[attr] if ("remove_overlays" in file and file["remove_overlays"] is True) \
else: or ("remove_overlay" in file and file["remove_overlay"] is True) \
final_text = f"Config Error: reset_overlays attribute {file[attr]} invalid. Options: " or ("revert_overlays" in file and file["revert_overlays"] is True):
for option, description in reset_overlay_options.items(): params["remove_overlays"] = True
final_text = f"{final_text}\n {option} ({description})" if ("reapply_overlays" in file and file["reapply_overlays"] is True) \
logger.error(final_text) or ("reapply_overlay" in file and file["reapply_overlay"] is True):
if "schedule" in file and file["schedule"]: params["reapply_overlays"] = True
logger.debug(f"Value: {file['schedule']}") if "reset_overlays" in file or "reset_overlay" in file:
err = None attr = f"reset_overlay{'s' if 'reset_overlays' in file else ''}"
try: if file[attr] and file[attr] in reset_overlay_options:
util.schedule_check("schedule", file["schedule"], current_time, self.run_hour) params["reset_overlays"] = file[attr]
except NotScheduledRange as e: else:
final_text = f"Config Error: reset_overlays attribute {file[attr]} invalid. Options: "
for option, description in reset_overlay_options.items():
final_text = f"{final_text}\n {option} ({description})"
logger.error(final_text)
if "schedule" in file and file["schedule"]:
logger.debug(f"Value: {file['schedule']}")
err = None
try:
util.schedule_check("schedule", file["schedule"], current_time, self.run_hour)
except NotScheduledRange as e:
err = e
except NotScheduled as e:
if not self.ignore_schedules:
err = e err = e
except NotScheduled as e: if err:
if not self.ignore_schedules: raise NotScheduled(f"{err}\n\nOverlays not scheduled to run")
err = e params["overlay_path"] = files
if err: except NotScheduled as e:
raise NotScheduled(f"{err}\n\nOverlays not scheduled to run") logger.info(e)
params["overlay_path"] = files params["overlay_path"] = []
except NotScheduled as e: params["remove_overlays"] = False
logger.info(e) except Failed as e:
params["overlay_path"] = [] logger.error(e)
params["remove_overlays"] = False
try:
logger.info("") logger.info("")
logger.separator("Plex Configuration", space=False, border=False) logger.separator("Plex Configuration", space=False, border=False)
params["plex"] = { params["plex"] = {

@ -111,8 +111,8 @@ class Library(ABC):
self.items_library_operation = True if self.assets_for_all or self.mass_genre_update or self.remove_title_parentheses \ self.items_library_operation = True if self.assets_for_all or self.mass_genre_update or self.remove_title_parentheses \
or self.mass_audience_rating_update or self.mass_critic_rating_update or self.mass_user_rating_update \ or self.mass_audience_rating_update or self.mass_critic_rating_update or self.mass_user_rating_update \
or self.mass_episode_audience_rating_update or self.mass_episode_critic_rating_update or self.mass_episode_user_rating_update \ or self.mass_episode_audience_rating_update or self.mass_episode_critic_rating_update or self.mass_episode_user_rating_update \
or self.mass_content_rating_update or self.mass_originally_available_update or self.mass_imdb_parental_labels \ or self.mass_content_rating_update or self.mass_originally_available_update or self.mass_original_title_update\
or self.genre_mapper or self.content_rating_mapper \ or self.mass_imdb_parental_labels or self.genre_mapper or self.content_rating_mapper \
or self.radarr_add_all_existing or self.sonarr_add_all_existing else False 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 \

@ -8,7 +8,7 @@ logger = util.logger
meta_operations = [ meta_operations = [
"mass_audience_rating_update", "mass_user_rating_update", "mass_critic_rating_update", "mass_audience_rating_update", "mass_user_rating_update", "mass_critic_rating_update",
"mass_episode_audience_rating_update", "mass_episode_user_rating_update", "mass_episode_critic_rating_update", "mass_episode_audience_rating_update", "mass_episode_user_rating_update", "mass_episode_critic_rating_update",
"mass_genre_update", "mass_content_rating_update", "mass_originally_available_update" "mass_genre_update", "mass_content_rating_update", "mass_originally_available_update", "mass_original_title_update"
] ]
class Operations: class Operations:
@ -33,6 +33,7 @@ class Operations:
logger.debug(f"Mass Episode Critic Rating Update: {self.library.mass_episode_critic_rating_update}") logger.debug(f"Mass Episode Critic Rating Update: {self.library.mass_episode_critic_rating_update}")
logger.debug(f"Mass Episode User Rating Update: {self.library.mass_episode_user_rating_update}") logger.debug(f"Mass Episode User Rating Update: {self.library.mass_episode_user_rating_update}")
logger.debug(f"Mass Content Rating Update: {self.library.mass_content_rating_update}") logger.debug(f"Mass Content Rating Update: {self.library.mass_content_rating_update}")
logger.debug(f"Mass Original Title Update: {self.library.mass_original_title_update}")
logger.debug(f"Mass Originally Available Update: {self.library.mass_originally_available_update}") logger.debug(f"Mass Originally Available Update: {self.library.mass_originally_available_update}")
logger.debug(f"Mass IMDb Parental Labels: {self.library.mass_imdb_parental_labels}") logger.debug(f"Mass IMDb Parental Labels: {self.library.mass_imdb_parental_labels}")
logger.debug(f"Mass Collection Mode Update: {self.library.mass_collection_mode}") logger.debug(f"Mass Collection Mode Update: {self.library.mass_collection_mode}")
@ -226,8 +227,10 @@ class Operations:
return f"\n{display} | None" return f"\n{display} | None"
elif attribute in ["unlock", "reset"] and item_attr in locked_fields: elif attribute in ["unlock", "reset"] and item_attr in locked_fields:
self.library.edit_query(item, {f"{item_attr}.locked": 0}) self.library.edit_query(item, {f"{item_attr}.locked": 0})
return f"\n{display} | Unlocked"
elif attribute in ["lock", "remove"] and item_attr not in locked_fields: elif attribute in ["lock", "remove"] and item_attr not in locked_fields:
self.library.edit_query(item, {f"{item_attr}.locked": 1}) self.library.edit_query(item, {f"{item_attr}.locked": 1})
return f"\n{display} | Locked"
elif attribute not in ["lock", "unlock", "remove", "reset"]: elif attribute not in ["lock", "unlock", "remove", "reset"]:
if tmdb_item and attribute == "tmdb": if tmdb_item and attribute == "tmdb":
found_rating = tmdb_item.vote_average found_rating = tmdb_item.vote_average
@ -306,17 +309,18 @@ class Operations:
raise Failed raise Failed
if not new_genres: if not new_genres:
logger.info(f"No Genres Found") logger.info(f"No Genres Found")
if self.library.genre_mapper: if self.library.genre_mapper or self.library.mass_genre_update in ["lock", "unlock"]:
if not new_genres and self.library.mass_genre_update not in ["remove", "reset"]: if not new_genres and self.library.mass_genre_update not in ["remove", "reset"]:
new_genres = [g.tag for g in item.genres] new_genres = [g.tag for g in item.genres]
mapped_genres = [] if self.library.genre_mapper:
for genre in new_genres: mapped_genres = []
if genre in self.library.genre_mapper: for genre in new_genres:
if self.library.genre_mapper[genre]: if genre in self.library.genre_mapper:
mapped_genres.append(self.library.genre_mapper[genre]) if self.library.genre_mapper[genre]:
else: mapped_genres.append(self.library.genre_mapper[genre])
mapped_genres.append(genre) else:
new_genres = mapped_genres mapped_genres.append(genre)
new_genres = mapped_genres
temp_display = self.library.edit_tags("genre", item, sync_tags=new_genres, do_print=False, temp_display = self.library.edit_tags("genre", item, sync_tags=new_genres, do_print=False,
locked=False if self.library.mass_genre_update in ["unlock", "reset"] else True, locked=False if self.library.mass_genre_update in ["unlock", "reset"] else True,
is_locked="genre" in locked_fields) is_locked="genre" in locked_fields)
@ -328,7 +332,7 @@ class Operations:
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:
try: try:
new_rating = None new_rating = None
if self.library.mass_content_rating_update and self.library.mass_genre_update not in ["lock", "unlock", "remove", "reset"]: if self.library.mass_content_rating_update and self.library.mass_content_rating_update not in ["lock", "unlock", "remove", "reset"]:
if omdb_item and self.library.mass_content_rating_update == "omdb": if omdb_item and self.library.mass_content_rating_update == "omdb":
new_rating = omdb_item.content_rating new_rating = omdb_item.content_rating
elif mdb_item and self.library.mass_content_rating_update == "mdb": elif mdb_item and self.library.mass_content_rating_update == "mdb":
@ -340,23 +344,24 @@ class Operations:
else: else:
raise Failed raise Failed
if self.library.content_rating_mapper: if self.library.content_rating_mapper:
if new_rating is None and self.library.mass_genre_update not in ["remove", "reset"]: if new_rating is None and self.library.mass_content_rating_update not in ["remove", "reset"]:
new_rating = item.contentRating new_rating = item.contentRating
if new_rating in self.library.content_rating_mapper: if new_rating in self.library.content_rating_mapper:
new_rating = self.library.content_rating_mapper[new_rating] new_rating = self.library.content_rating_mapper[new_rating]
if self.library.mass_content_rating_update in ["remove", "reset"] and item.contentRating: if self.library.mass_content_rating_update in ["remove", "reset"] and item.contentRating:
item.editField("contentRating", None, locked=self.library.mass_content_rating_update == "remove") item.editField("contentRating", None, locked=self.library.mass_content_rating_update == "remove")
batch_display += f"\nContent Rating | None" batch_display += f"\nContent Rating | None"
elif not new_rating and self.library.mass_genre_update not in ["lock", "unlock", "remove", "reset"]: elif not new_rating and self.library.mass_content_rating_update not in ["lock", "unlock", "remove", "reset"]:
logger.info(f"No Content Rating Found") logger.info(f"No Content Rating Found")
elif str(item.contentRating) != str(new_rating): elif str(item.contentRating) != str(new_rating):
item.editContentRating(new_rating) item.editContentRating(new_rating)
batch_display += f"\nContent Rating | {new_rating}" batch_display += f"\nContent Rating | {new_rating}"
elif self.library.mass_content_rating_update in ["unlock", "reset"] and "contentRating" in locked_fields: elif self.library.mass_content_rating_update in ["unlock", "reset"] and "contentRating" in locked_fields:
self.library.edit_query(item, {"contentRating.locked": 0}) self.library.edit_query(item, {"contentRating.locked": 0})
batch_display += f"\nContent Rating | Unlocked"
elif self.library.mass_content_rating_update in ["lock", "remove"] and "contentRating" not in locked_fields: elif self.library.mass_content_rating_update in ["lock", "remove"] and "contentRating" not in locked_fields:
self.library.edit_query(item, {"contentRating.locked": 1}) self.library.edit_query(item, {"contentRating.locked": 1})
batch_display += f"\nContent Rating | Locked"
except Failed: except Failed:
pass pass
@ -366,8 +371,10 @@ class Operations:
batch_display += f"\nOriginal Title | None" batch_display += f"\nOriginal Title | None"
elif self.library.mass_original_title_update in ["unlock", "reset"] and "originalTitle" in locked_fields: elif self.library.mass_original_title_update in ["unlock", "reset"] and "originalTitle" in locked_fields:
self.library.edit_query(item, {"originalTitle.locked": 0}) self.library.edit_query(item, {"originalTitle.locked": 0})
batch_display += f"\nOriginal Title | Unlocked"
elif self.library.mass_original_title_update in ["lock", "remove"] and "originalTitle" not in locked_fields: elif self.library.mass_original_title_update in ["lock", "remove"] and "originalTitle" not in locked_fields:
self.library.edit_query(item, {"originalTitle.locked": 1}) self.library.edit_query(item, {"originalTitle.locked": 1})
batch_display += f"\nOriginal Title | Locked"
elif self.library.mass_original_title_update not in ["lock", "unlock", "remove", "reset"]: elif self.library.mass_original_title_update not in ["lock", "unlock", "remove", "reset"]:
try: try:
if anidb_item and self.library.mass_original_title_update == "anidb": if anidb_item and self.library.mass_original_title_update == "anidb":
@ -396,8 +403,10 @@ class Operations:
batch_display += f"\nOriginally Available Date | None" batch_display += f"\nOriginally Available Date | None"
elif self.library.mass_originally_available_update in ["unlock", "reset"] and "originallyAvailableAt" in locked_fields: elif self.library.mass_originally_available_update in ["unlock", "reset"] and "originallyAvailableAt" in locked_fields:
self.library.edit_query(item, {"originallyAvailableAt.locked": 0}) self.library.edit_query(item, {"originallyAvailableAt.locked": 0})
batch_display += f"\nOriginally Available Date | Unlocked"
elif self.library.mass_originally_available_update in ["lock", "remove"] and "originallyAvailableAt" not in locked_fields: elif self.library.mass_originally_available_update in ["lock", "remove"] and "originallyAvailableAt" not in locked_fields:
self.library.edit_query(item, {"originallyAvailableAt.locked": 1}) self.library.edit_query(item, {"originallyAvailableAt.locked": 1})
batch_display += f"\nOriginally Available Date | Locked"
elif self.library.mass_originally_available_update not in ["lock", "unlock", "remove", "reset"]: elif self.library.mass_originally_available_update not in ["lock", "unlock", "remove", "reset"]:
try: try:
if omdb_item and self.library.mass_originally_available_update == "omdb": if omdb_item and self.library.mass_originally_available_update == "omdb":
@ -448,8 +457,10 @@ class Operations:
return f"\n{display} | None" return f"\n{display} | None"
elif attribute in ["unlock", "reset"] and item_attr in episode_locked_fields: elif attribute in ["unlock", "reset"] and item_attr in episode_locked_fields:
self.library.edit_query(ep, {f"{item_attr}.locked": 0}) self.library.edit_query(ep, {f"{item_attr}.locked": 0})
return f"\n{display} | Unlocked"
elif attribute in ["lock", "remove"] and item_attr not in episode_locked_fields: elif attribute in ["lock", "remove"] and item_attr not in episode_locked_fields:
self.library.edit_query(ep, {f"{item_attr}.locked": 1}) self.library.edit_query(ep, {f"{item_attr}.locked": 1})
return f"\n{display} | Locked"
elif attribute not in ["lock", "unlock", "remove", "reset"]: elif attribute not in ["lock", "unlock", "remove", "reset"]:
found_rating = None found_rating = None
if tmdb_item and attribute == "tmdb": if tmdb_item and attribute == "tmdb":

@ -1006,6 +1006,7 @@ class Plex(Library):
display += f"-{', -'.join(_remove)}" display += f"-{', -'.join(_remove)}"
if is_locked is not None and not display and is_locked != locked: if is_locked is not None and not display and is_locked != locked:
self.edit_query(obj, {f"{actual}.locked": 1 if locked else 0}) self.edit_query(obj, {f"{actual}.locked": 1 if locked else 0})
display = "Locked" if locked else "Unlocked"
final = f"{obj.title[:25]:<25} | {attr_display} | {display}" if display else display final = f"{obj.title[:25]:<25} | {attr_display} | {display}" if display else display
if do_print and final: if do_print and final:
logger.info(final) logger.info(final)

Loading…
Cancel
Save