update metadata updates for less calls

pull/652/head
meisnate12 3 years ago
parent 86fa3dbe7c
commit 1913e3ecc0

@ -565,13 +565,13 @@ class CollectionBuilder:
else: else:
logger.error(e) 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): 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') + 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]}")) (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: if "add_missing" not in self.radarr_details:
self.radarr_details["add_missing"] = self.library.Radarr.add_missing if self.library.Radarr else False self.radarr_details["add_missing"] = self.library.Radarr.add_missing if self.library.Radarr else False
if "add_existing" not in self.radarr_details: if "add_existing" not in self.radarr_details:

@ -479,16 +479,17 @@ class MetadataFile(DataFile):
elif not isinstance(meta[methods["seasons"]], dict): elif not isinstance(meta[methods["seasons"]], dict):
logger.error("Metadata Error: seasons attribute must be a dictionary") logger.error("Metadata Error: seasons attribute must be a dictionary")
else: 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(): for season_id, season_dict in meta[methods["seasons"]].items():
updated = False updated = False
logger.info("") logger.info("")
logger.info(f"Updating season {season_id} of {mapping_name}...") logger.info(f"Updating season {season_id} of {mapping_name}...")
try: if season_id in seasons:
if isinstance(season_id, int): season = seasons[season_id]
season = item.season(season=season_id) else:
else:
season = item.season(title=season_id)
except NotFound:
logger.error(f"Metadata Error: Season: {season_id} not found") logger.error(f"Metadata Error: Season: {season_id} not found")
continue continue
season_methods = {sm.lower(): sm for sm in season_dict} 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): elif not isinstance(season_dict[season_methods["episodes"]], dict):
logger.error("Metadata Error: episodes attribute must be a dictionary") logger.error("Metadata Error: episodes attribute must be a dictionary")
else: 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(): for episode_str, episode_dict in season_dict[season_methods["episodes"]].items():
updated = False updated = False
logger.info("") logger.info("")
logger.info(f"Updating episode {episode_str} in {season_id} of {mapping_name}...") logger.info(f"Updating episode {episode_str} in {season_id} of {mapping_name}...")
try: if episode_str in episodes:
if isinstance(episode_str, int): episode = episodes[episode_str]
episode = season.episode(episode=episode_str) else:
else:
episode = season.episode(title=episode_str)
except NotFound:
logger.error(f"Metadata Error: Episode {episode_str} in Season {season_id} not found") logger.error(f"Metadata Error: Episode {episode_str} in Season {season_id} not found")
continue continue
episode_methods = {em.lower(): em for em in episode_dict} episode_methods = {em.lower(): em for em in episode_dict}
@ -619,24 +621,21 @@ class MetadataFile(DataFile):
elif not isinstance(meta[methods["albums"]], dict): elif not isinstance(meta[methods["albums"]], dict):
logger.error("Metadata Error: albums attribute must be a dictionary") logger.error("Metadata Error: albums attribute must be a dictionary")
else: else:
albums = {album.title: album for album in item.albums()}
for album_name, album_dict in meta[methods["albums"]].items(): for album_name, album_dict in meta[methods["albums"]].items():
updated = False updated = False
title = None title = None
album_methods = {am.lower(): am for am in album_dict} album_methods = {am.lower(): am for am in album_dict}
logger.info("") logger.info("")
logger.info(f"Updating album {album_name} of {mapping_name}...") logger.info(f"Updating album {album_name} of {mapping_name}...")
try: if album_name in albums:
album = item.album(album_name) album = albums[album_name]
except NotFound: elif "alt_title" in album_methods and album_dict[album_methods["alt_title"]] and album_dict[album_methods["alt_title"]] in albums:
try: album = albums[album_dict[album_methods["alt_title"]]]
if "alt_title" not in album_methods or not album_dict[album_methods["alt_title"]]: title = album_name
raise NotFound else:
album = item.album(album_dict[album_methods["alt_title"]]) logger.error(f"Metadata Error: Album: {album_name} not found")
title = album_name continue
except NotFound:
logger.error(f"Metadata Error: Album: {album_name} not found")
continue
if not title: if not title:
title = album.title title = album.title
edits = {} edits = {}

Loading…
Cancel
Save