From 1913e3ecc024154e923e0a0edbbd28fe98ebaed9 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Mon, 24 Jan 2022 14:33:14 -0500 Subject: [PATCH] update metadata updates for less calls --- modules/builder.py | 6 +++--- modules/meta.py | 47 +++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/modules/builder.py b/modules/builder.py index 819105ce..01c282b6 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -565,13 +565,13 @@ class CollectionBuilder: else: logger.error(e) + if not self.server_preroll and not self.smart_url and len(self.builders) == 0: + raise Failed(f"{self.Type} Error: No builders were found") + if self.custom_sort is True and (len(self.builders) > 1 or self.builders[0][0] not in custom_sort_builders): raise Failed(f"{self.Type} Error: " + ('Playlists' if playlist else 'collection_order: custom') + (f" can only be used with a single builder per {self.type}" if len(self.builders) > 1 else f" cannot be used with {self.builders[0][0]}")) - if not self.server_preroll and not self.smart_url and len(self.builders) == 0: - raise Failed(f"{self.Type} Error: No builders were found") - if "add_missing" not in self.radarr_details: self.radarr_details["add_missing"] = self.library.Radarr.add_missing if self.library.Radarr else False if "add_existing" not in self.radarr_details: diff --git a/modules/meta.py b/modules/meta.py index a8370436..fb9d1065 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -479,16 +479,17 @@ class MetadataFile(DataFile): elif not isinstance(meta[methods["seasons"]], dict): logger.error("Metadata Error: seasons attribute must be a dictionary") else: + seasons = {} + for season in item.seasons(): + seasons[season.title] = season + seasons[int(season.index)] = season for season_id, season_dict in meta[methods["seasons"]].items(): updated = False logger.info("") logger.info(f"Updating season {season_id} of {mapping_name}...") - try: - if isinstance(season_id, int): - season = item.season(season=season_id) - else: - season = item.season(title=season_id) - except NotFound: + if season_id in seasons: + season = seasons[season_id] + else: logger.error(f"Metadata Error: Season: {season_id} not found") continue season_methods = {sm.lower(): sm for sm in season_dict} @@ -521,16 +522,17 @@ class MetadataFile(DataFile): elif not isinstance(season_dict[season_methods["episodes"]], dict): logger.error("Metadata Error: episodes attribute must be a dictionary") else: + episodes = {} + for episode in season.episodes(): + episodes[episode.title] = episode + episodes[int(episode.index)] = episode for episode_str, episode_dict in season_dict[season_methods["episodes"]].items(): updated = False logger.info("") logger.info(f"Updating episode {episode_str} in {season_id} of {mapping_name}...") - try: - if isinstance(episode_str, int): - episode = season.episode(episode=episode_str) - else: - episode = season.episode(title=episode_str) - except NotFound: + if episode_str in episodes: + episode = episodes[episode_str] + else: logger.error(f"Metadata Error: Episode {episode_str} in Season {season_id} not found") continue episode_methods = {em.lower(): em for em in episode_dict} @@ -619,24 +621,21 @@ class MetadataFile(DataFile): elif not isinstance(meta[methods["albums"]], dict): logger.error("Metadata Error: albums attribute must be a dictionary") else: + albums = {album.title: album for album in item.albums()} for album_name, album_dict in meta[methods["albums"]].items(): updated = False title = None album_methods = {am.lower(): am for am in album_dict} logger.info("") logger.info(f"Updating album {album_name} of {mapping_name}...") - try: - album = item.album(album_name) - except NotFound: - try: - if "alt_title" not in album_methods or not album_dict[album_methods["alt_title"]]: - raise NotFound - album = item.album(album_dict[album_methods["alt_title"]]) - title = album_name - except NotFound: - logger.error(f"Metadata Error: Album: {album_name} not found") - continue - + if album_name in albums: + album = albums[album_name] + elif "alt_title" in album_methods and album_dict[album_methods["alt_title"]] and album_dict[album_methods["alt_title"]] in albums: + album = albums[album_dict[album_methods["alt_title"]]] + title = album_name + else: + logger.error(f"Metadata Error: Album: {album_name} not found") + continue if not title: title = album.title edits = {}