mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2024-11-10 06:54:21 +00:00
speed up IMDb #267
This commit is contained in:
parent
1758dad7ca
commit
f1e56a5abc
7 changed files with 33 additions and 36 deletions
|
@ -1315,7 +1315,7 @@ class CollectionBuilder:
|
|||
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 "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 "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))
|
||||
|
@ -1432,7 +1432,7 @@ class CollectionBuilder:
|
|||
break
|
||||
length = util.print_return(length, f"Filtering {(' ' * (max_length - len(str(i)))) + str(i)}/{total} {current.title}")
|
||||
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:
|
||||
self.plex_map[current.ratingKey] = None
|
||||
elif self.smart_label_collection:
|
||||
|
@ -1442,7 +1442,7 @@ class CollectionBuilder:
|
|||
elif self.details["show_filtered"] is True:
|
||||
logger.info(f"{name} Collection | X | {current.title}")
|
||||
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):
|
||||
logger.info("")
|
||||
|
|
|
@ -214,7 +214,7 @@ class Convert:
|
|||
return cache_id
|
||||
imdb_id = None
|
||||
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:
|
||||
if self.config.Trakt:
|
||||
try:
|
||||
|
@ -235,7 +235,7 @@ class Convert:
|
|||
return cache_id
|
||||
tvdb_id = None
|
||||
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:
|
||||
if self.config.Trakt:
|
||||
try:
|
||||
|
@ -343,7 +343,7 @@ class Convert:
|
|||
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}")
|
||||
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)
|
||||
|
||||
if tmdb_id and library.is_movie:
|
||||
|
@ -358,8 +358,8 @@ class Convert:
|
|||
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}")
|
||||
logger.info(util.adjust_space(length, f"Mapping Error | {item.guid:<46} | {e} for {item.title}"))
|
||||
except BadRequest:
|
||||
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
|
||||
|
|
|
@ -91,34 +91,32 @@ class IMDbAPI:
|
|||
def _request(self, url, header):
|
||||
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
|
||||
logger.debug(f"Data: {data}")
|
||||
show_ids = []
|
||||
movie_ids = []
|
||||
if method == "imdb_id":
|
||||
logger.info(f"Processing {pretty}: {data}")
|
||||
tmdb_id = self.config.Convert.imdb_to_tmdb(data)
|
||||
tvdb_id = self.config.Convert.imdb_to_tvdb(data)
|
||||
def run_convert(imdb_id):
|
||||
tmdb_id = self.config.Convert.imdb_to_tmdb(imdb_id)
|
||||
tvdb_id = self.config.Convert.imdb_to_tvdb(imdb_id) if not is_movie else None
|
||||
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 tvdb_id: show_ids.append(tvdb_id)
|
||||
|
||||
if method == "imdb_id":
|
||||
logger.info(f"Processing {pretty}: {data}")
|
||||
run_convert(data)
|
||||
elif method == "imdb_list":
|
||||
status = f"{data['limit']} Items at " if data['limit'] > 0 else ''
|
||||
logger.info(f"Processing {pretty}: {status}{data['url']}")
|
||||
imdb_ids = self._ids_from_url(data["url"], language, data["limit"])
|
||||
total_ids = len(imdb_ids)
|
||||
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}")
|
||||
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)
|
||||
util.print_end(length, f"Processed {total_ids} IMDb IDs")
|
||||
run_convert(imdb)
|
||||
logger.info(util.adjust_space(length, f"Processed {total_ids} IMDb IDs"))
|
||||
else:
|
||||
raise Failed(f"IMDb Error: Method {method} not supported")
|
||||
logger.debug(f"TMDb IDs Found: {movie_ids}")
|
||||
|
|
|
@ -66,7 +66,7 @@ class LetterboxdAPI:
|
|||
if self.config.Cache:
|
||||
self.config.Cache.update_letterboxd_map(expired, letterboxd_id, 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:
|
||||
logger.error(f"Letterboxd Error: No List Items found in {data}")
|
||||
logger.debug(f"TMDb IDs Found: {movie_ids}")
|
||||
|
|
|
@ -617,7 +617,7 @@ class PlexAPI:
|
|||
break
|
||||
if add_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:
|
||||
raise Failed(f"Plex Error: Method {method} not supported")
|
||||
if len(items) > 0:
|
||||
|
|
|
@ -387,9 +387,8 @@ def print_return(length, text):
|
|||
print(adjust_space(length, f"| {text}"), end="\r")
|
||||
return len(text) + 2
|
||||
|
||||
def print_end(length, text=None):
|
||||
if text: logger.info(adjust_space(length, text))
|
||||
else: print(adjust_space(length, " "), end="\r")
|
||||
def print_end(length):
|
||||
print(adjust_space(length, " "), end="\r")
|
||||
|
||||
def validate_filename(filename):
|
||||
if is_valid_filename(filename):
|
||||
|
|
|
@ -251,7 +251,7 @@ def map_guids(config, library):
|
|||
for m in main_id:
|
||||
if m in show_map: show_map[m].append(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
|
||||
|
||||
def mass_metadata(config, library, movie_map, show_map):
|
||||
|
@ -298,9 +298,9 @@ def mass_metadata(config, library, movie_map, show_map):
|
|||
try:
|
||||
tmdb_item = config.TMDb.get_movie(tmdb_id) if library.is_movie else config.TMDb.get_show(tmdb_id)
|
||||
except Failed as e:
|
||||
util.print_end(length, str(e))
|
||||
logger.info(util.adjust_space(length, str(e)))
|
||||
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
|
||||
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:
|
||||
omdb_item = config.OMDb.get_omdb(imdb_id)
|
||||
except Failed as e:
|
||||
util.print_end(length, str(e))
|
||||
logger.info(util.adjust_space(length, str(e)))
|
||||
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:
|
||||
continue
|
||||
|
@ -337,7 +337,7 @@ def mass_metadata(config, library, movie_map, show_map):
|
|||
library.query_data(item.addGenre, genre)
|
||||
display_str += f"{', ' if len(display_str) > 0 else ''}+{genre}"
|
||||
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:
|
||||
pass
|
||||
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:
|
||||
raise Failed
|
||||
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:
|
||||
if library.mass_audience_rating_update and str(item.audienceRating) != str(new_rating):
|
||||
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):
|
||||
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:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in a new issue