[20] Add automated Anime Aggregations

This commit is contained in:
meisnate12 2024-05-17 13:50:12 -04:00
parent 4541e7a73d
commit 8a4300b8fd
6 changed files with 63 additions and 37 deletions

View file

@ -5,6 +5,7 @@
# New Features
Checks requirement versions to print a message if one needs to be updated
Added the `mass_added_at_update` operation to mass set the Added At field of Movies and Shows.
Add automated Anime Aggregations for AniDB matching
# Updates
Changed the `overlay_artwork_filetype` Setting to accept `webp_lossy` and `webp_lossless` while the old attribute `webp` will be treated as `webp_lossy`.

View file

@ -1 +1 @@
2.0.1-develop19
2.0.1-develop20

View file

@ -16,6 +16,10 @@ class Convert:
self._anilist_to_anidb = {}
self._anidb_to_imdb = {}
self._anidb_to_tvdb = {}
self._anidb_to_tmdb_movie = {}
self._anidb_to_tmdb_show = {}
self._tmdb_movie_to_anidb = {}
self._tmdb_show_to_anidb = {}
self._imdb_to_anidb = {}
self._tvdb_to_anidb = {}
self._anidb_ids = self.config.get_json(anime_lists_url)
@ -37,6 +41,14 @@ class Convert:
self._anidb_to_tvdb[anidb_id] = int(ids["tvdb_id"])
if "tvdb_season" in ids and ids["tvdb_season"] in [1, -1] and ids["tvdb_epoffset"] == 0:
self._tvdb_to_anidb[int(ids["tvdb_id"])] = anidb_id
if "tmdb_movie_id" in ids:
self._anidb_to_tmdb_movie[anidb_id] = util.get_list(ids["tmdb_movie_id"])
for tm_id in util.get_list(ids["tmdb_movie_id"]):
self._tmdb_movie_to_anidb[tm_id] = anidb_id
if "tmdb_show_id" in ids:
self._anidb_to_tmdb_show[anidb_id] = util.get_list(ids["tmdb_show_id"])
for tm_id in util.get_list(ids["tmdb_show_id"]):
self._tmdb_show_to_anidb[tm_id] = anidb_id
def imdb_to_anidb(self, imdb_id):
if imdb_id in self._imdb_to_anidb:
@ -50,6 +62,22 @@ class Convert:
else:
raise Failed(f"AniDB ID not found for TVDb ID: {tvdb_id}")
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:
return self._tvdb_to_anidb[int(tvdb_id)]
else:
tmdb_show_id = self.tvdb_to_tmdb(tvdb_id)
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:
return self._imdb_to_anidb[imdb_id]
elif tmdb_id in self._tmdb_movie_to_anidb:
return self._tmdb_movie_to_anidb[tmdb_id]
else:
return None
def anidb_to_ids(self, anidb_ids, library):
ids = []
anidb_list = anidb_ids if isinstance(anidb_ids, list) else [anidb_ids]
@ -65,8 +93,23 @@ 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"))
elif anidb_id in self._anidb_to_tmdb_movie:
added = False
for tmdb_id in self._anidb_to_tmdb_movie[anidb_id]:
ids.append((tmdb_id, "tmdb"))
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:
for tmdb_id in self._anidb_to_tmdb_show[anidb_id]:
try:
ids.append((int(self.tmdb_to_tvdb(tmdb_id, fail=True)), "tvdb"))
except Failed:
pass
ids.append((self._anidb_to_tmdb_movie[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:
@ -210,7 +253,7 @@ class Convert:
else:
return None
def ids_from_cache(self, ratingKey, guid, item_type, check_id, library):
def ids_from_cache(self, rating_key, guid, item_type, check_id, library):
media_id_type = None
cache_id = None
imdb_check = None
@ -221,9 +264,9 @@ class Convert:
media_id_type = "movie" if "movie" in media_type else "show"
if item_type == "hama" and check_id.startswith("anidb"):
anidb_id = int(re.search("-(.*)", check_id).group(1))
library.anidb_map[anidb_id] = ratingKey
library.anidb_map[anidb_id] = rating_key
elif item_type == "myanimelist":
library.mal_map[int(check_id)] = ratingKey
library.mal_map[int(check_id)] = rating_key
return media_id_type, cache_id, imdb_check, expired
def scan_guid(self, guid_str):

View file

@ -31,7 +31,9 @@ class Library(ABC):
self.show_map = {}
self.imdb_map = {}
self.anidb_map = {}
self.reverse_anidb = {}
self.mal_map = {}
self.reverse_mal = {}
self.movie_rating_key_map = {}
self.show_rating_key_map = {}
self.imdb_rating_key_map = {}
@ -404,5 +406,11 @@ class Library(ABC):
if imdb_id:
self.imdb_rating_key_map[key] = imdb_id[0]
util.add_dict_list(imdb_id, key, self.imdb_map)
self.reverse_anidb = {}
for k, v in self.anidb_map.items():
self.reverse_anidb[v] = k
self.reverse_mal = {}
for k, v in self.mal_map.items():
self.reverse_mal[v] = k
logger.info("")
logger.info(f"Processed {len(items)} {self.type}s")

View file

@ -101,13 +101,6 @@ class Operations:
ep_lock_edits = {}
ep_unlock_edits = {}
reverse_anidb = {}
for k, v in self.library.anidb_map.items():
reverse_anidb[v] = k
reverse_mal = {}
for k, v in self.library.mal_map.items():
reverse_mal[v] = k
if self.library.assets_for_all and not self.library.asset_directory:
logger.error("Asset Error: No Asset Directory for Assets For All")
@ -270,14 +263,8 @@ class Operations:
anidb_id = None
def get_anidb_id():
if item.ratingKey in reverse_anidb:
return reverse_anidb[item.ratingKey]
elif tvdb_id in self.config.Convert._tvdb_to_anidb:
return self.config.Convert._tvdb_to_anidb[tvdb_id]
elif imdb_id in self.config.Convert._imdb_to_anidb:
return self.config.Convert._imdb_to_anidb[imdb_id]
else:
return False
temp_id = self.config.Convert.ids_to_anidb(self.library, item.ratingKey, tvdb_id, imdb_id, tmdb_id)
return temp_id if temp_id else False
_anidb_obj = None
def anidb_obj():
@ -305,8 +292,8 @@ class Operations:
if anidb_id is None:
anidb_id = get_anidb_id()
mal_id = None
if item.ratingKey in reverse_mal:
mal_id = reverse_mal[item.ratingKey]
if item.ratingKey in self.library.reverse_mal:
mal_id = self.library.reverse_mal[item.ratingKey]
elif not anidb_id:
logger.warning(f"Convert Warning: No AniDB ID to Convert to MyAnimeList ID for Guid: {item.guid}")
elif anidb_id not in self.config.Convert._anidb_to_mal:

View file

@ -81,13 +81,6 @@ class Overlays:
raise Failed
return _trakt_ratings
reverse_anidb = {}
for k, v in self.library.anidb_map.items():
reverse_anidb[v] = k
reverse_mal = {}
for k, v in self.library.mal_map.items():
reverse_mal[v] = k
for i, (over_key, (item, over_names)) in enumerate(sorted(key_to_overlays.items(), key=lambda io: self.library.get_item_sort_title(io[1][0])), 1):
item_title = self.library.get_item_sort_title(item, atr="title")
try:
@ -358,13 +351,7 @@ class Overlays:
found_rating = mdb_item.score / 10 if mdb_item.score else None
elif str(format_var).startswith(("anidb", "mal")):
anidb_id = None
if item.ratingKey in reverse_anidb:
anidb_id = reverse_anidb[item.ratingKey]
elif tvdb_id in self.config.Convert._tvdb_to_anidb:
anidb_id = self.config.Convert._tvdb_to_anidb[tvdb_id]
elif imdb_id in self.config.Convert._imdb_to_anidb:
anidb_id = self.config.Convert._imdb_to_anidb[imdb_id]
anidb_id = self.config.Convert.ids_to_anidb(self.library, item.ratingKey, tvdb_id, imdb_id, tmdb_id)
if str(format_var).startswith("anidb"):
if anidb_id:
@ -378,8 +365,8 @@ class Overlays:
else:
raise Failed(f"No AniDB ID for Guid: {item.guid}")
else:
if item.ratingKey in reverse_mal:
mal_id = reverse_mal[item.ratingKey]
if item.ratingKey in self.library.reverse_mal:
mal_id = self.library.reverse_mal[item.ratingKey]
elif not anidb_id:
raise Failed(f"Convert Warning: No AniDB ID to Convert to MyAnimeList ID for Guid: {item.guid}")
elif anidb_id not in self.config.Convert._anidb_to_mal: