|
|
|
@ -52,7 +52,7 @@ class IMDbAPI:
|
|
|
|
|
def send_request(self, url, header):
|
|
|
|
|
return html.fromstring(requests.get(url, headers=header).content)
|
|
|
|
|
|
|
|
|
|
def get_items(self, method, data, language, status_message=True):
|
|
|
|
|
def get_items(self, config, method, data, language, status_message=True):
|
|
|
|
|
pretty = util.pretty_names[method] if method in util.pretty_names else method
|
|
|
|
|
if status_message:
|
|
|
|
|
logger.debug(f"Data: {data}")
|
|
|
|
@ -61,7 +61,7 @@ class IMDbAPI:
|
|
|
|
|
if method == "imdb_id":
|
|
|
|
|
if status_message:
|
|
|
|
|
logger.info(f"Processing {pretty}: {data}")
|
|
|
|
|
tmdb_id, tvdb_id = self.convert_from_imdb(data, language)
|
|
|
|
|
tmdb_id, tvdb_id = config.convert_from_imdb(data, language)
|
|
|
|
|
if tmdb_id: movie_ids.append(tmdb_id)
|
|
|
|
|
if tvdb_id: show_ids.append(tvdb_id)
|
|
|
|
|
elif method == "imdb_list":
|
|
|
|
@ -74,7 +74,7 @@ class IMDbAPI:
|
|
|
|
|
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.convert_from_imdb(imdb_id, language)
|
|
|
|
|
tmdb_id, tvdb_id = config.convert_from_imdb(imdb_id, language)
|
|
|
|
|
if tmdb_id: movie_ids.append(tmdb_id)
|
|
|
|
|
if tvdb_id: show_ids.append(tvdb_id)
|
|
|
|
|
except Failed as e: logger.warning(e)
|
|
|
|
@ -85,49 +85,3 @@ class IMDbAPI:
|
|
|
|
|
logger.debug(f"TMDb IDs Found: {movie_ids}")
|
|
|
|
|
logger.debug(f"TVDb IDs Found: {show_ids}")
|
|
|
|
|
return movie_ids, show_ids
|
|
|
|
|
|
|
|
|
|
def convert_from_imdb(self, imdb_id, language):
|
|
|
|
|
update_tmdb = False
|
|
|
|
|
update_tvdb = False
|
|
|
|
|
if self.Cache:
|
|
|
|
|
tmdb_id, tvdb_id = self.Cache.get_ids_from_imdb(imdb_id)
|
|
|
|
|
update_tmdb = False
|
|
|
|
|
if not tmdb_id:
|
|
|
|
|
tmdb_id, update_tmdb = self.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.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.TMDb:
|
|
|
|
|
try: tmdb_id = self.TMDb.convert_imdb_to_tmdb(imdb_id)
|
|
|
|
|
except Failed: pass
|
|
|
|
|
if not tmdb_id and not tvdb_id and self.TMDb:
|
|
|
|
|
try: tvdb_id = self.TMDb.convert_imdb_to_tvdb(imdb_id)
|
|
|
|
|
except Failed: pass
|
|
|
|
|
if not tmdb_id and not tvdb_id and self.Trakt:
|
|
|
|
|
try: tmdb_id = self.Trakt.convert_imdb_to_tmdb(imdb_id)
|
|
|
|
|
except Failed: pass
|
|
|
|
|
if not tmdb_id and not tvdb_id and self.Trakt:
|
|
|
|
|
try: tvdb_id = self.Trakt.convert_imdb_to_tvdb(imdb_id)
|
|
|
|
|
except Failed: pass
|
|
|
|
|
try:
|
|
|
|
|
if tmdb_id and not from_cache: self.TMDb.get_movie(tmdb_id)
|
|
|
|
|
except Failed: tmdb_id = None
|
|
|
|
|
try:
|
|
|
|
|
if tvdb_id and not from_cache: self.TVDb.get_series(language, tvdb_id=tvdb_id)
|
|
|
|
|
except Failed: tvdb_id = None
|
|
|
|
|
if not tmdb_id and not tvdb_id: raise Failed(f"IMDb Error: No TMDb ID or TVDb ID found for IMDb: {imdb_id}")
|
|
|
|
|
if self.Cache:
|
|
|
|
|
if tmdb_id and update_tmdb is not False:
|
|
|
|
|
self.Cache.update_imdb("movie", update_tmdb, imdb_id, tmdb_id)
|
|
|
|
|
if tvdb_id and update_tvdb is not False:
|
|
|
|
|
self.Cache.update_imdb("show", update_tvdb, imdb_id, tvdb_id)
|
|
|
|
|
return tmdb_id, tvdb_id
|
|
|
|
|