cache update

pull/240/head
meisnate12 4 years ago
parent b6e58a3482
commit adcf83b980

@ -61,7 +61,7 @@ class AniDBAPI:
if method == "anidb_id": anidb_ids.append(data)
elif method == "anidb_relation": anidb_ids.extend(self._relations(data, language))
else: raise Failed(f"AniDB Error: Method {method} not supported")
movie_ids, show_ids = self.config.Convert.anidb_to_ids(anidb_ids, language)
movie_ids, show_ids = self.config.Convert.anidb_to_ids(anidb_ids)
if status_message:
logger.debug(f"AniDB IDs Found: {anidb_ids}")
logger.debug(f"TMDb IDs Found: {movie_ids}")

@ -249,7 +249,7 @@ class AniListAPI:
logger.info(f"Processing {pretty}: ({data}) {name} ({len(anilist_ids)} Anime)")
else:
raise Failed(f"AniList Error: Method {method} not supported")
movie_ids, show_ids = self.config.Convert.anilist_to_ids(anilist_ids, language)
movie_ids, show_ids = self.config.Convert.anilist_to_ids(anilist_ids)
if status_message:
logger.debug(f"AniList IDs Found: {anilist_ids}")
logger.debug(f"Shows Found: {show_ids}")

@ -258,7 +258,7 @@ class CollectionBuilder:
for method_name, attr_data in template.items():
if method_name not in self.data and method_name not in ["default", "optional"]:
if attr_data:
if attr_data is not None:
def replace_txt(txt):
txt = str(txt)
for option in optional:

@ -11,29 +11,27 @@ class Cache:
with sqlite3.connect(cache) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
cursor.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='guids'")
cursor.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='guid_map'")
if cursor.fetchone()[0] == 0:
logger.info(f"Initializing cache database at {cache}")
else:
logger.info(f"Using cache database at {cache}")
cursor.execute("DROP TABLE IF EXISTS guids")
cursor.execute(
"""CREATE TABLE IF NOT EXISTS guids (
"""CREATE TABLE IF NOT EXISTS guid_map (
INTEGER PRIMARY KEY,
plex_guid TEXT UNIQUE,
tmdb_id TEXT,
imdb_id TEXT,
tvdb_id TEXT,
anidb_id TEXT,
expiration_date TEXT,
media_type TEXT)"""
t_id TEXT,
media_type TEXT,
expiration_date TEXT)"""
)
cursor.execute(
"""CREATE TABLE IF NOT EXISTS imdb_map (
INTEGER PRIMARY KEY,
imdb_id TEXT UNIQUE,
t_id TEXT,
expiration_date TEXT,
media_type TEXT)"""
media_type TEXT,
expiration_date TEXT)"""
)
cursor.execute(
"""CREATE TABLE IF NOT EXISTS letterboxd_map (
@ -68,45 +66,21 @@ class Cache:
self.expiration = expiration
self.cache_path = cache
def get_ids_from_imdb(self, imdb_id):
tmdb_id, tmdb_expired = self.get_tmdb_id("movie", imdb_id=imdb_id)
tvdb_id, tvdb_expired = self.get_tvdb_id("show", imdb_id=imdb_id)
return tmdb_id, tvdb_id
def get_tmdb_id(self, media_type, plex_guid=None, imdb_id=None, tvdb_id=None, anidb_id=None):
return self._id_from(media_type, "tmdb_id", plex_guid=plex_guid, imdb_id=imdb_id, tvdb_id=tvdb_id, anidb_id=anidb_id)
def get_imdb_id(self, media_type, plex_guid=None, tmdb_id=None, tvdb_id=None, anidb_id=None):
return self._id_from(media_type, "imdb_id", plex_guid=plex_guid, tmdb_id=tmdb_id, tvdb_id=tvdb_id, anidb_id=anidb_id)
def get_tvdb_id(self, media_type, plex_guid=None, tmdb_id=None, imdb_id=None, anidb_id=None):
return self._id_from(media_type, "tvdb_id", plex_guid=plex_guid, tmdb_id=tmdb_id, imdb_id=imdb_id, anidb_id=anidb_id)
def get_anidb_id(self, media_type, plex_guid=None, tmdb_id=None, imdb_id=None, tvdb_id=None):
return self._id_from(media_type, "anidb_id", plex_guid=plex_guid, tmdb_id=tmdb_id, imdb_id=imdb_id, tvdb_id=tvdb_id)
def _id_from(self, media_type, id_from, plex_guid=None, tmdb_id=None, imdb_id=None, tvdb_id=None, anidb_id=None):
if plex_guid: return self._id(media_type, "plex_guid", id_from, plex_guid)
elif tmdb_id: return self._id(media_type, "tmdb_id", id_from, tmdb_id)
elif imdb_id: return self._id(media_type, "imdb_id", id_from, imdb_id)
elif tvdb_id: return self._id(media_type, "tvdb_id", id_from, tvdb_id)
elif anidb_id: return self._id(media_type, "anidb_id", id_from, anidb_id)
else: return None, None
def _id(self, media_type, from_id, to_id, key):
def query_guid_map(self, plex_guid):
id_to_return = None
media_type = None
expired = None
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
cursor.execute(f"SELECT * FROM guids WHERE {from_id} = ? AND media_type = ?", (key, media_type))
cursor.execute(f"SELECT * FROM guid_map WHERE plex_guid = ?", (plex_guid,))
row = cursor.fetchone()
if row and row[to_id]:
datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d")
time_between_insertion = datetime.now() - datetime_object
id_to_return = int(row[to_id])
if row:
time_between_insertion = datetime.now() - datetime.strptime(row["expiration_date"], "%Y-%m-%d")
id_to_return = row["t_id"]
media_type = row["media_type"]
expired = time_between_insertion.days > self.expiration
return id_to_return, expired
return id_to_return, media_type, expired
def get_ids(self, media_type, plex_guid=None, tmdb_id=None, imdb_id=None, tvdb_id=None):
ids_to_return = {}
@ -128,7 +102,7 @@ class Cache:
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
cursor.execute(f"SELECT * FROM guids WHERE {key_type} = ? AND media_type = ?", (key, media_type))
cursor.execute(f"SELECT * FROM guid_map WHERE {key_type} = ? AND media_type = ?", (key, media_type))
row = cursor.fetchone()
if row:
if row["plex_guid"]: ids_to_return["plex"] = row["plex_guid"]
@ -141,24 +115,13 @@ class Cache:
expired = time_between_insertion.days > self.expiration
return ids_to_return, expired
def update_guid(self, media_type, plex_guid, tmdb_id, imdb_id, tvdb_id, anidb_id, expired):
def update_guid(self, media_type, plex_guid, t_id, expired):
expiration_date = datetime.now() if expired is True else (datetime.now() - timedelta(days=random.randint(1, self.expiration)))
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
cursor.execute("INSERT OR IGNORE INTO guids(plex_guid) VALUES(?)", (plex_guid,))
cursor.execute(
"""UPDATE guids SET
tmdb_id = ?,
imdb_id = ?,
tvdb_id = ?,
anidb_id = ?,
expiration_date = ?,
media_type = ?
WHERE plex_guid = ?""", (tmdb_id, imdb_id, tvdb_id, anidb_id, expiration_date.strftime("%Y-%m-%d"), media_type, plex_guid))
if imdb_id and (tmdb_id or tvdb_id):
cursor.execute("INSERT OR IGNORE INTO imdb_map(imdb_id) VALUES(?)", (imdb_id,))
cursor.execute("UPDATE imdb_map SET t_id = ?, expiration_date = ?, media_type = ? WHERE imdb_id = ?", (tmdb_id if media_type == "movie" else tvdb_id, expiration_date.strftime("%Y-%m-%d"), media_type, imdb_id))
cursor.execute("INSERT OR IGNORE INTO guid_map(plex_guid) VALUES(?)", (plex_guid,))
cursor.execute("UPDATE guid_map SET t_id = ?, media_type = ?, expiration_date = ? WHERE plex_guid = ?", (t_id, media_type, expiration_date.strftime("%Y-%m-%d"), plex_guid))
def get_tmdb_from_imdb(self, imdb_id): return self._imdb_map("movie", imdb_id)
def get_tvdb_from_imdb(self, imdb_id): return self._imdb_map("show", imdb_id)

@ -22,7 +22,7 @@ class Convert:
if len(ids) > 0:
try:
if len(ids[0]) > 0:
return ids[0].split(",") if to_id == "imdbid" else int(ids[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}"
@ -30,7 +30,7 @@ class Convert:
fail_text = f"Convert Error: AniDB ID: {input_id} not found"
if fail:
raise Failed(fail_text)
return None
return [] if to_id == "imdbid" else None
@retry(stop_max_attempt_number=6, wait_fixed=10000)
def _request(self, ids):
@ -67,79 +67,43 @@ class Convert:
converted_ids.append(anime_ids)
return converted_ids
def anidb_to_ids(self, anidb_list, language):
def anidb_to_ids(self, anidb_list):
show_ids = []
movie_ids = []
for anidb_id in anidb_list:
try:
for imdb_id in self.anidb_to_imdb(anidb_id, fail=True):
tmdb_id, _ = self.imdb_to_ids(imdb_id, language)
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:
movie_ids.append(tmdb_id)
except Failed:
tmdb_ids.append(tmdb_id)
tvdb_id = self.anidb_to_tvdb(anidb_id)
if tvdb_id:
show_ids.append(tvdb_id)
else:
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, language):
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, language)
return self.anidb_to_ids(anidb_ids)
def myanimelist_to_ids(self, mal_ids, language):
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, language)
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:
tmdb_id = self.imdb_to_tmdb(imdb_id)
if not tmdb_id and not tvdb_id:
tvdb_id = self.imdb_to_tvdb(imdb_id)
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"Convert 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
return self.anidb_to_ids(anidb_ids)
def anidb_to_tvdb(self, anidb_id, fail=False):
return self._anidb(anidb_id, "tvdbid", fail=fail)
@ -161,17 +125,25 @@ class Convert:
return None
def imdb_to_tmdb(self, imdb_id, is_movie=True, fail=False):
expired = False
if self.config.Cache and is_movie:
cache_id, expired = self.config.Cache.get_tmdb_from_imdb(imdb_id)
if cache_id and not expired:
return cache_id
tmdb_id = None
try:
return self.config.TMDb.convert_to(imdb_id, "imdb_id", is_movie)
tmdb_id = self.config.TMDb.convert_to(imdb_id, "imdb_id", is_movie)
except Failed:
if self.config.Trakt:
try:
return self.config.Trakt.convert(imdb_id, "imdb", "tmdb", "movie" if is_movie else "show")
tmdb_id = self.config.Trakt.convert(imdb_id, "imdb", "tmdb", "movie" if is_movie else "show")
except Failed:
pass
if fail:
if fail and tmdb_id is None:
raise Failed(f"Convert Error: No TMDb ID Found for IMDb ID: {imdb_id}")
return None
if self.config.Cache and tmdb_id and is_movie:
self.config.Cache.update_imdb("movie", expired, imdb_id, tmdb_id)
return tmdb_id
# TODO
def tmdb_to_tvdb(self, tmdb_id, fail=False):
@ -215,33 +187,38 @@ class Convert:
return None
def imdb_to_tvdb(self, imdb_id, fail=False):
expired = False
if self.config.Cache:
cache_id, expired = self.config.Cache.get_tvdb_from_imdb(imdb_id)
if cache_id and not expired:
return cache_id
tvdb_id = None
try:
return self.tmdb_to_tvdb(self.imdb_to_tmdb(imdb_id, False))
tvdb_id = self.tmdb_to_tvdb(self.imdb_to_tmdb(imdb_id, False))
except Failed:
if self.config.Trakt:
try:
return self.config.Trakt.convert(imdb_id, "imdb", "tvdb", "show")
tvdb_id = self.config.Trakt.convert(imdb_id, "imdb", "tvdb", "show")
except Failed:
pass
if fail:
if fail and tvdb_id is None:
raise Failed(f"Convert Error: No TVDb ID Found for IMDb ID: {imdb_id}")
return None
if self.config.Cache and tvdb_id:
self.config.Cache.update_imdb("show", 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
mal_id = None
error_message = None
if self.config.Cache:
if library.is_movie: tmdb_id, expired = self.config.Cache.get_tmdb_id("movie", plex_guid=item.guid)
else: tvdb_id, expired = self.config.Cache.get_tvdb_id("show", plex_guid=item.guid)
if not tvdb_id and library.is_show:
tmdb_id, expired = self.config.Cache.get_tmdb_id("show", plex_guid=item.guid)
anidb_id, expired = self.config.Cache.get_anidb_id("show", plex_guid=item.guid)
if expired or (not tmdb_id and library.is_movie) or (not tvdb_id and not tmdb_id and library.is_show):
guid = requests.utils.urlparse(item.guid)
item_type = guid.scheme.split(".")[-1]
check_id = guid.netloc
@ -250,17 +227,6 @@ class Convert:
tmdb_id = []
imdb_id = []
tvdb_id = []
if check_id == "movie":
try:
for guid_tag in library.get_guids(item):
url_parsed = requests.utils.urlparse(guid_tag.id)
if url_parsed.scheme == "tmdb": tmdb_id.append(int(url_parsed.netloc))
elif url_parsed.scheme == "imdb": imdb_id.append(url_parsed.netloc)
except requests.exceptions.ConnectionError:
util.print_stacktrace()
logger.error(f"{'Cache | ! |' if self.config.Cache else 'Mapping Error:'} {item.guid:<46} | No External GUIDs found for {item.title}")
return None, None
elif check_id == "show":
try:
for guid_tag in library.get_guids(item):
url_parsed = requests.utils.urlparse(guid_tag.id)
@ -269,28 +235,28 @@ class Convert:
elif url_parsed.scheme == "tmdb": tmdb_id.append(int(url_parsed.netloc))
except requests.exceptions.ConnectionError:
util.print_stacktrace()
logger.error(f"{'Cache | ! |' if self.config.Cache else 'Mapping Error:'} {item.guid:<46} | No External GUIDs found for {item.title}")
return None, None
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: error_message = f"Hama Agent ID: {check_id} not supported"
elif item_type == "myanimelist": mal_id = check_id
elif item_type == "local": error_message = "No match in Plex"
else: error_message = f"Agent {item_type} not supported"
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 not error_message:
if mal_id and not anidb_id:
anime_ids = self._arms_ids(mal_ids=mal_id)
if anime_ids[0] and anime_ids[0]["anidb"]:
anidb_id = anime_ids[0]["anidb"]
if anidb_id and not tvdb_id:
tvdb_id = self.anidb_to_tvdb(anidb_id)
if anidb_id and not imdb_id:
if anidb_id:
imdb_id = self.anidb_to_imdb(anidb_id)
if not imdb_id:
tvdb_id = self.anidb_to_tvdb(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 = []
@ -304,43 +270,31 @@ class Convert:
imdb_id = new_imdb_id
else:
tmdb_id = self.imdb_to_tmdb(imdb_id)
if not tmdb_id and tvdb_id and library.is_show: tmdb_id = self.tvdb_to_tmdb(tvdb_id)
if not imdb_id and tmdb_id and library.is_movie: imdb_id = self.tmdb_to_imdb(tmdb_id)
if not imdb_id and tvdb_id and library.is_show: imdb_id = self.tvdb_to_imdb(tvdb_id)
if not tvdb_id and tmdb_id and library.is_show: tvdb_id = self.tmdb_to_tvdb(tmdb_id)
if not tvdb_id and imdb_id and library.is_show: tvdb_id = self.imdb_to_tvdb(imdb_id)
if (not tmdb_id and library.is_movie) or (not tvdb_id and not (anidb_id and tmdb_id) and library.is_show):
service_name = "TMDb ID" if library.is_movie else "TVDb ID"
if self.config.Trakt: api_name = "TMDb or Trakt"
else: api_name = "TMDb"
if tmdb_id and imdb_id: id_name = f"TMDb ID: {tmdb_id} or IMDb ID: {imdb_id}"
elif imdb_id and tvdb_id: id_name = f"IMDb ID: {imdb_id} or TVDb ID: {tvdb_id}"
elif tmdb_id: id_name = f"TMDb ID: {tmdb_id}"
elif imdb_id: id_name = f"IMDb ID: {imdb_id}"
elif tvdb_id: id_name = f"TVDb ID: {tvdb_id}"
else: id_name = None
if not tmdb_id:
raise Failed(f"Unable to convert IMDb ID: {imdb_id} to TMDb ID")
if not anidb_id and not tvdb_id and tmdb_id and library.is_show:
tvdb_id = self.tmdb_to_tvdb(tmdb_id)
if not tvdb_id:
raise Failed(f"Unable to convert TMDb ID: {tmdb_id} to TVDb ID")
if anidb_id and not tmdb_id and not tvdb_id: error_message = f"Unable to convert AniDB ID: {anidb_id} to TMDb ID or TVDb ID"
elif id_name: error_message = f"Unable to convert {id_name} to {service_name} using {api_name}"
else: error_message = f"No ID to convert to {service_name}"
if self.config.Cache and ((tmdb_id and library.is_movie) or ((tvdb_id or (anidb_id and tmdb_id)) and library.is_show)):
if not isinstance(tmdb_id, list): tmdb_id = [tmdb_id]
if not isinstance(imdb_id, list): imdb_id = [imdb_id]
if not isinstance(tvdb_id, list): tvdb_id = [tvdb_id]
try: tvdb_value = tvdb_id[0]
except IndexError: tvdb_value = None
for i in range(len(tmdb_id)):
try: imdb_value = imdb_id[i]
except IndexError: imdb_value = None
util.print_end(length, f"Cache | {'^' if expired is True else '+'} | {item.guid:<46} | {tmdb_id[i] if tmdb_id[i] else 'None':<6} | {imdb_value if imdb_value else 'None':<10} | {tvdb_value if tvdb_value else 'None':<6} | {anidb_id if anidb_id else 'None':<5} | {item.title}")
self.config.Cache.update_guid("movie" if library.is_movie else "show", item.guid, tmdb_id[i], imdb_value, tvdb_value, anidb_id, expired)
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(guid_type, item.guid, cache_ids, 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 and tmdb_id: return "movie", tmdb_id
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:
util.print_end(length, f"{'Cache | ! |' if self.config.Cache else 'Mapping Error:'} {item.guid:<46} | {error_message} for {item.title}")
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

@ -100,7 +100,10 @@ class IMDbAPI:
if method == "imdb_id":
if status_message:
logger.info(f"Processing {pretty}: {data}")
tmdb_id, tvdb_id = self.config.Convert.imdb_to_ids(data, language)
tmdb_id = self.config.Convert.imdb_to_tmdb(data)
tvdb_id = self.config.Convert.imdb_to_tvdb(data)
if not tmdb_id and not tvdb_id:
logger.error(f"Convert Error: No TMDb ID or TVDb ID found for IMDb: {data}")
if tmdb_id: movie_ids.append(tmdb_id)
if tvdb_id: show_ids.append(tvdb_id)
elif method == "imdb_list":
@ -112,11 +115,12 @@ class IMDbAPI:
length = 0
for i, imdb_id in enumerate(imdb_ids, 1):
length = util.print_return(length, f"Converting IMDb ID {i}/{total_ids}")
try:
tmdb_id, tvdb_id = self.config.Convert.imdb_to_ids(imdb_id, language)
tmdb_id = self.config.Convert.imdb_to_tmdb(imdb_id)
tvdb_id = self.config.Convert.imdb_to_tvdb(imdb_id)
if not tmdb_id and not tvdb_id:
logger.error(f"Convert Error: No TMDb ID or TVDb ID found for IMDb: {imdb_id}")
if tmdb_id: movie_ids.append(tmdb_id)
if tvdb_id: show_ids.append(tvdb_id)
except Failed as e: logger.warning(e)
util.print_end(length, f"Processed {total_ids} IMDb IDs")
else:
raise Failed(f"IMDb Error: Method {method} not supported")

@ -219,7 +219,7 @@ class MyAnimeListAPI:
logger.info(f"Processing {pretty}: {data['limit']} Anime from {self._username() if data['username'] == '@me' else data['username']}'s {pretty_names[data['status']]} list sorted by {pretty_names[data['sort_by']]}")
else:
raise Failed(f"MyAnimeList Error: Method {method} not supported")
movie_ids, show_ids = self.config.Convert.myanimelist_to_ids(mal_ids, language)
movie_ids, show_ids = self.config.Convert.myanimelist_to_ids(mal_ids)
if status_message:
logger.debug(f"MyAnimeList IDs Found: {mal_ids}")
logger.debug(f"Shows Found: {show_ids}")

@ -63,7 +63,7 @@ class TVDbObj:
results = response.xpath("//*[text()='IMDB']/@href")
if len(results) > 0:
try:
tmdb_id, _ = TVDb.config.Convert.imdb_to_ids(util.get_id_from_imdb_url(results[0]), language)
tmdb_id = TVDb.config.Convert.imdb_to_tmdb(util.get_id_from_imdb_url(results[0]), fail=True)
except Failed as e:
logger.error(e)
self.tmdb_id = tmdb_id

@ -207,11 +207,22 @@ def get_bool(method_name, method_data):
else:
raise Failed(f"Collection Error: {method_name} attribute: {method_data} invalid must be either true or false")
def get_list(data, lower=False, split=True):
def compile_list(data):
if isinstance(data, list):
text = ""
for item in data:
text += f"{',' if len(text) > 0 else ''}{item}"
return text
else:
return data
def get_list(data, lower=False, split=True, int_list=False):
if isinstance(data, list): return data
elif isinstance(data, dict): return [data]
elif split is False: return [str(data)]
elif lower is True: return [d.strip().lower() for d in str(data).split(",")]
elif int_list is True: return [int(d.strip()) for d in str(data).split(",")]
else: return [d.strip() for d in str(data).split(",")]
def get_int_list(data, id_type):

Loading…
Cancel
Save