From 9314417ce4be4862d918d38128fee518d2e1803e Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Fri, 12 Feb 2021 09:23:07 -0500 Subject: [PATCH] anime id updates and fix for #22 --- modules/anidb.py | 62 +++++++++++++++++++++++++++-------------------- modules/config.py | 44 +++++++++++++++++++-------------- 2 files changed, 62 insertions(+), 44 deletions(-) diff --git a/modules/anidb.py b/modules/anidb.py index 318f442f..72fe6c3a 100644 --- a/modules/anidb.py +++ b/modules/anidb.py @@ -23,9 +23,12 @@ class AniDBAPI: def convert_tvdb_to_anidb(self, tvdb_id): return self.convert_anidb(tvdb_id, "tvdbid", "anidbid") def convert_imdb_to_anidb(self, imdb_id): return self.convert_anidb(imdb_id, "imdbid", "anidbid") def convert_anidb(self, input_id, from_id, to_id): - ids = self.id_list.xpath("//anime[@{}='{}']/@{}".format(from_id, input_id, to_id)) + ids = self.id_list.xpath("//anime[contains(@{}, '{}')]/@{}".format(from_id, input_id, to_id)) if len(ids) > 0: - if len(ids[0]) > 0: return ids[0] if to_id == "imdbid" else int(ids[0]) + if from_id == "tvdbid": return [int(id) for id in ids] + if len(ids[0]) > 0: + try: return ids[0].split(",") if to_id == "imdbid" else int(ids[0]) + except ValueError: raise Failed("AniDB Error: No {} ID found for {} ID: {}".format(util.pretty_ids[to_id], util.pretty_ids[from_id], input_id)) else: raise Failed("AniDB Error: No {} ID found for {} ID: {}".format(util.pretty_ids[to_id], util.pretty_ids[from_id], input_id)) else: raise Failed("AniDB Error: {} ID: {} not found".format(util.pretty_ids[from_id], input_id)) @@ -77,7 +80,7 @@ class AniDBAPI: movie_ids = [] for anidb_id in anime_ids: try: - tmdb_id, tvdb_id = self.convert_from_imdb(self.convert_anidb_to_imdb(anidb_id), language) + tmdb_id = self.convert_from_imdb(self.convert_anidb_to_imdb(anidb_id), language) if tmdb_id: movie_ids.append(tmdb_id) else: raise Failed except Failed: @@ -90,27 +93,34 @@ class AniDBAPI: return movie_ids, show_ids def convert_from_imdb(self, imdb_id, language): - if self.Cache: - tmdb_id, tvdb_id = self.Cache.get_ids_from_imdb(imdb_id) - expired = False - if not tmdb_id: - tmdb_id, expired = self.Cache.get_tmdb_from_imdb(imdb_id) - if expired: - tmdb_id = None - else: - tmdb_id = None - from_cache = tmdb_id is not None + output_tmdb_ids = [] + if not isinstance(imdb_id, list): + imdb_id = [imdb_id] + + for imdb in imdb_id: + if self.Cache: + tmdb_id, tvdb_id = self.Cache.get_ids_from_imdb(imdb) + expired = False + if not tmdb_id: + tmdb_id, expired = self.Cache.get_tmdb_from_imdb(imdb) + if expired: + tmdb_id = None + else: + tmdb_id = None + from_cache = tmdb_id is not None - if not tmdb_id and self.TMDb: - try: tmdb_id = self.TMDb.convert_imdb_to_tmdb(imdb_id) - except Failed: pass - if not tmdb_id and self.Trakt: - try: tmdb_id = self.Trakt.convert_imdb_to_tmdb(imdb_id) - except Failed: pass - try: - if tmdb_id and not from_cache: self.TMDb.get_movie(tmdb_id) - except Failed: tmdb_id = None - if not tmdb_id: raise Failed("TVDb Error: No TMDb ID found for IMDb: {}".format(imdb_id)) - if self.Cache and tmdb_id and expired is not False: - self.Cache.update_imdb("movie", expired, imdb_id, tmdb_id) - return tmdb_id + if not tmdb_id and self.TMDb: + try: tmdb_id = self.TMDb.convert_imdb_to_tmdb(imdb) + except Failed: pass + if not tmdb_id and self.Trakt: + try: tmdb_id = self.Trakt.convert_imdb_to_tmdb(imdb) + except Failed: pass + try: + if tmdb_id and not from_cache: self.TMDb.get_movie(tmdb_id) + except Failed: tmdb_id = None + if tmdb_id: output_tmdb_ids.append(tmdb_id) + if self.Cache and tmdb_id and expired is not False: + self.Cache.update_imdb("movie", expired, imdb, tmdb_id) + if len(output_tmdb_ids) == 0: raise Failed("AniDB Error: No TMDb ID found for IMDb: {}".format(imdb_id)) + elif len(output_tmdb_ids) == 1: return output_tmdb_ids[0] + else: return output_tmdb_ids diff --git a/modules/config.py b/modules/config.py index ee587d26..8f1069e2 100644 --- a/modules/config.py +++ b/modules/config.py @@ -1067,10 +1067,14 @@ class Config: for i, item in enumerate(items, 1): length = util.print_return(length, "Processing: {}/{} {}".format(i, len(items), item.title)) id_type, main_id = self.get_id(item, library, length) - if id_type == "movie": - movie_map[main_id] = item.ratingKey - elif id_type == "show": - show_map[main_id] = item.ratingKey + if isinstance(main_id, list): + if id_type == "movie": + for m in main_id: movie_map[m] = item.ratingKey + elif id_type == "show": + for m in main_id: show_map[m] = item.ratingKey + else: + if id_type == "movie": movie_map[main_id] = item.ratingKey + elif id_type == "show": show_map[main_id] = item.ratingKey util.print_end(length, "Processed {} {}".format(len(items), "Movies" if library.is_movie else "Shows")) return movie_map, show_map @@ -1130,6 +1134,17 @@ class Config: if mal_id and not tmdb_id: try: tmdb_id = self.MyAnimeListIDList.convert_mal_to_tmdb(mal_id) except Failed: pass + if not tmdb_id and imdb_id and isinstance(imdb_id, list) and self.TMDb: + tmdb_id = [] + new_imdb_id = [] + for imdb in imdb_id: + try: + temp_tmdb_id = self.TMDb.convert_imdb_to_tmdb(imdb) + tmdb_id.append(temp_tmdb_id) + new_imdb_id.append(imdb) + except Failed: + continue + imdb_id = new_imdb_id if not tmdb_id and imdb_id and self.TMDb: try: tmdb_id = self.TMDb.convert_imdb_to_tmdb(imdb_id) except Failed: pass @@ -1160,18 +1175,6 @@ class Config: if not tvdb_id and imdb_id and self.Trakt and library.is_show: try: tvdb_id = self.Trakt.convert_imdb_to_tvdb(imdb_id) except Failed: pass - if tvdb_id and not anidb_id: - try: anidb_id = self.AniDB.convert_tvdb_to_anidb(tvdb_id) - except Failed: pass - if imdb_id and not anidb_id: - try: anidb_id = self.AniDB.convert_imdb_to_anidb(imdb_id) - except Failed: pass - if tvdb_id and not mal_id: - try: mal_id = self.MyAnimeListIDList.convert_tvdb_to_mal(tvdb_id) - except Failed: pass - if tmdb_id and not mal_id: - try: mal_id = self.MyAnimeListIDList.convert_tmdb_to_mal(tmdb_id) - except Failed: pass if (not tmdb_id and library.is_movie) or (not tvdb_id and not ((anidb_id or mal_id) and tmdb_id) and library.is_show): service_name = "TMDb ID" if library.is_movie else "TVDb ID" @@ -1194,8 +1197,13 @@ class Config: elif id_name: error_message = "Configure TMDb or Trakt to covert {} to {}".format(id_name, service_name) else: error_message = "No ID to convert to {}".format(service_name) if self.Cache and (tmdb_id and library.is_movie) or ((tvdb_id or ((anidb_id or mal_id) and tmdb_id)) and library.is_show): - util.print_end(length, "Cache | {} | {:<46} | {:<6} | {:<10} | {:<6} | {:<5} | {:<5} | {}".format("^" if expired is True else "+", item.guid, tmdb_id if tmdb_id else "None", imdb_id if imdb_id else "None", tvdb_id if tvdb_id else "None", anidb_id if anidb_id else "None", mal_id if mal_id else "None", item.title)) - self.Cache.update_guid("movie" if library.is_movie else "show", item.guid, tmdb_id, imdb_id, tvdb_id, anidb_id, mal_id, expired) + if isinstance(tmdb_id, list): + for i in range(len(tmdb_id)): + util.print_end(length, "Cache | {} | {:<46} | {:<6} | {:<10} | {:<6} | {:<5} | {:<5} | {}".format("^" if expired is True else "+", item.guid, tmdb_id[i] if tmdb_id[i] else "None", imdb_id[i] if imdb_id[i] else "None", tvdb_id if tvdb_id else "None", anidb_id if anidb_id else "None", mal_id if mal_id else "None", item.title)) + self.Cache.update_guid("movie" if library.is_movie else "show", item.guid, tmdb_id[i], imdb_id[i], tvdb_id, anidb_id, mal_id, expired) + else: + util.print_end(length, "Cache | {} | {:<46} | {:<6} | {:<10} | {:<6} | {:<5} | {:<5} | {}".format("^" if expired is True else "+", item.guid, tmdb_id if tmdb_id else "None", imdb_id if imdb_id else "None", tvdb_id if tvdb_id else "None", anidb_id if anidb_id else "None", mal_id if mal_id else "None", item.title)) + self.Cache.update_guid("movie" if library.is_movie else "show", item.guid, tmdb_id, imdb_id, tvdb_id, anidb_id, mal_id, expired) if tmdb_id and library.is_movie: return "movie", tmdb_id elif tvdb_id and library.is_show: return "show", tvdb_id elif (anidb_id or mal_id) and tmdb_id: return "movie", tmdb_id