commit
be23b4a060
@ -1,161 +0,0 @@
|
||||
import logging, requests
|
||||
from lxml import html
|
||||
from modules import util
|
||||
from modules.util import Failed
|
||||
from retrying import retry
|
||||
|
||||
logger = logging.getLogger("Plex Meta Manager")
|
||||
|
||||
class ArmsAPI:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.arms_url = "https://relations.yuna.moe/api/ids"
|
||||
self.anidb_url = "https://raw.githubusercontent.com/Anime-Lists/anime-lists/master/anime-list-master.xml"
|
||||
self.AniDBIDs = self._get_anidb()
|
||||
|
||||
@retry(stop_max_attempt_number=6, wait_fixed=10000)
|
||||
def _get_anidb(self):
|
||||
return html.fromstring(requests.get(self.anidb_url).content)
|
||||
|
||||
def anidb_to_tvdb(self, anidb_id): return self._anidb(anidb_id, "tvdbid")
|
||||
def anidb_to_imdb(self, anidb_id): return self._anidb(anidb_id, "imdbid")
|
||||
def _anidb(self, input_id, to_id):
|
||||
ids = self.AniDBIDs.xpath(f"//anime[contains(@anidbid, '{input_id}')]/@{to_id}")
|
||||
if len(ids) > 0:
|
||||
try:
|
||||
if len(ids[0]) > 0:
|
||||
return ids[0].split(",") if to_id == "imdbid" else int(ids[0])
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
raise Failed(f"Arms Error: No {util.pretty_ids[to_id]} ID found for AniDB ID: {input_id}")
|
||||
else:
|
||||
raise Failed(f"Arms Error: AniDB ID: {input_id} not found")
|
||||
|
||||
@retry(stop_max_attempt_number=6, wait_fixed=10000)
|
||||
def _request(self, ids):
|
||||
return requests.post(self.arms_url, json=ids).json()
|
||||
|
||||
def mal_to_anidb(self, mal_id):
|
||||
anime_ids = self._arms_ids(mal_ids=mal_id)
|
||||
if anime_ids[0] is None:
|
||||
raise Failed(f"Arms Error: MyAnimeList ID: {mal_id} does not exist")
|
||||
if anime_ids[0]["anidb"] is None:
|
||||
raise Failed(f"Arms Error: No AniDB ID for MyAnimeList ID: {mal_id}")
|
||||
return anime_ids[0]["anidb"]
|
||||
|
||||
def anidb_to_ids(self, anidb_list, language):
|
||||
show_ids = []
|
||||
movie_ids = []
|
||||
for anidb_id in anidb_list:
|
||||
try:
|
||||
for imdb_id in self.anidb_to_imdb(anidb_id):
|
||||
tmdb_id, _ = self.imdb_to_ids(imdb_id, language)
|
||||
if tmdb_id:
|
||||
movie_ids.append(tmdb_id)
|
||||
break
|
||||
else:
|
||||
raise Failed
|
||||
except Failed:
|
||||
try:
|
||||
tvdb_id = self.anidb_to_tvdb(anidb_id)
|
||||
if tvdb_id:
|
||||
show_ids.append(tvdb_id)
|
||||
except Failed:
|
||||
logger.error(f"Arms Error: No TVDb ID or IMDb ID found for AniDB ID: {anidb_id}")
|
||||
return movie_ids, show_ids
|
||||
|
||||
def anilist_to_ids(self, anilist_ids, language):
|
||||
anidb_ids = []
|
||||
for id_set in self._arms_ids(anilist_ids=anilist_ids):
|
||||
if id_set["anidb"] is not None:
|
||||
anidb_ids.append(id_set["anidb"])
|
||||
else:
|
||||
logger.error(f"Arms Error: AniDB ID not found for AniList ID: {id_set['anilist']}")
|
||||
return self.anidb_to_ids(anidb_ids, language)
|
||||
|
||||
def myanimelist_to_ids(self, mal_ids, language):
|
||||
anidb_ids = []
|
||||
for id_set in self._arms_ids(mal_ids=mal_ids):
|
||||
if id_set["anidb"] is not None:
|
||||
anidb_ids.append(id_set["anidb"])
|
||||
else:
|
||||
logger.error(f"Arms Error: AniDB ID not found for MyAnimeList ID: {id_set['myanimelist']}")
|
||||
return self.anidb_to_ids(anidb_ids, language)
|
||||
|
||||
def _arms_ids(self, anilist_ids=None, anidb_ids=None, mal_ids=None):
|
||||
all_ids = []
|
||||
def collect_ids(ids, id_name):
|
||||
if ids:
|
||||
if isinstance(ids, list):
|
||||
all_ids.extend([{id_name: a_id} for a_id in ids])
|
||||
else:
|
||||
all_ids.append({id_name: ids})
|
||||
collect_ids(anilist_ids, "anilist")
|
||||
collect_ids(anidb_ids, "anidb")
|
||||
collect_ids(mal_ids, "myanimelist")
|
||||
converted_ids = []
|
||||
if self.config.Cache:
|
||||
unconverted_ids = []
|
||||
for anime_dict in all_ids:
|
||||
for id_type, anime_id in anime_dict.items():
|
||||
query_ids, update = self.config.Cache.query_anime_map(anime_id, id_type)
|
||||
if not update and query_ids:
|
||||
converted_ids.append(query_ids)
|
||||
else:
|
||||
unconverted_ids.append({id_type: anime_id})
|
||||
else:
|
||||
unconverted_ids = all_ids
|
||||
|
||||
for anime_ids in self._request(unconverted_ids):
|
||||
if anime_ids:
|
||||
if self.config.Cache:
|
||||
self.config.Cache.update_anime(False, anime_ids)
|
||||
converted_ids.append(anime_ids)
|
||||
return converted_ids
|
||||
|
||||
def imdb_to_ids(self, imdb_id, language):
|
||||
update_tmdb = False
|
||||
update_tvdb = False
|
||||
if self.config.Cache:
|
||||
tmdb_id, tvdb_id = self.config.Cache.get_ids_from_imdb(imdb_id)
|
||||
update_tmdb = False
|
||||
if not tmdb_id:
|
||||
tmdb_id, update_tmdb = self.config.Cache.get_tmdb_from_imdb(imdb_id)
|
||||
if update_tmdb:
|
||||
tmdb_id = None
|
||||
update_tvdb = False
|
||||
if not tvdb_id:
|
||||
tvdb_id, update_tvdb = self.config.Cache.get_tvdb_from_imdb(imdb_id)
|
||||
if update_tvdb:
|
||||
tvdb_id = None
|
||||
else:
|
||||
tmdb_id = None
|
||||
tvdb_id = None
|
||||
from_cache = tmdb_id is not None or tvdb_id is not None
|
||||
|
||||
if not tmdb_id and not tvdb_id and self.config.TMDb:
|
||||
try: tmdb_id = self.config.TMDb.convert_imdb_to_tmdb(imdb_id)
|
||||
except Failed: pass
|
||||
if not tmdb_id and not tvdb_id and self.config.TMDb:
|
||||
try: tvdb_id = self.config.TMDb.convert_imdb_to_tvdb(imdb_id)
|
||||
except Failed: pass
|
||||
if not tmdb_id and not tvdb_id and self.config.Trakt:
|
||||
try: tmdb_id = self.config.Trakt.convert_imdb_to_tmdb(imdb_id)
|
||||
except Failed: pass
|
||||
if not tmdb_id and not tvdb_id and self.config.Trakt:
|
||||
try: tvdb_id = self.config.Trakt.convert_imdb_to_tvdb(imdb_id)
|
||||
except Failed: pass
|
||||
if tmdb_id and not from_cache:
|
||||
try: self.config.TMDb.get_movie(tmdb_id)
|
||||
except Failed: tmdb_id = None
|
||||
if tvdb_id and not from_cache:
|
||||
try: self.config.TVDb.get_series(language, tvdb_id)
|
||||
except Failed: tvdb_id = None
|
||||
if not tmdb_id and not tvdb_id:
|
||||
raise Failed(f"Arms Error: No TMDb ID or TVDb ID found for IMDb: {imdb_id}")
|
||||
if self.config.Cache:
|
||||
if tmdb_id and update_tmdb is not False:
|
||||
self.config.Cache.update_imdb("movie", update_tmdb, imdb_id, tmdb_id)
|
||||
if tvdb_id and update_tvdb is not False:
|
||||
self.config.Cache.update_imdb("show", update_tvdb, imdb_id, tvdb_id)
|
||||
return tmdb_id, tvdb_id
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,360 @@
|
||||
import logging, re, requests
|
||||
from lxml import html
|
||||
from modules import util
|
||||
from modules.util import Failed
|
||||
from retrying import retry
|
||||
|
||||
logger = logging.getLogger("Plex Meta Manager")
|
||||
|
||||
class Convert:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.arms_url = "https://relations.yuna.moe/api/ids"
|
||||
self.anidb_url = "https://raw.githubusercontent.com/Anime-Lists/anime-lists/master/anime-list-master.xml"
|
||||
self.AniDBIDs = self._get_anidb()
|
||||
|
||||
@retry(stop_max_attempt_number=6, wait_fixed=10000)
|
||||
def _get_anidb(self):
|
||||
return html.fromstring(requests.get(self.anidb_url).content)
|
||||
|
||||
def _anidb(self, input_id, to_id, fail=False):
|
||||
ids = self.AniDBIDs.xpath(f"//anime[contains(@anidbid, '{input_id}')]/@{to_id}")
|
||||
if len(ids) > 0:
|
||||
try:
|
||||
if len(ids[0]) > 0:
|
||||
return util.get_list(ids[0]) if to_id == "imdbid" else int(ids[0])
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
fail_text = f"Convert Error: No {util.pretty_ids[to_id]} ID found for AniDB ID: {input_id}"
|
||||
else:
|
||||
fail_text = f"Convert Error: AniDB ID: {input_id} not found"
|
||||
if fail:
|
||||
raise Failed(fail_text)
|
||||
return [] if to_id == "imdbid" else None
|
||||
|
||||
@retry(stop_max_attempt_number=6, wait_fixed=10000)
|
||||
def _request(self, ids):
|
||||
return requests.post(self.arms_url, json=ids).json()
|
||||
|
||||
def _arms_ids(self, anilist_ids=None, anidb_ids=None, mal_ids=None):
|
||||
all_ids = []
|
||||
def collect_ids(ids, id_name):
|
||||
if ids:
|
||||
if isinstance(ids, list):
|
||||
all_ids.extend([{id_name: a_id} for a_id in ids])
|
||||
else:
|
||||
all_ids.append({id_name: ids})
|
||||
collect_ids(anilist_ids, "anilist")
|
||||
collect_ids(anidb_ids, "anidb")
|
||||
collect_ids(mal_ids, "myanimelist")
|
||||
converted_ids = []
|
||||
unconverted_ids = []
|
||||
unconverted_id_sets = []
|
||||
|
||||
for anime_dict in all_ids:
|
||||
if self.config.Cache:
|
||||
for id_type, anime_id in anime_dict.items():
|
||||
query_ids, expired = self.config.Cache.query_anime_map(anime_id, id_type)
|
||||
if query_ids and not expired:
|
||||
converted_ids.append(query_ids)
|
||||
else:
|
||||
unconverted_ids.append({id_type: anime_id})
|
||||
if len(unconverted_ids) == 100:
|
||||
unconverted_id_sets.append(unconverted_ids)
|
||||
unconverted_ids = []
|
||||
else:
|
||||
unconverted_ids.append(anime_dict)
|
||||
if len(unconverted_ids) == 100:
|
||||
unconverted_id_sets.append(unconverted_ids)
|
||||
unconverted_ids = []
|
||||
for unconverted_id_set in unconverted_id_sets:
|
||||
for anime_ids in self._request(unconverted_id_set):
|
||||
if anime_ids:
|
||||
if self.config.Cache:
|
||||
self.config.Cache.update_anime_map(False, anime_ids)
|
||||
converted_ids.append(anime_ids)
|
||||
return converted_ids
|
||||
|
||||
def anidb_to_ids(self, anidb_list):
|
||||
show_ids = []
|
||||
movie_ids = []
|
||||
for anidb_id in anidb_list:
|
||||
imdb_ids = self.anidb_to_imdb(anidb_id)
|
||||
tmdb_ids = []
|
||||
if imdb_ids:
|
||||
for imdb_id in imdb_ids:
|
||||
tmdb_id = self.imdb_to_tmdb(imdb_id)
|
||||
if tmdb_id:
|
||||
tmdb_ids.append(tmdb_id)
|
||||
tvdb_id = self.anidb_to_tvdb(anidb_id)
|
||||
if tvdb_id:
|
||||
show_ids.append(tvdb_id)
|
||||
if tmdb_ids:
|
||||
movie_ids.extend(tmdb_ids)
|
||||
if not tvdb_id and not tmdb_ids:
|
||||
logger.error(f"Convert Error: No TVDb ID or IMDb ID found for AniDB ID: {anidb_id}")
|
||||
return movie_ids, show_ids
|
||||
|
||||
def anilist_to_ids(self, anilist_ids):
|
||||
anidb_ids = []
|
||||
for id_set in self._arms_ids(anilist_ids=anilist_ids):
|
||||
if id_set["anidb"] is not None:
|
||||
anidb_ids.append(id_set["anidb"])
|
||||
else:
|
||||
logger.error(f"Convert Error: AniDB ID not found for AniList ID: {id_set['anilist']}")
|
||||
return self.anidb_to_ids(anidb_ids)
|
||||
|
||||
def myanimelist_to_ids(self, mal_ids):
|
||||
anidb_ids = []
|
||||
for id_set in self._arms_ids(mal_ids=mal_ids):
|
||||
if id_set["anidb"] is not None:
|
||||
anidb_ids.append(id_set["anidb"])
|
||||
else:
|
||||
logger.error(f"Convert Error: AniDB ID not found for MyAnimeList ID: {id_set['myanimelist']}")
|
||||
return self.anidb_to_ids(anidb_ids)
|
||||
|
||||
def anidb_to_tvdb(self, anidb_id, fail=False):
|
||||
return self._anidb(anidb_id, "tvdbid", fail=fail)
|
||||
|
||||
def anidb_to_imdb(self, anidb_id, fail=False):
|
||||
return self._anidb(anidb_id, "imdbid", fail=fail)
|
||||
|
||||
def tmdb_to_imdb(self, tmdb_id, is_movie=True, fail=False):
|
||||
media_type = "movie" if is_movie else "show"
|
||||
expired = False
|
||||
if self.config.Cache and is_movie:
|
||||
cache_id, expired = self.config.Cache.query_imdb_to_tmdb_map(media_type, tmdb_id, imdb=False)
|
||||
if cache_id and not expired:
|
||||
return cache_id
|
||||
imdb_id = None
|
||||
try:
|
||||
imdb_id = self.config.TMDb.convert_from(tmdb_id, "imdb_id", is_movie)
|
||||
except Failed:
|
||||
if self.config.Trakt:
|
||||
try:
|
||||
imdb_id = self.config.Trakt.convert(tmdb_id, "tmdb", "imdb", "movie" if is_movie else "show")
|
||||
except Failed:
|
||||
pass
|
||||
if fail and imdb_id is None:
|
||||
raise Failed(f"Convert Error: No IMDb ID Found for TMDb ID: {tmdb_id}")
|
||||
if self.config.Cache and imdb_id:
|
||||
self.config.Cache.update_imdb_to_tmdb_map(media_type, expired, imdb_id, tmdb_id)
|
||||
return imdb_id
|
||||
|
||||
def imdb_to_tmdb(self, imdb_id, is_movie=True, fail=False):
|
||||
media_type = "movie" if is_movie else "show"
|
||||
expired = False
|
||||
if self.config.Cache and is_movie:
|
||||
cache_id, expired = self.config.Cache.query_imdb_to_tmdb_map(media_type, imdb_id, imdb=True)
|
||||
if cache_id and not expired:
|
||||
return cache_id
|
||||
tmdb_id = None
|
||||
try:
|
||||
tmdb_id = self.config.TMDb.convert_to(imdb_id, "imdb_id", is_movie)
|
||||
except Failed:
|
||||
if self.config.Trakt:
|
||||
try:
|
||||
tmdb_id = self.config.Trakt.convert(imdb_id, "imdb", "tmdb", media_type)
|
||||
except Failed:
|
||||
pass
|
||||
if fail and tmdb_id is None:
|
||||
raise Failed(f"Convert Error: No TMDb ID Found for IMDb ID: {imdb_id}")
|
||||
if self.config.Cache and tmdb_id:
|
||||
self.config.Cache.update_imdb_to_tmdb_map(media_type, expired, imdb_id, tmdb_id)
|
||||
return tmdb_id
|
||||
|
||||
def tmdb_to_tvdb(self, tmdb_id, fail=False):
|
||||
expired = False
|
||||
if self.config.Cache:
|
||||
cache_id, expired = self.config.Cache.query_tmdb_to_tvdb_map(tmdb_id, tmdb=True)
|
||||
if cache_id and not expired:
|
||||
return cache_id
|
||||
tvdb_id = None
|
||||
try:
|
||||
tvdb_id = self.config.TMDb.convert_from(tmdb_id, "tvdb_id", False)
|
||||
except Failed:
|
||||
if self.config.Trakt:
|
||||
try:
|
||||
tvdb_id = self.config.Trakt.convert(tmdb_id, "tmdb", "tvdb", "show")
|
||||
except Failed:
|
||||
pass
|
||||
if fail and tvdb_id is None:
|
||||
raise Failed(f"Convert Error: No TVDb ID Found for TMDb ID: {tmdb_id}")
|
||||
if self.config.Cache and tvdb_id:
|
||||
self.config.Cache.update_tmdb_to_tvdb_map(expired, tmdb_id, tvdb_id)
|
||||
return tvdb_id
|
||||
|
||||
def tvdb_to_tmdb(self, tvdb_id, fail=False):
|
||||
expired = False
|
||||
if self.config.Cache:
|
||||
cache_id, expired = self.config.Cache.query_tmdb_to_tvdb_map(tvdb_id, tmdb=False)
|
||||
if cache_id and not expired:
|
||||
return cache_id
|
||||
tmdb_id = None
|
||||
try:
|
||||
tmdb_id = self.config.TMDb.convert_to(tvdb_id, "tvdb_id", False)
|
||||
except Failed:
|
||||
if self.config.Trakt:
|
||||
try:
|
||||
tmdb_id = self.config.Trakt.convert(tvdb_id, "tvdb", "tmdb", "show")
|
||||
except Failed:
|
||||
pass
|
||||
if fail and tmdb_id is None:
|
||||
raise Failed(f"Convert Error: No TMDb ID Found for TVDb ID: {tvdb_id}")
|
||||
if self.config.Cache and tmdb_id:
|
||||
self.config.Cache.update_tmdb_to_tvdb_map(expired, tmdb_id, tvdb_id)
|
||||
return tmdb_id
|
||||
|
||||
def tvdb_to_imdb(self, tvdb_id, fail=False):
|
||||
expired = False
|
||||
if self.config.Cache:
|
||||
cache_id, expired = self.config.Cache.query_imdb_to_tvdb_map(tvdb_id, imdb=False)
|
||||
if cache_id and not expired:
|
||||
return cache_id
|
||||
imdb_id = None
|
||||
try:
|
||||
imdb_id = self.tmdb_to_imdb(self.tvdb_to_tmdb(tvdb_id), False)
|
||||
except Failed:
|
||||
if self.config.Trakt:
|
||||
try:
|
||||
imdb_id = self.config.Trakt.convert(tvdb_id, "tvdb", "imdb", "show")
|
||||
except Failed:
|
||||
pass
|
||||
if fail and imdb_id is None:
|
||||
raise Failed(f"Convert Error: No IMDb ID Found for TVDb ID: {tvdb_id}")
|
||||
if self.config.Cache and imdb_id:
|
||||
self.config.Cache.update_imdb_to_tvdb_map(expired, imdb_id, tvdb_id)
|
||||
return imdb_id
|
||||
|
||||
def imdb_to_tvdb(self, imdb_id, fail=False):
|
||||
expired = False
|
||||
if self.config.Cache:
|
||||
cache_id, expired = self.config.Cache.query_imdb_to_tvdb_map(imdb_id, imdb=True)
|
||||
if cache_id and not expired:
|
||||
return cache_id
|
||||
tvdb_id = None
|
||||
try:
|
||||
tvdb_id = self.tmdb_to_tvdb(self.imdb_to_tmdb(imdb_id, False))
|
||||
except Failed:
|
||||
if self.config.Trakt:
|
||||
try:
|
||||
tvdb_id = self.config.Trakt.convert(imdb_id, "imdb", "tvdb", "show")
|
||||
except Failed:
|
||||
pass
|
||||
if fail and tvdb_id is None:
|
||||
raise Failed(f"Convert Error: No TVDb ID Found for IMDb ID: {imdb_id}")
|
||||
if self.config.Cache and tvdb_id:
|
||||
self.config.Cache.update_imdb_to_tvdb_map(expired, imdb_id, tvdb_id)
|
||||
return tvdb_id
|
||||
|
||||
def get_id(self, item, library, length):
|
||||
expired = None
|
||||
if self.config.Cache:
|
||||
cache_id, media_type, expired = self.config.Cache.query_guid_map(item.guid)
|
||||
if cache_id and not expired:
|
||||
media_id_type = "movie" if "movie" in media_type else "show"
|
||||
return media_id_type, util.get_list(cache_id, int_list=True)
|
||||
try:
|
||||
tmdb_id = None
|
||||
imdb_id = None
|
||||
tvdb_id = None
|
||||
anidb_id = None
|
||||
guid = requests.utils.urlparse(item.guid)
|
||||
item_type = guid.scheme.split(".")[-1]
|
||||
check_id = guid.netloc
|
||||
|
||||
if item_type == "plex":
|
||||
tmdb_id = []
|
||||
imdb_id = []
|
||||
tvdb_id = []
|
||||
try:
|
||||
for guid_tag in library.get_guids(item):
|
||||
url_parsed = requests.utils.urlparse(guid_tag.id)
|
||||
if url_parsed.scheme == "tvdb": tvdb_id.append(int(url_parsed.netloc))
|
||||
elif url_parsed.scheme == "imdb": imdb_id.append(url_parsed.netloc)
|
||||
elif url_parsed.scheme == "tmdb": tmdb_id.append(int(url_parsed.netloc))
|
||||
except requests.exceptions.ConnectionError:
|
||||
util.print_stacktrace()
|
||||
raise Failed("No External GUIDs found")
|
||||
elif item_type == "imdb": imdb_id = check_id
|
||||
elif item_type == "thetvdb": tvdb_id = int(check_id)
|
||||
elif item_type == "themoviedb": tmdb_id = int(check_id)
|
||||
elif item_type == "hama":
|
||||
if check_id.startswith("tvdb"): tvdb_id = int(re.search("-(.*)", check_id).group(1))
|
||||
elif check_id.startswith("anidb"): anidb_id = re.search("-(.*)", check_id).group(1)
|
||||
else: raise Failed(f"Hama Agent ID: {check_id} not supported")
|
||||
elif item_type == "myanimelist":
|
||||
anime_ids = self._arms_ids(mal_ids=check_id)
|
||||
if anime_ids[0] and anime_ids[0]["anidb"]: anidb_id = anime_ids[0]["anidb"]
|
||||
else: raise Failed(f"Unable to convert MyAnimeList ID: {check_id} to AniDB ID")
|
||||
elif item_type == "local": raise Failed("No match in Plex")
|
||||
else: raise Failed(f"Agent {item_type} not supported")
|
||||
|
||||
if anidb_id:
|
||||
tvdb_id = self.anidb_to_tvdb(anidb_id)
|
||||
if not tvdb_id:
|
||||
imdb_id = self.anidb_to_imdb(anidb_id)
|
||||
if not imdb_id and not tvdb_id:
|
||||
raise Failed(f"Unable to convert AniDB ID: {anidb_id} to TVDb ID or IMDb ID")
|
||||
|
||||
if not tmdb_id and imdb_id:
|
||||
if isinstance(imdb_id, list):
|
||||
tmdb_id = []
|
||||
for imdb in imdb_id:
|
||||
try:
|
||||
tmdb_id.append(self.imdb_to_tmdb(imdb, fail=True))
|
||||
except Failed:
|
||||
continue
|
||||
else:
|
||||
tmdb_id = self.imdb_to_tmdb(imdb_id)
|
||||
if not tmdb_id:
|
||||
raise Failed(f"Unable to convert IMDb ID: {util.compile_list(imdb_id)} to TMDb ID")
|
||||
if not anidb_id and not tvdb_id and tmdb_id and library.is_show:
|
||||
if isinstance(tmdb_id, list):
|
||||
tvdb_id = []
|
||||
for tmdb in tmdb_id:
|
||||
try:
|
||||
tvdb_id.append(self.tmdb_to_tvdb(tmdb, fail=True))
|
||||
except Failed:
|
||||
continue
|
||||
else:
|
||||
tvdb_id = self.tmdb_to_tvdb(tmdb_id)
|
||||
if not tvdb_id:
|
||||
raise Failed(f"Unable to convert TMDb ID: {util.compile_list(tmdb_id)} to TVDb ID")
|
||||
|
||||
if tvdb_id:
|
||||
if isinstance(tvdb_id, list):
|
||||
new_tvdb_id = []
|
||||
for tvdb in tvdb_id:
|
||||
try:
|
||||
new_tvdb_id.append(int(tvdb))
|
||||
except ValueError:
|
||||
continue
|
||||
tvdb_id = new_tvdb_id
|
||||
else:
|
||||
try:
|
||||
tvdb_id = int(tvdb_id)
|
||||
except ValueError:
|
||||
tvdb_id = None
|
||||
|
||||
def update_cache(cache_ids, id_type, guid_type):
|
||||
if self.config.Cache:
|
||||
cache_ids = util.compile_list(cache_ids)
|
||||
util.print_end(length, f" Cache | {'^' if expired else '+'} | {item.guid:<46} | {id_type} ID: {cache_ids:<6} | {item.title}")
|
||||
self.config.Cache.update_guid_map(guid_type, item.guid, cache_ids, expired)
|
||||
|
||||
if tmdb_id and library.is_movie:
|
||||
update_cache(tmdb_id, "TMDb", "movie")
|
||||
return "movie", tmdb_id
|
||||
elif tvdb_id and library.is_show:
|
||||
update_cache(tvdb_id, "TVDb", "show")
|
||||
return "show", tvdb_id
|
||||
elif anidb_id and tmdb_id and library.is_show:
|
||||
update_cache(tmdb_id, "TMDb", "show_movie")
|
||||
return "movie", tmdb_id
|
||||
else:
|
||||
raise Failed(f"No ID to convert")
|
||||
|
||||
except Failed as e:
|
||||
util.print_end(length, f"Mapping Error | {item.guid:<46} | {e} for {item.title}")
|
||||
return None, None
|
@ -0,0 +1,379 @@
|
||||
import logging, os, re, requests
|
||||
from datetime import datetime
|
||||
from modules import plex, util
|
||||
from modules.util import Failed
|
||||
from plexapi.exceptions import NotFound
|
||||
from ruamel import yaml
|
||||
|
||||
logger = logging.getLogger("Plex Meta Manager")
|
||||
|
||||
class Metadata:
|
||||
def __init__(self, library, file_type, path):
|
||||
self.library = library
|
||||
self.type = file_type
|
||||
self.path = path
|
||||
self.github_base = "https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Configs/master/"
|
||||
logger.info("")
|
||||
logger.info(f"Loading Metadata {file_type}: {path}")
|
||||
def get_dict(attribute, attr_data, check_list=None):
|
||||
if attribute in attr_data:
|
||||
if attr_data[attribute]:
|
||||
if isinstance(attr_data[attribute], dict):
|
||||
if check_list:
|
||||
new_dict = {}
|
||||
for a_name, a_data in attr_data[attribute].items():
|
||||
if a_name in check_list:
|
||||
logger.error(f"Config Warning: Skipping duplicate {attribute[:-1] if attribute[-1] == 's' else attribute}: {a_name}")
|
||||
else:
|
||||
new_dict[a_name] = a_data
|
||||
return new_dict
|
||||
else:
|
||||
return attr_data[attribute]
|
||||
else:
|
||||
logger.warning(f"Config Warning: {attribute} must be a dictionary")
|
||||
else:
|
||||
logger.warning(f"Config Warning: {attribute} attribute is blank")
|
||||
return None
|
||||
try:
|
||||
if file_type in ["URL", "Git"]:
|
||||
content_path = path if file_type == "URL" else f"{self.github_base}{path}.yml"
|
||||
response = requests.get(content_path)
|
||||
if response.status_code >= 400:
|
||||
raise Failed(f"URL Error: No file found at {content_path}")
|
||||
content = response.content
|
||||
elif os.path.exists(os.path.abspath(path)):
|
||||
content = open(path, encoding="utf-8")
|
||||
else:
|
||||
raise Failed(f"File Error: File does not exist {path}")
|
||||
data, ind, bsi = yaml.util.load_yaml_guess_indent(content)
|
||||
self.metadata = get_dict("metadata", data, library.metadatas)
|
||||
self.templates = get_dict("templates", data)
|
||||
self.collections = get_dict("collections", data, library.collections)
|
||||
|
||||
if self.metadata is None and self.collections is None:
|
||||
raise Failed("YAML Error: metadata or collections attribute is required")
|
||||
logger.info(f"Metadata File Loaded Successfully")
|
||||
except yaml.scanner.ScannerError as ye:
|
||||
raise Failed(f"YAML Error: {util.tab_new_lines(ye)}")
|
||||
except Exception as e:
|
||||
util.print_stacktrace()
|
||||
raise Failed(f"YAML Error: {e}")
|
||||
|
||||
def get_collections(self, requested_collections):
|
||||
if requested_collections:
|
||||
return {c: self.collections[c] for c in util.get_list(requested_collections) if c in self.collections}
|
||||
else:
|
||||
return self.collections
|
||||
|
||||
def update_metadata(self, TMDb, test):
|
||||
logger.info("")
|
||||
util.separator(f"Running Metadata")
|
||||
logger.info("")
|
||||
if not self.metadata:
|
||||
raise Failed("No metadata to edit")
|
||||
for mapping_name, meta in self.metadata.items():
|
||||
methods = {mm.lower(): mm for mm in meta}
|
||||
if test and ("test" not in methods or meta[methods["test"]] is not True):
|
||||
continue
|
||||
|
||||
updated = False
|
||||
edits = {}
|
||||
advance_edits = {}
|
||||
|
||||
def add_edit(name, current, group, alias, key=None, value=None, var_type="str"):
|
||||
if value or name in alias:
|
||||
if value or group[alias[name]]:
|
||||
if key is None: key = name
|
||||
if value is None: value = group[alias[name]]
|
||||
try:
|
||||
if var_type == "date":
|
||||
final_value = util.check_date(value, name, return_string=True, plex_date=True)
|
||||
elif var_type == "float":
|
||||
final_value = util.check_number(value, name, number_type="float", minimum=0, maximum=10)
|
||||
else:
|
||||
final_value = value
|
||||
if str(current) != str(final_value):
|
||||
edits[f"{key}.value"] = final_value
|
||||
edits[f"{key}.locked"] = 1
|
||||
logger.info(f"Detail: {name} updated to {final_value}")
|
||||
except Failed as ee:
|
||||
logger.error(ee)
|
||||
else:
|
||||
logger.error(f"Metadata Error: {name} attribute is blank")
|
||||
|
||||
def add_advanced_edit(attr, obj, group, alias, show_library=False, new_agent=False):
|
||||
key, options = plex.advance_keys[attr]
|
||||
if attr in alias:
|
||||
if new_agent and self.library.agent not in plex.new_plex_agents:
|
||||
logger.error(f"Metadata Error: {attr} attribute only works for with the New Plex Movie Agent and New Plex TV Agent")
|
||||
elif show_library and not self.library.is_show:
|
||||
logger.error(f"Metadata Error: {attr} attribute only works for show libraries")
|
||||
elif group[alias[attr]]:
|
||||
method_data = str(group[alias[attr]]).lower()
|
||||
if method_data not in options:
|
||||
logger.error(f"Metadata Error: {group[alias[attr]]} {attr} attribute invalid")
|
||||
elif getattr(obj, key) != options[method_data]:
|
||||
advance_edits[key] = options[method_data]
|
||||
logger.info(f"Detail: {attr} updated to {method_data}")
|
||||
else:
|
||||
logger.error(f"Metadata Error: {attr} attribute is blank")
|
||||
|
||||
def edit_tags(attr, obj, group, alias, key=None, extra=None, movie_library=False):
|
||||
if key is None:
|
||||
key = f"{attr}s"
|
||||
if attr in alias and f"{attr}.sync" in alias:
|
||||
logger.error(f"Metadata Error: Cannot use {attr} and {attr}.sync together")
|
||||
elif attr in alias or f"{attr}.sync" in alias:
|
||||
attr_key = attr if attr in alias else f"{attr}.sync"
|
||||
if movie_library and not self.library.is_movie:
|
||||
logger.error(f"Metadata Error: {attr_key} attribute only works for movie libraries")
|
||||
elif group[alias[attr_key]] or extra:
|
||||
item_tags = [item_tag.tag for item_tag in getattr(obj, key)]
|
||||
input_tags = []
|
||||
if group[alias[attr_key]]:
|
||||
input_tags.extend(util.get_list(group[alias[attr_key]]))
|
||||
if extra:
|
||||
input_tags.extend(extra)
|
||||
if f"{attr}.sync" in alias:
|
||||
remove_method = getattr(obj, f"remove{attr.capitalize()}")
|
||||
for tag in (t for t in item_tags if t not in input_tags):
|
||||
updated = True
|
||||
remove_method(tag)
|
||||
logger.info(f"Detail: {attr.capitalize()} {tag} removed")
|
||||
add_method = getattr(obj, f"add{attr.capitalize()}")
|
||||
for tag in (t for t in input_tags if t not in item_tags):
|
||||
updated = True
|
||||
add_method(tag)
|
||||
logger.info(f"Detail: {attr.capitalize()} {tag} added")
|
||||
else:
|
||||
logger.error(f"Metadata Error: {attr} attribute is blank")
|
||||
|
||||
def set_image(attr, obj, group, alias, poster=True, url=True):
|
||||
if group[alias[attr]]:
|
||||
message = f"{'poster' if poster else 'background'} to [{'URL' if url else 'File'}] {group[alias[attr]]}"
|
||||
self.library.upload_image(obj, group[alias[attr]], poster=poster, url=url)
|
||||
logger.info(f"Detail: {attr} updated {message}")
|
||||
else:
|
||||
logger.error(f"Metadata Error: {attr} attribute is blank")
|
||||
|
||||
def set_images(obj, group, alias):
|
||||
if "url_poster" in alias:
|
||||
set_image("url_poster", obj, group, alias)
|
||||
elif "file_poster" in alias:
|
||||
set_image("file_poster", obj, group, alias, url=False)
|
||||
if "url_background" in alias:
|
||||
set_image("url_background", obj, group, alias, poster=False)
|
||||
elif "file_background" in alias:
|
||||
set_image("file_background", obj, group, alias, poster=False, url=False)
|
||||
|
||||
logger.info("")
|
||||
util.separator()
|
||||
logger.info("")
|
||||
year = None
|
||||
if "year" in methods:
|
||||
year = util.check_number(meta[methods["year"]], "year", minimum=1800, maximum=datetime.now().year + 1)
|
||||
|
||||
title = mapping_name
|
||||
if "title" in methods:
|
||||
if meta[methods["title"]] is None:
|
||||
logger.error("Metadata Error: title attribute is blank")
|
||||
else:
|
||||
title = meta[methods["title"]]
|
||||
|
||||
item = self.library.search_item(title, year=year)
|
||||
|
||||
if item is None:
|
||||
item = self.library.search_item(f"{title} (SUB)", year=year)
|
||||
|
||||
if item is None and "alt_title" in methods:
|
||||
if meta[methods["alt_title"]] is None:
|
||||
logger.error("Metadata Error: alt_title attribute is blank")
|
||||
else:
|
||||
alt_title = meta["alt_title"]
|
||||
item = self.library.search_item(alt_title, year=year)
|
||||
|
||||
if item is None:
|
||||
logger.error(f"Plex Error: Item {mapping_name} not found")
|
||||
logger.error(f"Skipping {mapping_name}")
|
||||
continue
|
||||
|
||||
item_type = "Movie" if self.library.is_movie else "Show"
|
||||
logger.info(f"Updating {item_type}: {title}...")
|
||||
|
||||
tmdb_item = None
|
||||
tmdb_is_movie = None
|
||||
if ("tmdb_show" in methods or "tmdb_id" in methods) and "tmdb_movie" in methods:
|
||||
logger.error("Metadata Error: Cannot use tmdb_movie and tmdb_show when editing the same metadata item")
|
||||
|
||||
if "tmdb_show" in methods or "tmdb_id" in methods or "tmdb_movie" in methods:
|
||||
try:
|
||||
if "tmdb_show" in methods or "tmdb_id" in methods:
|
||||
data = meta[methods["tmdb_show" if "tmdb_show" in methods else "tmdb_id"]]
|
||||
if data is None:
|
||||
logger.error("Metadata Error: tmdb_show attribute is blank")
|
||||
else:
|
||||
tmdb_is_movie = False
|
||||
tmdb_item = TMDb.get_show(util.regex_first_int(data, "Show"))
|
||||
elif "tmdb_movie" in methods:
|
||||
if meta[methods["tmdb_movie"]] is None:
|
||||
logger.error("Metadata Error: tmdb_movie attribute is blank")
|
||||
else:
|
||||
tmdb_is_movie = True
|
||||
tmdb_item = TMDb.get_movie(util.regex_first_int(meta[methods["tmdb_movie"]], "Movie"))
|
||||
except Failed as e:
|
||||
logger.error(e)
|
||||
|
||||
originally_available = None
|
||||
original_title = None
|
||||
rating = None
|
||||
studio = None
|
||||
tagline = None
|
||||
summary = None
|
||||
genres = []
|
||||
if tmdb_item:
|
||||
originally_available = tmdb_item.release_date if tmdb_is_movie else tmdb_item.first_air_date
|
||||
if tmdb_item and tmdb_is_movie is True and tmdb_item.original_title != tmdb_item.title:
|
||||
original_title = tmdb_item.original_title
|
||||
elif tmdb_item and tmdb_is_movie is False and tmdb_item.original_name != tmdb_item.name:
|
||||
original_title = tmdb_item.original_name
|
||||
rating = tmdb_item.vote_average
|
||||
if tmdb_is_movie is True and tmdb_item.production_companies:
|
||||
studio = tmdb_item.production_companies[0].name
|
||||
elif tmdb_is_movie is False and tmdb_item.networks:
|
||||
studio = tmdb_item.networks[0].name
|
||||
tagline = tmdb_item.tagline if len(tmdb_item.tagline) > 0 else None
|
||||
summary = tmdb_item.overview
|
||||
genres = [genre.name for genre in tmdb_item.genres]
|
||||
|
||||
edits = {}
|
||||
add_edit("title", item.title, meta, methods, value=title)
|
||||
add_edit("sort_title", item.titleSort, meta, methods, key="titleSort")
|
||||
add_edit("originally_available", str(item.originallyAvailableAt)[:-9], meta, methods,
|
||||
key="originallyAvailableAt", value=originally_available, var_type="date")
|
||||
add_edit("critic_rating", item.rating, meta, methods, value=rating, key="rating", var_type="float")
|
||||
add_edit("audience_rating", item.audienceRating, meta, methods, key="audienceRating", var_type="float")
|
||||
add_edit("content_rating", item.contentRating, meta, methods, key="contentRating")
|
||||
add_edit("original_title", item.originalTitle, meta, methods, key="originalTitle", value=original_title)
|
||||
add_edit("studio", item.studio, meta, methods, value=studio)
|
||||
add_edit("tagline", item.tagline, meta, methods, value=tagline)
|
||||
add_edit("summary", item.summary, meta, methods, value=summary)
|
||||
self.library.edit_item(item, mapping_name, item_type, edits)
|
||||
|
||||
advance_edits = {}
|
||||
add_advanced_edit("episode_sorting", item, meta, methods, show_library=True)
|
||||
add_advanced_edit("keep_episodes", item, meta, methods, show_library=True)
|
||||
add_advanced_edit("delete_episodes", item, meta, methods, show_library=True)
|
||||
add_advanced_edit("season_display", item, meta, methods, show_library=True)
|
||||
add_advanced_edit("episode_ordering", item, meta, methods, show_library=True)
|
||||
add_advanced_edit("metadata_language", item, meta, methods, new_agent=True)
|
||||
add_advanced_edit("use_original_title", item, meta, methods, new_agent=True)
|
||||
self.library.edit_item(item, mapping_name, item_type, advance_edits, advanced=True)
|
||||
|
||||
edit_tags("genre", item, meta, methods, extra=genres)
|
||||
edit_tags("label", item, meta, methods)
|
||||
edit_tags("collection", item, meta, methods)
|
||||
edit_tags("country", item, meta, methods, key="countries", movie_library=True)
|
||||
edit_tags("director", item, meta, methods, movie_library=True)
|
||||
edit_tags("producer", item, meta, methods, movie_library=True)
|
||||
edit_tags("writer", item, meta, methods, movie_library=True)
|
||||
|
||||
logger.info(f"{item_type}: {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}")
|
||||
|
||||
set_images(item, meta, methods)
|
||||
|
||||
if "seasons" in methods and self.library.is_show:
|
||||
if meta[methods["seasons"]]:
|
||||
for season_id in meta[methods["seasons"]]:
|
||||
updated = False
|
||||
logger.info("")
|
||||
logger.info(f"Updating season {season_id} of {mapping_name}...")
|
||||
if isinstance(season_id, int):
|
||||
season = None
|
||||
for s in item.seasons():
|
||||
if s.index == season_id:
|
||||
season = s
|
||||
break
|
||||
if season is None:
|
||||
logger.error(f"Metadata Error: Season: {season_id} not found")
|
||||
else:
|
||||
season_dict = meta[methods["seasons"]][season_id]
|
||||
season_methods = {sm.lower(): sm for sm in season_dict}
|
||||
|
||||
if "title" in season_methods and season_dict[season_methods["title"]]:
|
||||
title = season_dict[season_methods["title"]]
|
||||
else:
|
||||
title = season.title
|
||||
if "sub" in season_methods:
|
||||
if season_dict[season_methods["sub"]] is None:
|
||||
logger.error("Metadata Error: sub attribute is blank")
|
||||
elif season_dict[season_methods["sub"]] is True and "(SUB)" not in title:
|
||||
title = f"{title} (SUB)"
|
||||
elif season_dict[season_methods["sub"]] is False and title.endswith(" (SUB)"):
|
||||
title = title[:-6]
|
||||
else:
|
||||
logger.error("Metadata Error: sub attribute must be True or False")
|
||||
|
||||
edits = {}
|
||||
add_edit("title", season.title, season_dict, season_methods, value=title)
|
||||
add_edit("summary", season.summary, season_dict, season_methods)
|
||||
self.library.edit_item(season, season_id, "Season", edits)
|
||||
set_images(season, season_dict, season_methods)
|
||||
else:
|
||||
logger.error(f"Metadata Error: Season: {season_id} invalid, it must be an integer")
|
||||
logger.info(f"Season {season_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}")
|
||||
else:
|
||||
logger.error("Metadata Error: seasons attribute is blank")
|
||||
elif "seasons" in methods:
|
||||
logger.error("Metadata Error: seasons attribute only works for show libraries")
|
||||
|
||||
if "episodes" in methods and self.library.is_show:
|
||||
if meta[methods["episodes"]]:
|
||||
for episode_str in meta[methods["episodes"]]:
|
||||
updated = False
|
||||
logger.info("")
|
||||
match = re.search("[Ss]\\d+[Ee]\\d+", episode_str)
|
||||
if match:
|
||||
output = match.group(0)[1:].split("E" if "E" in match.group(0) else "e")
|
||||
season_id = int(output[0])
|
||||
episode_id = int(output[1])
|
||||
logger.info(f"Updating episode S{season_id}E{episode_id} of {mapping_name}...")
|
||||
try:
|
||||
episode = item.episode(season=season_id, episode=episode_id)
|
||||
except NotFound:
|
||||
logger.error(f"Metadata Error: episode {episode_id} of season {season_id} not found")
|
||||
else:
|
||||
episode_dict = meta[methods["episodes"]][episode_str]
|
||||
episode_methods = {em.lower(): em for em in episode_dict}
|
||||
|
||||
if "title" in episode_methods and episode_dict[episode_methods["title"]]:
|
||||
title = episode_dict[episode_methods["title"]]
|
||||
else:
|
||||
title = episode.title
|
||||
if "sub" in episode_dict:
|
||||
if episode_dict[episode_methods["sub"]] is None:
|
||||
logger.error("Metadata Error: sub attribute is blank")
|
||||
elif episode_dict[episode_methods["sub"]] is True and "(SUB)" not in title:
|
||||
title = f"{title} (SUB)"
|
||||
elif episode_dict[episode_methods["sub"]] is False and title.endswith(" (SUB)"):
|
||||
title = title[:-6]
|
||||
else:
|
||||
logger.error("Metadata Error: sub attribute must be True or False")
|
||||
edits = {}
|
||||
add_edit("title", episode.title, episode_dict, episode_methods, value=title)
|
||||
add_edit("sort_title", episode.titleSort, episode_dict, episode_methods,
|
||||
key="titleSort")
|
||||
add_edit("rating", episode.rating, episode_dict, episode_methods)
|
||||
add_edit("originally_available", str(episode.originallyAvailableAt)[:-9],
|
||||
episode_dict, episode_methods, key="originallyAvailableAt")
|
||||
add_edit("summary", episode.summary, episode_dict, episode_methods)
|
||||
self.library.edit_item(episode, f"{season_id} Episode: {episode_id}", "Season", edits)
|
||||
edit_tags("director", episode, episode_dict, episode_methods)
|
||||
edit_tags("writer", episode, episode_dict, episode_methods)
|
||||
set_images(episode, episode_dict, episode_methods)
|
||||
logger.info(f"Episode S{episode_id}E{season_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}")
|
||||
else:
|
||||
logger.error(f"Metadata Error: episode {episode_str} invalid must have S##E## format")
|
||||
else:
|
||||
logger.error("Metadata Error: episodes attribute is blank")
|
||||
elif "episodes" in methods:
|
||||
logger.error("Metadata Error: episodes attribute only works for show libraries")
|
File diff suppressed because it is too large
Load Diff
@ -1,346 +0,0 @@
|
||||
import logging
|
||||
from modules import util
|
||||
from modules.config import Config
|
||||
from modules.util import Failed
|
||||
|
||||
logger = logging.getLogger("Plex Meta Manager")
|
||||
|
||||
def run_tests(default_dir):
|
||||
try:
|
||||
config = Config(default_dir)
|
||||
logger.info("")
|
||||
util.separator("Mapping Tests")
|
||||
for library in config.libraries:
|
||||
config.map_guids(library)
|
||||
anidb_tests(config)
|
||||
imdb_tests(config)
|
||||
mal_tests(config)
|
||||
tautulli_tests(config)
|
||||
tmdb_tests(config)
|
||||
trakt_tests(config)
|
||||
tvdb_tests(config)
|
||||
util.separator("Finished All Plex Meta Manager Tests")
|
||||
except KeyboardInterrupt:
|
||||
util.separator("Canceled Plex Meta Manager Tests")
|
||||
|
||||
def anidb_tests(config):
|
||||
if config.AniDB:
|
||||
util.separator("AniDB Tests")
|
||||
|
||||
try:
|
||||
config.AniDB.get_items("anidb_id", 69, "en", status_message=False)
|
||||
logger.info("Success | Get AniDB ID")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get AniDB ID: {e}")
|
||||
|
||||
try:
|
||||
config.AniDB.get_items("anidb_relation", 69, "en", status_message=False)
|
||||
logger.info("Success | Get AniDB Relation")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get AniDB Relation: {e}")
|
||||
|
||||
try:
|
||||
config.AniDB.get_items("anidb_popular", 30, "en", status_message=False)
|
||||
logger.info("Success | Get AniDB Popular")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get AniDB Popular: {e}")
|
||||
|
||||
try:
|
||||
config.AniDB.validate_anidb_list(["69", "112"], "en")
|
||||
logger.info("Success | Validate AniDB List")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Validate AniDB List: {e}")
|
||||
|
||||
else:
|
||||
util.separator("AniDB Not Configured")
|
||||
|
||||
def imdb_tests(config):
|
||||
if config.IMDb:
|
||||
util.separator("IMDb Tests")
|
||||
|
||||
tmdb_ids, tvdb_ids = config.IMDb.get_items("imdb_list", {"url": "https://www.imdb.com/search/title/?groups=top_1000", "limit": 0}, "en", status_message=False)
|
||||
if len(tmdb_ids) == 1000: logger.info("Success | IMDb URL get TMDb IDs")
|
||||
else: logger.error(f"Failure | IMDb URL get TMDb IDs: {len(tmdb_ids)} Should be 1000")
|
||||
|
||||
tmdb_ids, tvdb_ids = config.IMDb.get_items("imdb_list", {"url": "https://www.imdb.com/list/ls026173135/", "limit": 0}, "en", status_message=False)
|
||||
if len(tmdb_ids) == 250: logger.info("Success | IMDb URL get TMDb IDs")
|
||||
else: logger.error(f"Failure | IMDb URL get TMDb IDs: {len(tmdb_ids)} Should be 250")
|
||||
|
||||
tmdb_ids, tvdb_ids = config.IMDb.get_items("imdb_id", "tt0814243", "en", status_message=False)
|
||||
if len(tmdb_ids) == 1: logger.info("Success | IMDb ID get TMDb IDs")
|
||||
else: logger.error(f"Failure | IMDb ID get TMDb IDs: {len(tmdb_ids)} Should be 1")
|
||||
|
||||
else:
|
||||
util.separator("IMDb Not Configured")
|
||||
|
||||
def mal_tests(config):
|
||||
if config.MyAnimeList:
|
||||
util.separator("MyAnimeList Tests")
|
||||
|
||||
mal_list_tests = [
|
||||
("mal_all", 10),
|
||||
("mal_airing", 10),
|
||||
("mal_upcoming", 10),
|
||||
("mal_tv", 10),
|
||||
("mal_movie", 10),
|
||||
("mal_ova", 10),
|
||||
("mal_special", 10),
|
||||
("mal_popular", 10),
|
||||
("mal_favorite", 10),
|
||||
("mal_suggested", 10),
|
||||
("mal_userlist", {"limit": 10, "username": "@me", "status": "completed", "sort_by": "list_score"}),
|
||||
("mal_season", {"limit": 10, "season": "fall", "year": 2020, "sort_by": "anime_score"})
|
||||
]
|
||||
|
||||
for mal_list_test in mal_list_tests:
|
||||
try:
|
||||
config.MyAnimeList.get_items(mal_list_test[0], mal_list_test[1], status_message=False)
|
||||
logger.info(f"Success | Get Anime using {util.pretty_names[mal_list_test[0]]}")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get Anime using {util.pretty_names[mal_list_test[0]]}: {e}")
|
||||
else:
|
||||
util.separator("MyAnimeList Not Configured")
|
||||
|
||||
def tautulli_tests(config):
|
||||
if config.libraries[0].Tautulli:
|
||||
util.separator("Tautulli Tests")
|
||||
|
||||
try:
|
||||
config.libraries[0].Tautulli.get_section_id(config.libraries[0].name)
|
||||
logger.info("Success | Get Section ID")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get Section ID: {e}")
|
||||
|
||||
try:
|
||||
config.libraries[0].Tautulli.get_popular(config.libraries[0], status_message=False)
|
||||
logger.info("Success | Get Popular")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get Popular: {e}")
|
||||
|
||||
try:
|
||||
config.libraries[0].Tautulli.get_top(config.libraries[0], status_message=False)
|
||||
logger.info("Success | Get Top")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get Top: {e}")
|
||||
else:
|
||||
util.separator("Tautulli Not Configured")
|
||||
|
||||
def tmdb_tests(config):
|
||||
if config.TMDb:
|
||||
util.separator("TMDb Tests")
|
||||
|
||||
try:
|
||||
config.TMDb.convert_imdb_to_tmdb("tt0076759")
|
||||
logger.info("Success | Convert IMDb to TMDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert IMDb to TMDb: {e}")
|
||||
|
||||
try:
|
||||
config.TMDb.convert_tmdb_to_imdb(11)
|
||||
logger.info("Success | Convert TMDb to IMDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert TMDb to IMDb: {e}")
|
||||
|
||||
try:
|
||||
config.TMDb.convert_imdb_to_tvdb("tt0458290")
|
||||
logger.info("Success | Convert IMDb to TVDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert IMDb to TVDb: {e}")
|
||||
|
||||
try:
|
||||
config.TMDb.convert_tvdb_to_imdb(83268)
|
||||
logger.info("Success | Convert TVDb to IMDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert TVDb to IMDb: {e}")
|
||||
|
||||
tmdb_list_tests = [
|
||||
([11], "Movie"),
|
||||
([4194], "Show"),
|
||||
([10], "Collection"),
|
||||
([1], "Person"),
|
||||
([1], "Company"),
|
||||
([2739], "Network"),
|
||||
([8136], "List")
|
||||
]
|
||||
|
||||
for tmdb_list_test in tmdb_list_tests:
|
||||
try:
|
||||
config.TMDb.validate_tmdb_list(tmdb_list_test[0], tmdb_type=tmdb_list_test[1])
|
||||
logger.info(f"Success | Get TMDb {tmdb_list_test[1]}")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get TMDb {tmdb_list_test[1]}: {e}")
|
||||
|
||||
tmdb_list_tests = [
|
||||
("tmdb_discover", {"sort_by": "popularity.desc", "limit": 100}, True),
|
||||
("tmdb_discover", {"sort_by": "popularity.desc", "limit": 100}, False),
|
||||
("tmdb_company", 1, True),
|
||||
("tmdb_company", 1, False),
|
||||
("tmdb_network", 2739, False),
|
||||
("tmdb_keyword", 180547, True),
|
||||
("tmdb_keyword", 180547, False),
|
||||
("tmdb_now_playing", 10, True),
|
||||
("tmdb_popular", 10, True),
|
||||
("tmdb_popular", 10, False),
|
||||
("tmdb_top_rated", 10, True),
|
||||
("tmdb_top_rated", 10, False),
|
||||
("tmdb_trending_daily", 10, True),
|
||||
("tmdb_trending_daily", 10, False),
|
||||
("tmdb_trending_weekly", 10, True),
|
||||
("tmdb_trending_weekly", 10, False),
|
||||
("tmdb_list", 7068209, True),
|
||||
("tmdb_list", 7068209, False),
|
||||
("tmdb_movie", 11, True),
|
||||
("tmdb_collection", 10, True),
|
||||
("tmdb_show", 4194, False)
|
||||
]
|
||||
|
||||
for tmdb_list_test in tmdb_list_tests:
|
||||
try:
|
||||
config.TMDb.get_items(tmdb_list_test[0], tmdb_list_test[1], tmdb_list_test[2], status_message=False)
|
||||
logger.info(f"Success | Get {'Movies' if tmdb_list_test[2] else 'Shows'} using {util.pretty_names[tmdb_list_test[0]]}")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get {'Movies' if tmdb_list_test[2] else 'Shows'} using {util.pretty_names[tmdb_list_test[0]]}: {e}")
|
||||
else:
|
||||
util.separator("TMDb Not Configured")
|
||||
|
||||
def trakt_tests(config):
|
||||
if config.Trakt:
|
||||
util.separator("Trakt Tests")
|
||||
|
||||
try:
|
||||
config.Trakt.convert_imdb_to_tmdb("tt0076759")
|
||||
logger.info("Success | Convert IMDb to TMDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert IMDb to TMDb: {e}")
|
||||
|
||||
try:
|
||||
config.Trakt.convert_tmdb_to_imdb(11)
|
||||
logger.info("Success | Convert TMDb to IMDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert TMDb to IMDb: {e}")
|
||||
|
||||
try:
|
||||
config.Trakt.convert_imdb_to_tvdb("tt0458290")
|
||||
logger.info("Success | Convert IMDb to TVDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert IMDb to TVDb: {e}")
|
||||
|
||||
try:
|
||||
config.Trakt.convert_tvdb_to_imdb(83268)
|
||||
logger.info("Success | Convert TVDb to IMDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert TVDb to IMDb: {e}")
|
||||
|
||||
try:
|
||||
config.Trakt.convert_tmdb_to_tvdb(11)
|
||||
logger.info("Success | Convert TMDb to TVDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert TMDb to TVDb: {e}")
|
||||
|
||||
try:
|
||||
config.Trakt.convert_tvdb_to_tmdb(83268)
|
||||
logger.info("Success | Convert TVDb to TMDb")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Convert TVDb to TMDb: {e}")
|
||||
|
||||
try:
|
||||
config.Trakt.validate_trakt_list(["https://trakt.tv/users/movistapp/lists/christmas-movies"])
|
||||
logger.info("Success | Get List")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get List: {e}")
|
||||
|
||||
try:
|
||||
config.Trakt.validate_trakt_watchlist(["me"], True)
|
||||
logger.info("Success | Get Watchlist Movies")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get Watchlist Movies: {e}")
|
||||
|
||||
try:
|
||||
config.Trakt.validate_trakt_watchlist(["me"], False)
|
||||
logger.info("Success | Get Watchlist Shows")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get Watchlist Shows: {e}")
|
||||
|
||||
trakt_list_tests = [
|
||||
("trakt_list", "https://trakt.tv/users/movistapp/lists/christmas-movies", True),
|
||||
("trakt_trending", 10, True),
|
||||
("trakt_trending", 10, False),
|
||||
("trakt_watchlist", "me", True),
|
||||
("trakt_watchlist", "me", False)
|
||||
]
|
||||
|
||||
for trakt_list_test in trakt_list_tests:
|
||||
try:
|
||||
config.Trakt.get_items(trakt_list_test[0], trakt_list_test[1], trakt_list_test[2], status_message=False)
|
||||
logger.info(f"Success | Get {'Movies' if trakt_list_test[2] else 'Shows'} using {util.pretty_names[trakt_list_test[0]]}")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | Get {'Movies' if trakt_list_test[2] else 'Shows'} using {util.pretty_names[trakt_list_test[0]]}: {e}")
|
||||
else:
|
||||
util.separator("Trakt Not Configured")
|
||||
|
||||
def tvdb_tests(config):
|
||||
if config.TVDb:
|
||||
util.separator("TVDb Tests")
|
||||
|
||||
tmdb_ids, tvdb_ids = config.TVDb.get_items("tvdb_list", "https://www.thetvdb.com/lists/arrowverse", "en", status_message=False)
|
||||
if len(tvdb_ids) == 10 and len(tmdb_ids) == 0: logger.info("Success | TVDb URL get TVDb IDs and TMDb IDs")
|
||||
else: logger.error(f"Failure | TVDb URL get TVDb IDs and TMDb IDs: {len(tvdb_ids)} Should be 10 and {len(tmdb_ids)} Should be 0")
|
||||
|
||||
tmdb_ids, tvdb_ids = config.TVDb.get_items("tvdb_list", "https://www.thetvdb.com/lists/6957", "en", status_message=False)
|
||||
if len(tvdb_ids) == 4 and len(tmdb_ids) == 2: logger.info("Success | TVDb URL get TVDb IDs and TMDb IDs")
|
||||
else: logger.error(f"Failure | TVDb URL get TVDb IDs and TMDb IDs: {len(tvdb_ids)} Should be 4 and {len(tmdb_ids)} Should be 2")
|
||||
|
||||
try:
|
||||
config.TVDb.get_items("tvdb_show", "https://www.thetvdb.com/series/arrow", "en", status_message=False)
|
||||
logger.info("Success | TVDb URL get TVDb Series ID")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | TVDb URL get TVDb Series ID: {e}")
|
||||
|
||||
try:
|
||||
config.TVDb.get_items("tvdb_show", 279121, "en", status_message=False)
|
||||
logger.info("Success | TVDb ID get TVDb Series ID")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | TVDb ID get TVDb Series ID: {e}")
|
||||
|
||||
try:
|
||||
config.TVDb.get_items("tvdb_movie", "https://www.thetvdb.com/movies/the-lord-of-the-rings-the-fellowship-of-the-ring", "en", status_message=False)
|
||||
logger.info("Success | TVDb URL get TVDb Movie ID")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | TVDb URL get TVDb Movie ID: {e}")
|
||||
|
||||
try:
|
||||
config.TVDb.get_items("tvdb_movie", 107, "en", status_message=False)
|
||||
logger.info("Success | TVDb ID get TVDb Movie ID")
|
||||
except Failed as e:
|
||||
util.print_stacktrace()
|
||||
logger.error(f"Failure | TVDb ID get TVDb Movie ID: {e}")
|
||||
|
||||
else:
|
||||
util.separator("TVDb Not Configured")
|
Loading…
Reference in new issue