[27] fix anidb genre update

pull/783/head
meisnate12 3 years ago
parent e5e36f823a
commit 8071924a20

@ -1 +1 @@
1.16.1-develop26 1.16.1-develop27

@ -332,7 +332,7 @@ class Cache:
sql = f"UPDATE {map_name} SET {val2_name} = ?, expiration_date = ? WHERE {val1_name} = ?" sql = f"UPDATE {map_name} SET {val2_name} = ?, expiration_date = ? WHERE {val1_name} = ?"
cursor.execute(sql, (val2, expiration_date.strftime("%Y-%m-%d"), val1)) cursor.execute(sql, (val2, expiration_date.strftime("%Y-%m-%d"), val1))
else: else:
sql = f"UPDATE {map_name} SET {val2_name} = ?, expiration_date = ?{'' if media_type is None else ', media_type = ?'} WHERE {val1_name} = ?" sql = f"UPDATE {map_name} SET {val2_name} = ?, expiration_date = ?, media_type = ? WHERE {val1_name} = ?"
cursor.execute(sql, (val2, expiration_date.strftime("%Y-%m-%d"), media_type, val1)) cursor.execute(sql, (val2, expiration_date.strftime("%Y-%m-%d"), media_type, val1))
def query_omdb(self, imdb_id, expiration): def query_omdb(self, imdb_id, expiration):
@ -504,8 +504,8 @@ class Cache:
tmdb_dict["status"] = row["status"] if row["status"] else None tmdb_dict["status"] = row["status"] if row["status"] else None
tmdb_dict["type"] = row["type"] if row["type"] else None tmdb_dict["type"] = row["type"] if row["type"] else None
tmdb_dict["tvdb_id"] = row["tvdb_id"] if row["tvdb_id"] else None tmdb_dict["tvdb_id"] = row["tvdb_id"] if row["tvdb_id"] else None
tmdb_dict["countries"] = row["countries"] if row["countries"] else None tmdb_dict["countries"] = row["countries"] if row["countries"] else ""
tmdb_dict["seasons"] = row["seasons"] if row["seasons"] else None tmdb_dict["seasons"] = row["seasons"] if row["seasons"] else ""
datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d") datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d")
time_between_insertion = datetime.now() - datetime_object time_between_insertion = datetime.now() - datetime_object
expired = time_between_insertion.days > expiration expired = time_between_insertion.days > expiration

@ -10,40 +10,13 @@ anime_lists_url = "https://raw.githubusercontent.com/Fribb/anime-lists/master/an
class Convert: class Convert:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
self._loaded = False
self._anidb_ids = {} self._anidb_ids = {}
self._mal_to_anidb = {} self._mal_to_anidb = {}
self._anilist_to_anidb = {} self._anilist_to_anidb = {}
self._anidb_to_imdb = {} self._anidb_to_imdb = {}
self._anidb_to_tvdb = {} self._anidb_to_tvdb = {}
self._imdb_to_anidb = {}
@property self._tvdb_to_anidb = {}
def anidb_ids(self):
self._load_anime_conversion()
return self._anidb_ids
@property
def mal_to_anidb(self):
self._load_anime_conversion()
return self._mal_to_anidb
@property
def anilist_to_anidb(self):
self._load_anime_conversion()
return self._anilist_to_anidb
@property
def anidb_to_imdb(self):
self._load_anime_conversion()
return self._anidb_to_imdb
@property
def anidb_to_tvdb(self):
self._load_anime_conversion()
return self._anidb_to_tvdb
def _load_anime_conversion(self):
if not self._loaded:
for anime_id in self.config.get_json(anime_lists_url): for anime_id in self.config.get_json(anime_lists_url):
if "anidb_id" in anime_id: if "anidb_id" in anime_id:
self._anidb_ids[anime_id["anidb_id"]] = anime_id self._anidb_ids[anime_id["anidb_id"]] = anime_id
@ -53,9 +26,23 @@ class Convert:
self._anilist_to_anidb[int(anime_id["anilist_id"])] = int(anime_id["anidb_id"]) self._anilist_to_anidb[int(anime_id["anilist_id"])] = int(anime_id["anidb_id"])
if "imdb_id" in anime_id and str(anime_id["imdb_id"]).startswith("tt"): if "imdb_id" in anime_id and str(anime_id["imdb_id"]).startswith("tt"):
self._anidb_to_imdb[int(anime_id["anidb_id"])] = util.get_list(anime_id["imdb_id"]) self._anidb_to_imdb[int(anime_id["anidb_id"])] = util.get_list(anime_id["imdb_id"])
for im_id in util.get_list(anime_id["imdb_id"]):
self._imdb_to_anidb[im_id] = int(anime_id["anidb_id"])
if "thetvdb_id" in anime_id: if "thetvdb_id" in anime_id:
self._anidb_to_tvdb[int(anime_id["anidb_id"])] = int(anime_id["thetvdb_id"]) self._anidb_to_tvdb[int(anime_id["anidb_id"])] = int(anime_id["thetvdb_id"])
self._loaded = True self._tvdb_to_anidb[int(anime_id["thetvdb_id"])] = int(anime_id["anidb_id"])
def imdb_to_anidb(self, imdb_id):
if imdb_id in self._imdb_to_anidb:
return self._imdb_to_anidb[imdb_id]
else:
raise Failed(f"AniDB ID not found for IMDb ID: {imdb_id}")
def tvdb_to_anidb(self, tvdb_id):
if int(tvdb_id) in self._tvdb_to_anidb:
return self._tvdb_to_anidb[int(tvdb_id)]
else:
raise Failed(f"AniDB ID not found for TVDb ID: {tvdb_id}")
def anidb_to_ids(self, anidb_ids, library): def anidb_to_ids(self, anidb_ids, library):
ids = [] ids = []
@ -63,18 +50,18 @@ class Convert:
for anidb_id in anidb_list: for anidb_id in anidb_list:
if anidb_id in library.anidb_map: if anidb_id in library.anidb_map:
ids.append((library.anidb_map[anidb_id], "ratingKey")) ids.append((library.anidb_map[anidb_id], "ratingKey"))
elif anidb_id in self.anidb_to_imdb: elif anidb_id in self._anidb_to_imdb:
added = False added = False
for imdb in self.anidb_to_imdb[anidb_id]: for imdb in self._anidb_to_imdb[anidb_id]:
tmdb, tmdb_type = self.imdb_to_tmdb(imdb) tmdb, tmdb_type = self.imdb_to_tmdb(imdb)
if tmdb and tmdb_type == "movie": if tmdb and tmdb_type == "movie":
ids.append((tmdb, "tmdb")) ids.append((tmdb, "tmdb"))
added = True added = True
if added is False and anidb_id in self.anidb_to_tvdb: 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_tvdb[anidb_id], "tvdb"))
elif anidb_id in self.anidb_to_tvdb: elif anidb_id in self._anidb_to_tvdb:
ids.append((self.anidb_to_tvdb[anidb_id], "tvdb")) ids.append((self._anidb_to_tvdb[anidb_id], "tvdb"))
elif anidb_id in self.anidb_ids: elif anidb_id in self._anidb_ids:
logger.warning(f"Convert Error: No TVDb ID or IMDb ID found for AniDB ID: {anidb_id}") logger.warning(f"Convert Error: No TVDb ID or IMDb ID found for AniDB ID: {anidb_id}")
else: else:
logger.warning(f"Convert Error: AniDB ID: {anidb_id} not found") logger.warning(f"Convert Error: AniDB ID: {anidb_id} not found")
@ -83,8 +70,8 @@ class Convert:
def anilist_to_ids(self, anilist_ids, library): def anilist_to_ids(self, anilist_ids, library):
anidb_ids = [] anidb_ids = []
for anilist_id in anilist_ids: for anilist_id in anilist_ids:
if anilist_id in self.anilist_to_anidb: if anilist_id in self._anilist_to_anidb:
anidb_ids.append(self.anilist_to_anidb[anilist_id]) anidb_ids.append(self._anilist_to_anidb[anilist_id])
else: else:
logger.warning(f"Convert Error: AniDB ID not found for AniList ID: {anilist_id}") logger.warning(f"Convert Error: AniDB ID not found for AniList ID: {anilist_id}")
return self.anidb_to_ids(anidb_ids, library) return self.anidb_to_ids(anidb_ids, library)
@ -94,8 +81,8 @@ class Convert:
for mal_id in mal_ids: for mal_id in mal_ids:
if int(mal_id) in library.mal_map: if int(mal_id) in library.mal_map:
ids.append((library.mal_map[int(mal_id)], "ratingKey")) ids.append((library.mal_map[int(mal_id)], "ratingKey"))
elif int(mal_id) in self.mal_to_anidb: elif int(mal_id) in self._mal_to_anidb:
ids.extend(self.anidb_to_ids(self.mal_to_anidb[int(mal_id)], library)) ids.extend(self.anidb_to_ids(self._mal_to_anidb[int(mal_id)], library))
else: else:
logger.warning(f"Convert Error: AniDB ID not found for MyAnimeList ID: {mal_id}") logger.warning(f"Convert Error: AniDB ID not found for MyAnimeList ID: {mal_id}")
return ids return ids
@ -275,26 +262,26 @@ class Convert:
raise Failed(f"Hama Agent ID: {check_id} not supported") raise Failed(f"Hama Agent ID: {check_id} not supported")
elif item_type == "myanimelist": elif item_type == "myanimelist":
library.mal_map[int(check_id)] = item.ratingKey library.mal_map[int(check_id)] = item.ratingKey
if int(check_id) in self.mal_to_anidb: if int(check_id) in self._mal_to_anidb:
anidb_id = self.mal_to_anidb[int(check_id)] anidb_id = self._mal_to_anidb[int(check_id)]
else: else:
raise Failed(f"AniDB ID not found for MyAnimeList ID: {check_id}") raise Failed(f"AniDB ID not found for MyAnimeList ID: {check_id}")
elif item_type == "local": raise Failed("No match in Plex") elif item_type == "local": raise Failed("No match in Plex")
else: raise Failed(f"Agent {item_type} not supported") else: raise Failed(f"Agent {item_type} not supported")
if anidb_id: if anidb_id:
if anidb_id in self.anidb_to_imdb: if anidb_id in self._anidb_to_imdb:
added = False added = False
for imdb in self.anidb_to_imdb[anidb_id]: for imdb in self._anidb_to_imdb[anidb_id]:
tmdb, tmdb_type = self.imdb_to_tmdb(imdb) tmdb, tmdb_type = self.imdb_to_tmdb(imdb)
if tmdb and tmdb_type == "movie": if tmdb and tmdb_type == "movie":
imdb_id.append(imdb) imdb_id.append(imdb)
tmdb_id.append(tmdb) tmdb_id.append(tmdb)
added = True added = True
if added is False and anidb_id in self.anidb_to_tvdb: if added is False and anidb_id in self._anidb_to_tvdb:
tvdb_id.append(self.anidb_to_tvdb[anidb_id]) tvdb_id.append(self._anidb_to_tvdb[anidb_id])
elif anidb_id in self.anidb_to_tvdb: elif anidb_id in self._anidb_to_tvdb:
tvdb_id.append(self.anidb_to_tvdb[anidb_id]) tvdb_id.append(self._anidb_to_tvdb[anidb_id])
else: else:
raise Failed(f"AniDB: {anidb_id} not found") raise Failed(f"AniDB: {anidb_id} not found")
else: else:

@ -459,6 +459,7 @@ def library_operations(config, library):
trakt_ratings = config.Trakt.user_ratings(library.is_movie) if library.mass_trakt_rating_update else [] trakt_ratings = config.Trakt.user_ratings(library.is_movie) if library.mass_trakt_rating_update else []
reverse_anidb = {} reverse_anidb = {}
if library.mass_genre_update == "anidb":
for k, v in library.anidb_map.values(): for k, v in library.anidb_map.values():
reverse_anidb[v] = k reverse_anidb[v] = k
@ -494,6 +495,7 @@ def library_operations(config, library):
library.edit_tags("label", item, append_tags=labels) library.edit_tags("label", item, append_tags=labels)
except Failed: except Failed:
pass pass
path = os.path.dirname(str(item.locations[0])) if library.is_movie else str(item.locations[0]) path = os.path.dirname(str(item.locations[0])) if library.is_movie else str(item.locations[0])
if library.Radarr and library.radarr_add_all_existing and tmdb_id: if library.Radarr and library.radarr_add_all_existing and tmdb_id:
path = path.replace(library.Radarr.plex_path, library.Radarr.radarr_path) path = path.replace(library.Radarr.plex_path, library.Radarr.radarr_path)
@ -542,12 +544,19 @@ def library_operations(config, library):
anidb_item = None anidb_item = None
if library.mass_genre_update == "anidb": if library.mass_genre_update == "anidb":
if item.ratingKey in reverse_anidb: if item.ratingKey in reverse_anidb:
anidb_id = reverse_anidb[item.ratingKey]
elif tvdb_id in config.Convert._tvdb_to_anidb:
anidb_id = config.Convert._tvdb_to_anidb[tvdb_id]
elif imdb_id in config.Convert._imdb_to_anidb:
anidb_id = config.Convert._imdb_to_anidb[imdb_id]
else:
anidb_id = None
logger.info(f"{item.title[:25]:<25} | No AniDB ID for Guid: {item.guid}")
if anidb_id:
try: try:
anidb_item = config.AniDB.get_anime(reverse_anidb[item.ratingKey]) anidb_item = config.AniDB.get_anime(anidb_id)
except Failed as e: except Failed as e:
logger.error(str(e)) logger.error(str(e))
else:
logger.info(f"{item.title[:25]:<25} | No AniDB ID for Guid: {item.guid}")
mdb_item = None mdb_item = None
if library.mass_audience_rating_update in util.mdb_types or library.mass_critic_rating_update in util.mdb_types \ if library.mass_audience_rating_update in util.mdb_types or library.mass_critic_rating_update in util.mdb_types \

Loading…
Cancel
Save