more caches

pull/240/head
meisnate12 3 years ago
parent 3f992d0f5c
commit 733c606743

@ -17,6 +17,7 @@ class Cache:
else:
logger.info(f"Using cache database at {cache}")
cursor.execute("DROP TABLE IF EXISTS guids")
cursor.execute("DROP TABLE IF EXISTS imdb_map")
cursor.execute(
"""CREATE TABLE IF NOT EXISTS guid_map (
INTEGER PRIMARY KEY,
@ -26,13 +27,27 @@ class Cache:
expiration_date TEXT)"""
)
cursor.execute(
"""CREATE TABLE IF NOT EXISTS imdb_map (
"""CREATE TABLE IF NOT EXISTS imdb_to_tmdb_map (
INTEGER PRIMARY KEY,
imdb_id TEXT UNIQUE,
t_id TEXT,
tmdb_id TEXT,
media_type TEXT,
expiration_date TEXT)"""
)
cursor.execute(
"""CREATE TABLE IF NOT EXISTS imdb_to_tvdb_map (
INTEGER PRIMARY KEY,
imdb_id TEXT UNIQUE,
tvdb_id TEXT UNIQUE,
expiration_date TEXT)"""
)
cursor.execute(
"""CREATE TABLE IF NOT EXISTS tmdb_to_tvdb_map (
INTEGER PRIMARY KEY,
tmdb_id TEXT UNIQUE,
tvdb_id TEXT UNIQUE,
expiration_date TEXT)"""
)
cursor.execute(
"""CREATE TABLE IF NOT EXISTS letterboxd_map (
INTEGER PRIMARY KEY,
@ -82,94 +97,69 @@ class Cache:
expired = time_between_insertion.days > self.expiration
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 = {}
expired = None
if plex_guid:
key = plex_guid
key_type = "plex_guid"
elif tmdb_id:
key = tmdb_id
key_type = "tmdb_id"
elif imdb_id:
key = imdb_id
key_type = "imdb_id"
elif tvdb_id:
key = tvdb_id
key_type = "tvdb_id"
else:
raise Failed("ID Required")
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
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"]
if row["tmdb_id"]: ids_to_return["tmdb"] = int(row["tmdb_id"])
if row["imdb_id"]: ids_to_return["imdb"] = row["imdb_id"]
if row["tvdb_id"]: ids_to_return["tvdb"] = int(row["tvdb_id"])
if row["anidb_id"]: ids_to_return["anidb"] = int(row["anidb_id"])
datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d")
time_between_insertion = datetime.now() - datetime_object
expired = time_between_insertion.days > self.expiration
return ids_to_return, expired
def update_guid_map(self, media_type, plex_guid, t_id, expired):
self._update_map("guid_map", "plex_guid", plex_guid, "t_id", t_id, expired, media_type=media_type)
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 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 query_imdb_to_tmdb_map(self, media_type, _id, imdb=True):
from_id = "imdb_id" if imdb else "tmdb_id"
to_id = "tmdb_id" if imdb else "imdb_id"
return self._query_map("imdb_to_tmdb_map", _id, from_id, to_id, media_type=media_type)
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)
def _imdb_map(self, media_type, imdb_id):
id_to_return = None
expired = None
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
cursor.execute("SELECT * FROM imdb_map WHERE imdb_id = ? AND media_type = ?", (imdb_id, media_type))
row = cursor.fetchone()
if row and row["t_id"]:
datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d")
time_between_insertion = datetime.now() - datetime_object
id_to_return = int(row["t_id"])
expired = time_between_insertion.days > self.expiration
return id_to_return, expired
def update_imdb_to_tmdb_map(self, media_type, expired, imdb_id, tmdb_id):
self._update_map("imdb_to_tmdb_map", "imdb_id", imdb_id, "tmdb_id", tmdb_id, expired, media_type=media_type)
def update_imdb(self, media_type, expired, imdb_id, t_id):
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 imdb_map(imdb_id) VALUES(?)", (imdb_id,))
cursor.execute("UPDATE imdb_map SET t_id = ?, expiration_date = ?, media_type = ? WHERE imdb_id = ?", (t_id, expiration_date.strftime("%Y-%m-%d"), media_type, imdb_id))
def query_imdb_to_tvdb_map(self, _id, imdb=True):
from_id = "imdb_id" if imdb else "tvdb_id"
to_id = "tvdb_id" if imdb else "imdb_id"
return self._query_map("imdb_to_tvdb_map", _id, from_id, to_id)
def update_imdb_to_tvdb_map(self, expired, imdb_id, tvdb_id):
self._update_map("imdb_to_tvdb_map", "imdb_id", imdb_id, "tvdb_id", tvdb_id, expired)
def query_tmdb_to_tvdb_map(self, _id, tmdb=True):
from_id = "tmdb_id" if tmdb else "tvdb_id"
to_id = "tvdb_id" if tmdb else "tmdb_id"
return self._query_map("tmdb_to_tvdb_map", _id, from_id, to_id)
def update_tmdb_to_tvdb_map(self, expired, tmdb_id, tvdb_id):
self._update_map("tmdb_to_tvdb_map", "tmdb_id", tmdb_id, "tvdb_id", tvdb_id, expired)
def query_letterboxd_map(self, letterboxd_id):
tmdb_id = None
return self._query_map("letterboxd_map", letterboxd_id, "letterboxd_id", "tmdb_id")
def update_letterboxd_map(self, expired, letterboxd_id, tmdb_id):
self._update_map("letterboxd_map", "letterboxd_id", letterboxd_id, "tmdb_id", tmdb_id, expired)
def _query_map(self, map_name, _id, from_id, to_id, media_type=None):
id_to_return = None
expired = None
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:
cursor.execute("SELECT * FROM letterboxd_map WHERE letterboxd_id = ?", (letterboxd_id, ))
if media_type is None:
cursor.execute(f"SELECT * FROM {map_name} WHERE {from_id} = ?", (_id,))
else:
cursor.execute(f"SELECT * FROM {map_name} WHERE {from_id} = ? AND media_type = ?", (_id, media_type))
row = cursor.fetchone()
if row and row["tmdb_id"]:
if row and row[to_id]:
datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d")
time_between_insertion = datetime.now() - datetime_object
tmdb_id = int(row["tmdb_id"])
id_to_return = int(row[to_id])
expired = time_between_insertion.days > self.expiration
return tmdb_id, expired
return id_to_return, expired
def update_letterboxd(self, expired, letterboxd_id, tmdb_id):
def _update_map(self, map_name, val1, val1_name, val2, val2_name, expired, media_type=None):
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 letterboxd_map(letterboxd_id) VALUES(?)", (letterboxd_id,))
cursor.execute("UPDATE letterboxd_map SET tmdb_id = ?, expiration_date = ? WHERE letterboxd_id = ?", (tmdb_id, expiration_date.strftime("%Y-%m-%d"), letterboxd_id))
cursor.execute(f"INSERT OR IGNORE INTO {map_name}({val1_name}) VALUES(?)", (val1,))
if media_type is None:
sql = f"UPDATE {map_name} SET {val2_name} = ?, expiration_date = ? WHERE {val1_name} = ?"
cursor.execute(sql, (val2, expiration_date.strftime("%Y-%m-%d"), val1))
else:
sql = f"UPDATE {map_name} SET {val2_name} = ?, expiration_date = ?{'' if media_type is None else ', media_type = ?'} WHERE {val1_name} = ?"
cursor.execute(sql, (val2, expiration_date.strftime("%Y-%m-%d"), media_type, val1))
def query_omdb(self, imdb_id):
omdb_dict = {}
@ -223,7 +213,7 @@ class Cache:
expired = time_between_insertion.days > self.expiration
return ids, expired
def update_anime(self, expired, anime_ids):
def update_anime_map(self, expired, anime_ids):
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

@ -63,7 +63,7 @@ class Convert:
for anime_ids in self._request(unconverted_ids):
if anime_ids:
if self.config.Cache:
self.config.Cache.update_anime(False, anime_ids)
self.config.Cache.update_anime_map(False, anime_ids)
converted_ids.append(anime_ids)
return converted_ids
@ -112,22 +112,32 @@ class Convert:
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:
return self.config.TMDb.convert_from(tmdb_id, "imdb_id", is_movie)
imdb_id = self.config.TMDb.convert_from(tmdb_id, "imdb_id", is_movie)
except Failed:
if self.config.Trakt:
try:
return self.config.Trakt.convert(tmdb_id, "tmdb", "imdb", "movie" if is_movie else "show")
imdb_id = self.config.Trakt.convert(tmdb_id, "tmdb", "imdb", "movie" if is_movie else "show")
except Failed:
pass
if fail:
if fail and imdb_id is None:
raise Failed(f"Convert Error: No IMDb ID Found for TMDb ID: {tmdb_id}")
return None
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.get_tmdb_from_imdb(imdb_id)
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
@ -136,60 +146,82 @@ class Convert:
except Failed:
if self.config.Trakt:
try:
tmdb_id = self.config.Trakt.convert(imdb_id, "imdb", "tmdb", "movie" if is_movie else "show")
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 and is_movie:
self.config.Cache.update_imdb("movie", expired, imdb_id, tmdb_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
# TODO
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:
return self.config.TMDb.convert_from(tmdb_id, "tvdb_id", False)
tvdb_id = self.config.TMDb.convert_from(tmdb_id, "tvdb_id", False)
except Failed:
if self.config.Trakt:
try:
return self.config.Trakt.convert(tmdb_id, "tmdb", "tvdb", "show")
tvdb_id = self.config.Trakt.convert(tmdb_id, "tmdb", "tvdb", "show")
except Failed:
pass
if fail:
if fail and tvdb_id is None:
raise Failed(f"Convert Error: No TVDb ID Found for TMDb ID: {tmdb_id}")
return None
if self.config.Cache and tvdb_id:
self.config.Cache.update_tmdb_to_tvdb_map(expired, tmdb_id, tvdb_id)
return tvdb_id
# TODO
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:
return self.config.TMDb.convert_to(tvdb_id, "tvdb_id", False)
tmdb_id = self.config.TMDb.convert_to(tvdb_id, "tvdb_id", False)
except Failed:
if self.config.Trakt:
try:
return self.config.Trakt.convert(tvdb_id, "tvdb", "tmdb", "show")
tmdb_id = self.config.Trakt.convert(tvdb_id, "tvdb", "tmdb", "show")
except Failed:
pass
if fail:
if fail and tmdb_id is None:
raise Failed(f"Convert Error: No TMDb ID Found for TVDb ID: {tvdb_id}")
return None
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:
return self.tmdb_to_imdb(self.tvdb_to_tmdb(tvdb_id), False)
imdb_id = self.tmdb_to_imdb(self.tvdb_to_tmdb(tvdb_id), False)
except Failed:
if self.config.Trakt:
try:
return self.config.Trakt.convert(tvdb_id, "tvdb", "imdb", "show")
imdb_id = self.config.Trakt.convert(tvdb_id, "tvdb", "imdb", "show")
except Failed:
pass
if fail:
if fail and imdb_id is None:
raise Failed(f"Convert Error: No IMDb ID Found for TVDb ID: {tvdb_id}")
return None
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.get_tvdb_from_imdb(imdb_id)
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
@ -204,7 +236,7 @@ class Convert:
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("show", expired, imdb_id, 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):
@ -281,7 +313,7 @@ class Convert:
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)
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")

@ -42,32 +42,32 @@ class LetterboxdAPI:
descriptions = self._request(list_url, language).xpath("//meta[@property='og:description']/@content")
return descriptions[0] if len(descriptions) > 0 and len(descriptions[0]) > 0 else None
def get_items(self, method, data, language, status_message=True):
def get_items(self, method, data, language):
pretty = util.pretty_names[method] if method in util.pretty_names else method
movie_ids = []
if status_message:
logger.info(f"Processing {pretty}: {data}")
logger.info(f"Processing {pretty}: {data}")
items = self._parse_list(data, language)
total_items = len(items)
if total_items == 0:
raise Failed(f"Letterboxd Error: No List Items found in {data}")
length = 0
for i, item in enumerate(items, 1):
length = util.print_return(length, f"Finding TMDb ID {i}/{total_items}")
tmdb_id = None
expired = None
if self.config.Cache:
tmdb_id, expired = self.config.Cache.query_letterboxd_map(item[0])
if not tmdb_id or expired is not False:
try:
tmdb_id = self._tmdb(f"{self.url}{item[1]}", language)
except Failed as e:
logger.error(e)
continue
if total_items > 0:
length = 0
for i, item in enumerate(items, 1):
letterboxd_id, slug = item
length = util.print_return(length, f"Finding TMDb ID {i}/{total_items}")
tmdb_id = None
expired = None
if self.config.Cache:
self.config.Cache.update_letterboxd(expired, item[0], tmdb_id)
movie_ids.append(tmdb_id)
util.print_end(length, f"Processed {total_items} TMDb IDs")
if status_message:
logger.debug(f"TMDb IDs Found: {movie_ids}")
tmdb_id, expired = self.config.Cache.query_letterboxd_map(letterboxd_id)
if not tmdb_id or expired is not False:
try:
tmdb_id = self._tmdb(f"{self.url}{slug}", language)
except Failed as e:
logger.error(e)
continue
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")
else:
logger.error(f"Letterboxd Error: No List Items found in {data}")
logger.debug(f"TMDb IDs Found: {movie_ids}")
return movie_ids, []

@ -294,85 +294,91 @@ def mass_metadata(config, library, movie_map, show_map):
items = library.Plex.all()
for i, item in enumerate(items, 1):
length = util.print_return(length, f"Processing: {i}/{len(items)} {item.title}")
ids = {}
tmdb_id = None
tvdb_id = None
imdb_id = None
if config.Cache:
ids, expired = config.Cache.get_ids("movie" if library.is_movie else "show", plex_guid=item.guid)
elif library.is_movie:
t_id, guid_media_type, _ = config.Cache.config.Cache.query_guid_map(item.guid)
if t_id:
if "movie" in guid_media_type:
tmdb_id = t_id
else:
tvdb_id = t_id
if not tmdb_id and not tvdb_id:
for tmdb, rating_keys in movie_map.items():
if item.ratingKey in rating_keys:
ids["tmdb"] = tmdb
tmdb_id = tmdb
break
else:
if not tmdb_id and not tvdb_id and library.is_show:
for tvdb, rating_keys in show_map.items():
if item.ratingKey in rating_keys:
ids["tvdb"] = tvdb
break
if library.mass_genre_update:
if library.mass_genre_update == "tmdb":
if "tmdb" not in ids:
util.print_end(length, f"{item.title[:25]:<25} | No TMDb for Guid: {item.guid}")
continue
try:
tmdb_item = config.TMDb.get_movie(ids["tmdb"]) if library.is_movie else config.TMDb.get_show(ids["tmdb"])
except Failed as e:
util.print_end(length, str(e))
continue
new_genres = [genre.name for genre in tmdb_item.genres]
elif library.mass_genre_update in ["omdb", "imdb"]:
if config.OMDb.limit is True:
tvdb_id = tvdb
break
if "imdb" not in ids:
util.print_end(length, f"{item.title[:25]:<25} | No IMDb for Guid: {item.guid}")
continue
if tmdb_id:
imdb_id = config.Convert.tmdb_to_imdb(tmdb_id)
elif tvdb_id:
tmdb_id = config.Convert.tvdb_to_tmdb(tvdb_id)
imdb_id = config.Convert.tvdb_to_imdb(tvdb_id)
tmdb_item = None
if library.mass_genre_update == "tmdb" or library.mass_audience_rating_update == "tmdb":
if tmdb_id:
try:
omdb_item = config.OMDb.get_omdb(ids["imdb"])
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))
continue
new_genres = omdb_item.genres
else:
raise Failed
item_genres = [genre.tag for genre in item.genres]
display_str = ""
for genre in (g for g in item_genres if g not in new_genres):
library.query_data(item.removeGenre, genre)
display_str += f"{', ' if len(display_str) > 0 else ''}-{genre}"
for genre in (g for g in new_genres if g not in item_genres):
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}")
util.print_end(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"]:
if config.OMDb.limit is False:
if imdb_id:
try:
omdb_item = config.OMDb.get_omdb(imdb_id)
except Failed as e:
util.print_end(length, str(e))
else:
util.print_end(length, f"{item.title[:25]:<25} | No IMDb ID for Guid: {item.guid}")
if not tmdb_item and not omdb_item:
continue
if library.mass_genre_update:
try:
if tmdb_item and library.mass_genre_update == "tmdb":
new_genres = [genre.name for genre in tmdb_item.genres]
elif omdb_item and library.mass_genre_update in ["omdb", "imdb"]:
new_genres = omdb_item.genres
else:
raise Failed
item_genres = [genre.tag for genre in item.genres]
display_str = ""
for genre in (g for g in item_genres if g not in new_genres):
library.query_data(item.removeGenre, genre)
display_str += f"{', ' if len(display_str) > 0 else ''}-{genre}"
for genre in (g for g in new_genres if g not in item_genres):
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}")
except Failed:
pass
if library.mass_audience_rating_update:
if library.mass_audience_rating_update == "tmdb":
if "tmdb" not in ids:
util.print_end(length, f"{item.title[:25]:<25} | No TMDb for Guid: {item.guid}")
continue
try:
tmdb_item = config.TMDb.get_movie(ids["tmdb"]) if library.is_movie else config.TMDb.get_show(ids["tmdb"])
except Failed as e:
util.print_end(length, str(e))
continue
new_rating = tmdb_item.vote_average
elif library.mass_audience_rating_update in ["omdb", "imdb"]:
if config.OMDb.limit is True:
break
if "imdb" not in ids:
util.print_end(length, f"{item.title[:25]:<25} | No IMDb for Guid: {item.guid}")
continue
try:
omdb_item = config.OMDb.get_omdb(ids["imdb"])
except Failed as e:
util.print_end(length, str(e))
continue
new_rating = omdb_item.imdb_rating
else:
raise Failed
if new_rating is None:
util.print_end(length, f"{item.title[:25]:<25} | No Rating Found")
elif 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}")
try:
if tmdb_item and library.mass_genre_update == "tmdb":
new_rating = tmdb_item.vote_average
elif omdb_item and library.mass_genre_update in ["omdb", "imdb"]:
new_rating = omdb_item.imdb_rating
else:
raise Failed
if new_rating is None:
util.print_end(length, f"{item.title[:25]:<25} | No Rating Found")
elif 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}")
except Failed:
pass
def map_guids(config, library):
movie_map = {}

Loading…
Cancel
Save