From 3af2dee7c5f2dedfcbd53d8791de37df77c5033d Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 6 Jun 2024 09:16:57 -0400 Subject: [PATCH] [2] Fixed multiple anime `int()` Errors (#2099) --- CHANGELOG | 1 + VERSION | 2 +- modules/builder.py | 328 +++++++++++++++++++++++---------------------- modules/convert.py | 6 +- 4 files changed, 170 insertions(+), 167 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2ac0ffa2..e516e4cf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,5 +10,6 @@ Added [`letterboxd_user_lists`](https://kometa.wiki/en/latest/files/dynamic_type # Defaults # Bug Fixes +Fixed multiple anime `int()` Errors Various other Minor Fixes \ No newline at end of file diff --git a/VERSION b/VERSION index 3072430c..bd5cac7a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.2-build1 +2.0.2-build2 diff --git a/modules/builder.py b/modules/builder.py index 8f41f0e8..2b3d6780 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -2234,179 +2234,183 @@ class CollectionBuilder: logger.trace(f"IDs: {ids}") logger.debug("") for i, input_data in enumerate(ids, 1): - input_id, id_type = input_data - logger.ghost(f"Parsing ID {i}/{total_ids}") - rating_keys = [] - if id_type == "ratingKey": - rating_keys = int(input_id) - elif id_type == "imdb": - if input_id not in self.ignore_imdb_ids: - found = False - for pl_library in self.libraries: - if input_id in pl_library.imdb_map: - found = True - rating_keys = pl_library.imdb_map[input_id] - break - if not found and (self.builder_level == "episode" or self.playlist or self.do_missing): - try: - _id, tmdb_type = self.config.Convert.imdb_to_tmdb(input_id, fail=True) - if tmdb_type == "episode" and (self.builder_level == "episode" or self.playlist): - try: - tmdb_id, season_num, episode_num = _id.split("_") - tvdb_id = self.config.Convert.tmdb_to_tvdb(tmdb_id, fail=True) - tvdb_id = int(tvdb_id) - except Failed as e: + try: + input_id, id_type = input_data + logger.ghost(f"Parsing ID {i}/{total_ids}") + rating_keys = [] + if id_type == "ratingKey": + rating_keys = int(input_id) + elif id_type == "imdb": + if input_id not in self.ignore_imdb_ids: + found = False + for pl_library in self.libraries: + if input_id in pl_library.imdb_map: + found = True + rating_keys = pl_library.imdb_map[input_id] + break + if not found and (self.builder_level == "episode" or self.playlist or self.do_missing): + try: + _id, tmdb_type = self.config.Convert.imdb_to_tmdb(input_id, fail=True) + if tmdb_type == "episode" and (self.builder_level == "episode" or self.playlist): try: - if not self.config.OMDb: - raise Failed("") - if self.config.OMDb.limit: - raise Failed(" and OMDb limit reached.") - omdb_item = self.config.OMDb.get_omdb(input_id) - tvdb_id = omdb_item.series_id - season_num = omdb_item.season_num - episode_num = omdb_item.episode_num - if not tvdb_id or not season_num or not episode_num: - raise Failed(f" and OMDb metadata lookup Failed for IMDb ID: {input_id}") - except Failed as ee: - logger.error(f"{e}{ee}") - continue - for pl_library in self.libraries: - if tvdb_id in pl_library.show_map: - found = True - show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0]) + tmdb_id, season_num, episode_num = _id.split("_") + tvdb_id = self.config.Convert.tmdb_to_tvdb(tmdb_id, fail=True) + tvdb_id = int(tvdb_id) + except Failed as e: try: - items.append(show_item.episode(season=int(season_num), episode=int(episode_num))) - except NotFound: - self.missing_parts.append(f"{show_item.title} Season: {season_num} Episode: {episode_num} Missing") - break - if not found and tvdb_id not in self.missing_shows and self.do_missing: - self.missing_shows.append(tvdb_id) - elif tmdb_type == "movie" and self.do_missing and _id not in self.missing_movies: - self.missing_movies.append(_id) - elif tmdb_type in ["show", "episode"] and self.do_missing: - if tmdb_type == "episode": - tmdb_id, _, _ = _id.split("_") - else: - tmdb_id = _id - tvdb_id = self.config.Convert.tmdb_to_tvdb(tmdb_id, fail=True) - if tvdb_id not in self.missing_shows: - self.missing_shows.append(tvdb_id) - except Failed as e: - logger.warning(e) - continue - elif id_type == "tmdb" and not self.parts_collection: - input_id = int(input_id) - if input_id not in self.ignore_ids: + if not self.config.OMDb: + raise Failed("") + if self.config.OMDb.limit: + raise Failed(" and OMDb limit reached.") + omdb_item = self.config.OMDb.get_omdb(input_id) + tvdb_id = omdb_item.series_id + season_num = omdb_item.season_num + episode_num = omdb_item.episode_num + if not tvdb_id or not season_num or not episode_num: + raise Failed(f" and OMDb metadata lookup Failed for IMDb ID: {input_id}") + except Failed as ee: + logger.error(f"{e}{ee}") + continue + for pl_library in self.libraries: + if tvdb_id in pl_library.show_map: + found = True + show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0]) + try: + items.append(show_item.episode(season=int(season_num), episode=int(episode_num))) + except NotFound: + self.missing_parts.append(f"{show_item.title} Season: {season_num} Episode: {episode_num} Missing") + break + if not found and tvdb_id not in self.missing_shows and self.do_missing: + self.missing_shows.append(tvdb_id) + elif tmdb_type == "movie" and self.do_missing and _id not in self.missing_movies: + self.missing_movies.append(_id) + elif tmdb_type in ["show", "episode"] and self.do_missing: + if tmdb_type == "episode": + tmdb_id, _, _ = _id.split("_") + else: + tmdb_id = _id + tvdb_id = self.config.Convert.tmdb_to_tvdb(tmdb_id, fail=True) + if tvdb_id not in self.missing_shows: + self.missing_shows.append(tvdb_id) + except Failed as e: + logger.warning(e) + continue + elif id_type == "tmdb" and not self.parts_collection: + input_id = int(input_id) + if input_id not in self.ignore_ids: + found = False + for pl_library in self.libraries: + if input_id in pl_library.movie_map: + found = True + rating_keys = pl_library.movie_map[input_id] + break + if not found and input_id not in self.missing_movies: + self.missing_movies.append(input_id) + elif id_type == "tvdb_season" and (self.builder_level == "season" or self.playlist): + tvdb_id, season_num = input_id.split("_") + tvdb_id = int(tvdb_id) found = False for pl_library in self.libraries: - if input_id in pl_library.movie_map: + if tvdb_id in pl_library.show_map: found = True - rating_keys = pl_library.movie_map[input_id] + show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0]) + try: + season_obj = show_item.season(season=int(season_num)) + if self.playlist: + items.extend(season_obj.episodes()) + else: + items.append(season_obj) + except NotFound: + self.missing_parts.append(f"{show_item.title} Season: {season_num} Missing") break - if not found and input_id not in self.missing_movies: - self.missing_movies.append(input_id) - elif id_type == "tvdb_season" and (self.builder_level == "season" or self.playlist): - tvdb_id, season_num = input_id.split("_") - tvdb_id = int(tvdb_id) - found = False - for pl_library in self.libraries: - if tvdb_id in pl_library.show_map: - found = True - show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0]) - try: - season_obj = show_item.season(season=int(season_num)) - if self.playlist: - items.extend(season_obj.episodes()) - else: - items.append(season_obj) - except NotFound: - self.missing_parts.append(f"{show_item.title} Season: {season_num} Missing") - break - if not found and tvdb_id not in self.missing_shows: - self.missing_shows.append(tvdb_id) - elif id_type == "tvdb_episode" and (self.builder_level == "episode" or self.playlist): - tvdb_id, season_num, episode_num = input_id.split("_") - tvdb_id = int(tvdb_id) - found = False - for pl_library in self.libraries: - if tvdb_id in pl_library.show_map: - found = True - show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0]) - try: - items.append(show_item.episode(season=int(season_num), episode=int(episode_num))) - except NotFound: - self.missing_parts.append(f"{show_item.title} Season: {season_num} Episode: {episode_num} Missing") - if not found and tvdb_id not in self.missing_shows and self.do_missing: - self.missing_shows.append(tvdb_id) - elif id_type in ["tvdb", "tmdb_show", "tvdb_season", "tvdb_episode"]: - tvdb_season = None - if id_type == "tmdb_show": - try: - tvdb_id = self.config.Convert.tmdb_to_tvdb(input_id, fail=True) - except Failed as e: - logger.warning(e) - continue - elif id_type == "tvdb_season": - tvdb_id, tvdb_season = input_id.split("_") - tvdb_id = int(tvdb_id) - tvdb_season = int(tvdb_season) - elif id_type == "tvdb_episode": - tvdb_id, _, _ = input_id.split("_") + if not found and tvdb_id not in self.missing_shows: + self.missing_shows.append(tvdb_id) + elif id_type == "tvdb_episode" and (self.builder_level == "episode" or self.playlist): + tvdb_id, season_num, episode_num = input_id.split("_") tvdb_id = int(tvdb_id) - else: - tvdb_id = int(input_id) - if tvdb_id not in self.ignore_ids: - found_keys = None + found = False for pl_library in self.libraries: if tvdb_id in pl_library.show_map: - found_keys = pl_library.show_map[tvdb_id] - break - if not found_keys and tvdb_id not in self.missing_shows: + found = True + show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0]) + try: + items.append(show_item.episode(season=int(season_num), episode=int(episode_num))) + except NotFound: + self.missing_parts.append(f"{show_item.title} Season: {season_num} Episode: {episode_num} Missing") + if not found and tvdb_id not in self.missing_shows and self.do_missing: self.missing_shows.append(tvdb_id) - if found_keys: - if self.parts_collection: - rating_keys = [] - for rk in found_keys: - try: - item = self.library.fetch_item(rk) - if self.builder_level == "episode" and isinstance(item, Show): - if tvdb_season is not None: - item = item.season(season=tvdb_season) - rating_keys.extend([k.ratingKey for k in item.episodes()]) - elif self.builder_level == "season" and isinstance(item, Show): - rating_keys.extend([k.ratingKey for k in item.seasons()]) - except Failed as e: - logger.error(e) - else: - rating_keys = found_keys - else: - continue - - if not isinstance(rating_keys, list): - rating_keys = [rating_keys] - for rk in rating_keys: - try: - item = self.library.fetch_item(rk) - if self.playlist and isinstance(item, (Show, Season)): - items.extend(item.episodes()) - elif self.builder_level == "movie" and not isinstance(item, Movie): - logger.info(f"Item: {item} is not an Movie") - elif self.builder_level == "show" and not isinstance(item, Show): - logger.info(f"Item: {item} is not an Show") - elif self.builder_level == "episode" and not isinstance(item, Episode): - logger.info(f"Item: {item} is not an Episode") - elif self.builder_level == "season" and not isinstance(item, Season): - logger.info(f"Item: {item} is not a Season") - elif self.builder_level == "artist" and not isinstance(item, Artist): - logger.info(f"Item: {item} is not an Artist") - elif self.builder_level == "album" and not isinstance(item, Album): - logger.info(f"Item: {item} is not an Album") - elif self.builder_level == "track" and not isinstance(item, Track): - logger.info(f"Item: {item} is not a Track") + elif id_type in ["tvdb", "tmdb_show", "tvdb_season", "tvdb_episode"]: + tvdb_season = None + if id_type == "tmdb_show": + try: + tvdb_id = self.config.Convert.tmdb_to_tvdb(input_id, fail=True) + except Failed as e: + logger.warning(e) + continue + elif id_type == "tvdb_season": + tvdb_id, tvdb_season = input_id.split("_") + tvdb_id = int(tvdb_id) + tvdb_season = int(tvdb_season) + elif id_type == "tvdb_episode": + tvdb_id, _, _ = input_id.split("_") + tvdb_id = int(tvdb_id) else: - items.append(item) - except Failed as e: - logger.error(e) + tvdb_id = int(input_id) + if tvdb_id not in self.ignore_ids: + found_keys = None + for pl_library in self.libraries: + if tvdb_id in pl_library.show_map: + found_keys = pl_library.show_map[tvdb_id] + break + if not found_keys and tvdb_id not in self.missing_shows: + self.missing_shows.append(tvdb_id) + if found_keys: + if self.parts_collection: + rating_keys = [] + for rk in found_keys: + try: + item = self.library.fetch_item(rk) + if self.builder_level == "episode" and isinstance(item, Show): + if tvdb_season is not None: + item = item.season(season=tvdb_season) + rating_keys.extend([k.ratingKey for k in item.episodes()]) + elif self.builder_level == "season" and isinstance(item, Show): + rating_keys.extend([k.ratingKey for k in item.seasons()]) + except Failed as e: + logger.error(e) + else: + rating_keys = found_keys + else: + continue + if not isinstance(rating_keys, list): + rating_keys = [rating_keys] + for rk in rating_keys: + try: + item = self.library.fetch_item(rk) + if self.playlist and isinstance(item, (Show, Season)): + items.extend(item.episodes()) + elif self.builder_level == "movie" and not isinstance(item, Movie): + logger.info(f"Item: {item} is not an Movie") + elif self.builder_level == "show" and not isinstance(item, Show): + logger.info(f"Item: {item} is not an Show") + elif self.builder_level == "episode" and not isinstance(item, Episode): + logger.info(f"Item: {item} is not an Episode") + elif self.builder_level == "season" and not isinstance(item, Season): + logger.info(f"Item: {item} is not a Season") + elif self.builder_level == "artist" and not isinstance(item, Artist): + logger.info(f"Item: {item} is not an Artist") + elif self.builder_level == "album" and not isinstance(item, Album): + logger.info(f"Item: {item} is not an Album") + elif self.builder_level == "track" and not isinstance(item, Track): + logger.info(f"Item: {item} is not a Track") + else: + items.append(item) + except Failed as e: + logger.error(e) + except Exception as e: + logger.stacktrace() + logger.error(e) + logger.info(input_data) logger.exorcise() if not items: return None diff --git a/modules/convert.py b/modules/convert.py index 3573be93..1d454186 100644 --- a/modules/convert.py +++ b/modules/convert.py @@ -69,10 +69,10 @@ class Convert: def ids_to_anidb(self, library, rating_key, tvdb_id, imdb_id, tmdb_id): if rating_key in library.reverse_anidb: return library.reverse_anidb[rating_key] - elif int(tvdb_id) in self._tvdb_to_anidb: + elif tvdb_id and int(tvdb_id) in self._tvdb_to_anidb: return self._tvdb_to_anidb[int(tvdb_id)] else: - tmdb_show_id = self.tvdb_to_tmdb(tvdb_id) + tmdb_show_id = self.tvdb_to_tmdb(tvdb_id) if tvdb_id else None if tmdb_show_id and tmdb_show_id in self._tmdb_show_to_anidb: return self._tmdb_show_to_anidb[tmdb_show_id] elif imdb_id in self._imdb_to_anidb: @@ -109,7 +109,6 @@ class Convert: added = True if added is False and anidb_id in self._anidb_to_tvdb: ids.append((self._anidb_to_tvdb[anidb_id], "tvdb")) - ids.append((self._anidb_to_tmdb_movie[anidb_id], "tmdb")) elif anidb_id in self._anidb_to_tvdb: ids.append((self._anidb_to_tvdb[anidb_id], "tvdb")) elif anidb_id in self._anidb_to_tmdb_show: @@ -118,7 +117,6 @@ class Convert: ids.append((int(self.tmdb_to_tvdb(tmdb_id, fail=True)), "tvdb")) except Failed: pass - ids.append((self._anidb_to_tmdb_show[anidb_id], "tmdb")) elif str(anidb_id) in self._anidb_ids: logger.warning(f"Convert Warning: No TVDb ID or IMDb ID found for AniDB ID: {anidb_id}") else: