speed up IMDb #267

This commit is contained in:
meisnate12 2021-05-21 10:30:23 -04:00
parent 1758dad7ca
commit f1e56a5abc
7 changed files with 33 additions and 36 deletions

View file

@ -1315,7 +1315,7 @@ class CollectionBuilder:
elif "anilist" in method: check_map(self.config.AniList.get_items(method, value)) elif "anilist" in method: check_map(self.config.AniList.get_items(method, value))
elif "mal" in method: check_map(self.config.MyAnimeList.get_items(method, value)) elif "mal" in method: check_map(self.config.MyAnimeList.get_items(method, value))
elif "tvdb" in method: check_map(self.config.TVDb.get_items(method, value, self.library.Plex.language)) elif "tvdb" in method: check_map(self.config.TVDb.get_items(method, value, self.library.Plex.language))
elif "imdb" in method: check_map(self.config.IMDb.get_items(method, value, self.library.Plex.language)) elif "imdb" in method: check_map(self.config.IMDb.get_items(method, value, self.library.Plex.language, self.library.is_movie))
elif "letterboxd" in method: check_map(self.config.Letterboxd.get_items(method, value, self.library.Plex.language)) elif "letterboxd" in method: check_map(self.config.Letterboxd.get_items(method, value, self.library.Plex.language))
elif "tmdb" in method: check_map(self.config.TMDb.get_items(method, value, self.library.is_movie)) elif "tmdb" in method: check_map(self.config.TMDb.get_items(method, value, self.library.is_movie))
elif "trakt" in method: check_map(self.config.Trakt.get_items(method, value, self.library.is_movie)) elif "trakt" in method: check_map(self.config.Trakt.get_items(method, value, self.library.is_movie))
@ -1432,7 +1432,7 @@ class CollectionBuilder:
break break
length = util.print_return(length, f"Filtering {(' ' * (max_length - len(str(i)))) + str(i)}/{total} {current.title}") length = util.print_return(length, f"Filtering {(' ' * (max_length - len(str(i)))) + str(i)}/{total} {current.title}")
if match: if match:
util.print_end(length, f"{name} Collection | {'=' if current in collection_items else '+'} | {current.title}") logger.info(util.adjust_space(length, f"{name} Collection | {'=' if current in collection_items else '+'} | {current.title}"))
if current in collection_items: if current in collection_items:
self.plex_map[current.ratingKey] = None self.plex_map[current.ratingKey] = None
elif self.smart_label_collection: elif self.smart_label_collection:
@ -1442,7 +1442,7 @@ class CollectionBuilder:
elif self.details["show_filtered"] is True: elif self.details["show_filtered"] is True:
logger.info(f"{name} Collection | X | {current.title}") logger.info(f"{name} Collection | X | {current.title}")
media_type = f"{'Movie' if self.library.is_movie else 'Show'}{'s' if total > 1 else ''}" media_type = f"{'Movie' if self.library.is_movie else 'Show'}{'s' if total > 1 else ''}"
util.print_end(length, f"{total} {media_type} Processed") logger.info(util.adjust_space(length, f"{total} {media_type} Processed"))
def run_missing(self): def run_missing(self):
logger.info("") logger.info("")

View file

@ -214,7 +214,7 @@ class Convert:
return cache_id return cache_id
imdb_id = None imdb_id = None
try: try:
imdb_id = self.tmdb_to_imdb(self.tvdb_to_tmdb(tvdb_id), False) imdb_id = self.tmdb_to_imdb(self.tvdb_to_tmdb(tvdb_id, fail=True), is_movie=False, fail=True)
except Failed: except Failed:
if self.config.Trakt: if self.config.Trakt:
try: try:
@ -235,7 +235,7 @@ class Convert:
return cache_id return cache_id
tvdb_id = None tvdb_id = None
try: try:
tvdb_id = self.tmdb_to_tvdb(self.imdb_to_tmdb(imdb_id, False)) tvdb_id = self.tmdb_to_tvdb(self.imdb_to_tmdb(imdb_id, is_movie=False, fail=True), fail=True)
except Failed: except Failed:
if self.config.Trakt: if self.config.Trakt:
try: try:
@ -343,7 +343,7 @@ class Convert:
def update_cache(cache_ids, id_type, guid_type): def update_cache(cache_ids, id_type, guid_type):
if self.config.Cache: if self.config.Cache:
cache_ids = util.compile_list(cache_ids) 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}") logger.info(util.adjust_space(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) self.config.Cache.update_guid_map(guid_type, item.guid, cache_ids, expired)
if tmdb_id and library.is_movie: if tmdb_id and library.is_movie:
@ -358,8 +358,8 @@ class Convert:
else: else:
raise Failed(f"No ID to convert") raise Failed(f"No ID to convert")
except Failed as e: except Failed as e:
util.print_end(length, f"Mapping Error | {item.guid:<46} | {e} for {item.title}") logger.info(util.adjust_space(length, f"Mapping Error | {item.guid:<46} | {e} for {item.title}"))
except BadRequest: except BadRequest:
util.print_stacktrace() util.print_stacktrace()
util.print_end(length, f"Mapping Error: | {item.guid} for {item.title} not found") logger.info(util.adjust_space(length, f"Mapping Error: | {item.guid} for {item.title} not found"))
return None, None return None, None

View file

@ -91,34 +91,32 @@ class IMDbAPI:
def _request(self, url, header): def _request(self, url, header):
return html.fromstring(requests.get(url, headers=header).content) return html.fromstring(requests.get(url, headers=header).content)
def get_items(self, method, data, language): def get_items(self, method, data, language, is_movie):
pretty = util.pretty_names[method] if method in util.pretty_names else method pretty = util.pretty_names[method] if method in util.pretty_names else method
logger.debug(f"Data: {data}") logger.debug(f"Data: {data}")
show_ids = [] show_ids = []
movie_ids = [] movie_ids = []
if method == "imdb_id": def run_convert(imdb_id):
logger.info(f"Processing {pretty}: {data}") tmdb_id = self.config.Convert.imdb_to_tmdb(imdb_id)
tmdb_id = self.config.Convert.imdb_to_tmdb(data) tvdb_id = self.config.Convert.imdb_to_tvdb(imdb_id) if not is_movie else None
tvdb_id = self.config.Convert.imdb_to_tvdb(data)
if not tmdb_id and not tvdb_id: if not tmdb_id and not tvdb_id:
logger.error(f"Convert Error: No TMDb ID or TVDb ID found for IMDb: {data}") 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 tmdb_id: movie_ids.append(tmdb_id)
if tvdb_id: show_ids.append(tvdb_id) if tvdb_id: show_ids.append(tvdb_id)
if method == "imdb_id":
logger.info(f"Processing {pretty}: {data}")
run_convert(data)
elif method == "imdb_list": elif method == "imdb_list":
status = f"{data['limit']} Items at " if data['limit'] > 0 else '' status = f"{data['limit']} Items at " if data['limit'] > 0 else ''
logger.info(f"Processing {pretty}: {status}{data['url']}") logger.info(f"Processing {pretty}: {status}{data['url']}")
imdb_ids = self._ids_from_url(data["url"], language, data["limit"]) imdb_ids = self._ids_from_url(data["url"], language, data["limit"])
total_ids = len(imdb_ids) total_ids = len(imdb_ids)
length = 0 length = 0
for i, imdb_id in enumerate(imdb_ids, 1): for i, imdb in enumerate(imdb_ids, 1):
length = util.print_return(length, f"Converting IMDb ID {i}/{total_ids}") length = util.print_return(length, f"Converting IMDb ID {i}/{total_ids}")
tmdb_id = self.config.Convert.imdb_to_tmdb(imdb_id) run_convert(imdb)
tvdb_id = self.config.Convert.imdb_to_tvdb(imdb_id) logger.info(util.adjust_space(length, f"Processed {total_ids} IMDb IDs"))
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)
util.print_end(length, f"Processed {total_ids} IMDb IDs")
else: else:
raise Failed(f"IMDb Error: Method {method} not supported") raise Failed(f"IMDb Error: Method {method} not supported")
logger.debug(f"TMDb IDs Found: {movie_ids}") logger.debug(f"TMDb IDs Found: {movie_ids}")

View file

@ -66,7 +66,7 @@ class LetterboxdAPI:
if self.config.Cache: if self.config.Cache:
self.config.Cache.update_letterboxd_map(expired, letterboxd_id, tmdb_id) self.config.Cache.update_letterboxd_map(expired, letterboxd_id, tmdb_id)
movie_ids.append(tmdb_id) movie_ids.append(tmdb_id)
util.print_end(length, f"Processed {total_items} TMDb IDs") logger.info(util.adjust_space(length, f"Processed {total_items} TMDb IDs"))
else: else:
logger.error(f"Letterboxd Error: No List Items found in {data}") logger.error(f"Letterboxd Error: No List Items found in {data}")
logger.debug(f"TMDb IDs Found: {movie_ids}") logger.debug(f"TMDb IDs Found: {movie_ids}")

View file

@ -617,7 +617,7 @@ class PlexAPI:
break break
if add_item: if add_item:
items.append(item) items.append(item)
util.print_end(length, f"Processed {len(all_items)} {'Movies' if self.is_movie else 'Shows'}") logger.info(util.adjust_space(length, f"Processed {len(all_items)} {'Movies' if self.is_movie else 'Shows'}"))
else: else:
raise Failed(f"Plex Error: Method {method} not supported") raise Failed(f"Plex Error: Method {method} not supported")
if len(items) > 0: if len(items) > 0:

View file

@ -387,9 +387,8 @@ def print_return(length, text):
print(adjust_space(length, f"| {text}"), end="\r") print(adjust_space(length, f"| {text}"), end="\r")
return len(text) + 2 return len(text) + 2
def print_end(length, text=None): def print_end(length):
if text: logger.info(adjust_space(length, text)) print(adjust_space(length, " "), end="\r")
else: print(adjust_space(length, " "), end="\r")
def validate_filename(filename): def validate_filename(filename):
if is_valid_filename(filename): if is_valid_filename(filename):

View file

@ -251,7 +251,7 @@ def map_guids(config, library):
for m in main_id: for m in main_id:
if m in show_map: show_map[m].append(item.ratingKey) if m in show_map: show_map[m].append(item.ratingKey)
else: show_map[m] = [item.ratingKey] else: show_map[m] = [item.ratingKey]
util.print_end(length, f"Processed {len(items)} {'Movies' if library.is_movie else 'Shows'}") logger.info(util.adjust_space(length, f"Processed {len(items)} {'Movies' if library.is_movie else 'Shows'}"))
return movie_map, show_map return movie_map, show_map
def mass_metadata(config, library, movie_map, show_map): def mass_metadata(config, library, movie_map, show_map):
@ -298,9 +298,9 @@ def mass_metadata(config, library, movie_map, show_map):
try: try:
tmdb_item = config.TMDb.get_movie(tmdb_id) if library.is_movie else config.TMDb.get_show(tmdb_id) tmdb_item = config.TMDb.get_movie(tmdb_id) if library.is_movie else config.TMDb.get_show(tmdb_id)
except Failed as e: except Failed as e:
util.print_end(length, str(e)) logger.info(util.adjust_space(length, str(e)))
else: else:
util.print_end(length, f"{item.title[:25]:<25} | No TMDb ID for Guid: {item.guid}") logger.info(util.adjust_space(length, f"{item.title[:25]:<25} | No TMDb ID for Guid: {item.guid}"))
omdb_item = None omdb_item = None
if library.mass_genre_update in ["omdb", "imdb"] or library.mass_audience_rating_update in ["omdb", "imdb"] or library.mass_critic_rating_update in ["omdb", "imdb"]: if library.mass_genre_update in ["omdb", "imdb"] or library.mass_audience_rating_update in ["omdb", "imdb"] or library.mass_critic_rating_update in ["omdb", "imdb"]:
@ -313,9 +313,9 @@ def mass_metadata(config, library, movie_map, show_map):
try: try:
omdb_item = config.OMDb.get_omdb(imdb_id) omdb_item = config.OMDb.get_omdb(imdb_id)
except Failed as e: except Failed as e:
util.print_end(length, str(e)) logger.info(util.adjust_space(length, str(e)))
else: else:
util.print_end(length, f"{item.title[:25]:<25} | No IMDb ID for Guid: {item.guid}") logger.info(util.adjust_space(length, f"{item.title[:25]:<25} | No IMDb ID for Guid: {item.guid}"))
if not tmdb_item and not omdb_item: if not tmdb_item and not omdb_item:
continue continue
@ -337,7 +337,7 @@ def mass_metadata(config, library, movie_map, show_map):
library.query_data(item.addGenre, genre) library.query_data(item.addGenre, genre)
display_str += f"{', ' if len(display_str) > 0 else ''}+{genre}" display_str += f"{', ' if len(display_str) > 0 else ''}+{genre}"
if len(display_str) > 0: if len(display_str) > 0:
util.print_end(length, f"{item.title[:25]:<25} | Genres | {display_str}") logger.info(util.adjust_space(length, f"{item.title[:25]:<25} | Genres | {display_str}"))
except Failed: except Failed:
pass pass
if library.mass_audience_rating_update or library.mass_critic_rating_update: if library.mass_audience_rating_update or library.mass_critic_rating_update:
@ -349,14 +349,14 @@ def mass_metadata(config, library, movie_map, show_map):
else: else:
raise Failed raise Failed
if new_rating is None: if new_rating is None:
util.print_end(length, f"{item.title[:25]:<25} | No Rating Found") logger.info(util.adjust_space(length, f"{item.title[:25]:<25} | No Rating Found"))
else: else:
if library.mass_audience_rating_update and str(item.audienceRating) != str(new_rating): if library.mass_audience_rating_update and str(item.audienceRating) != str(new_rating):
library.edit_query(item, {"audienceRating.value": new_rating, "audienceRating.locked": 1}) library.edit_query(item, {"audienceRating.value": new_rating, "audienceRating.locked": 1})
util.print_end(length, f"{item.title[:25]:<25} | Audience Rating | {new_rating}") logger.info(util.adjust_space(length, f"{item.title[:25]:<25} | Audience Rating | {new_rating}"))
if library.mass_critic_rating_update and str(item.rating) != str(new_rating): if library.mass_critic_rating_update and str(item.rating) != str(new_rating):
library.edit_query(item, {"rating.value": new_rating, "rating.locked": 1}) library.edit_query(item, {"rating.value": new_rating, "rating.locked": 1})
util.print_end(length, f"{item.title[:25]:<25} | Critic Rating | {new_rating}") logger.info(util.adjust_space(length, f"{item.title[:25]:<25} | Critic Rating | {new_rating}"))
except Failed: except Failed:
pass pass