diff --git a/modules/builder.py b/modules/builder.py index 2f4236cc..5dfa8f26 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -1308,27 +1308,50 @@ class CollectionBuilder: elif id_type in ["tvdb_episode", "imdb"] and self.collection_level == "episode": if id_type == "tvdb_episode": show_id, season_num, episode_num = input_id.split("_") + show_id = int(show_id) elif id_type == "imdb" and input_id not in self.ignore_imdb_ids: try: _id, tmdb_type = self.config.Convert.imdb_to_tmdb(input_id, fail=True) if tmdb_type != "episode": - continue + raise Failed tmdb_id, season_num, episode_num = _id.split("_") show_id = self.config.Convert.tmdb_to_tvdb(tmdb_id, fail=True) except Failed as e: - logger.error(e) - continue + if self.config.OMDb: + try: + if self.config.OMDb.limit: + raise Failed(f" and OMDb limit reached.") + omdb_item = self.config.OMDb.get_omdb(input_id) + show_id = omdb_item.series_id + season_num = omdb_item.season_num + episode_num = omdb_item.episode_num + if not show_id or not season_num or not episode_num: + raise Failed(f" and OMDb metadata lookup Failed for IMDb ID: {input_id}") + except Failed as ee: + logger.error(f"{e}{ee}") + continue + else: + logger.error(e) + continue else: continue - show_id = int(show_id) - if show_id in self.library.show_map: - show_item = self.library.fetchItem(self.library.show_map[show_id][0]) + if show_id in self.library.show_map or show_id in self.library.imdb_map: + show_item = self.library.fetchItem(self.library.show_map[show_id][0] if show_id in self.library.show_map else self.library.imdb_map[show_id][0]) try: items.append(show_item.episode(season=int(season_num), episode=int(episode_num))) except NotFound: self.missing_parts.append(f"{show_item.title} Season: {season_num} Episode: {episode_num} Missing") - elif show_id not in self.missing_shows: - self.missing_shows.append(show_id) + else: + if isinstance(show_id, str) and self.do_missing: + try: + tmdb_id, _ = self.config.Convert.imdb_to_tmdb(input_id, fail=True) + tvdb_id = self.config.Convert.tmdb_to_tvdb(tmdb_id, fail=True) + if tvdb_id not in self.missing_shows: + self.missing_shows.append(tvdb_id) + except Failed as e: + logger.error(e) + elif show_id not in self.missing_shows: + self.missing_shows.append(show_id) else: rating_keys = [] if id_type == "ratingKey": diff --git a/modules/cache.py b/modules/cache.py index b5fd7067..ef7709de 100644 --- a/modules/cache.py +++ b/modules/cache.py @@ -22,6 +22,7 @@ class Cache: cursor.execute("DROP TABLE IF EXISTS imdb_to_tvdb_map") cursor.execute("DROP TABLE IF EXISTS tmdb_to_tvdb_map") cursor.execute("DROP TABLE IF EXISTS imdb_map") + cursor.execute("DROP TABLE IF EXISTS omdb_data") cursor.execute( """CREATE TABLE IF NOT EXISTS guids_map ( key INTEGER PRIMARY KEY, @@ -69,7 +70,7 @@ class Cache: expiration_date TEXT)""" ) cursor.execute( - """CREATE TABLE IF NOT EXISTS omdb_data ( + """CREATE TABLE IF NOT EXISTS omdb_data2 ( key INTEGER PRIMARY KEY, imdb_id TEXT UNIQUE, title TEXT, @@ -80,6 +81,9 @@ class Cache: imdb_votes INTEGER, metacritic_rating INTEGER, type TEXT, + series_id TEXT, + season_num INTEGER, + episode_num INTEGER, expiration_date TEXT)""" ) cursor.execute( @@ -235,7 +239,7 @@ class Cache: with sqlite3.connect(self.cache_path) as connection: connection.row_factory = sqlite3.Row with closing(connection.cursor()) as cursor: - cursor.execute("SELECT * FROM omdb_data WHERE imdb_id = ?", (imdb_id,)) + cursor.execute("SELECT * FROM omdb_data2 WHERE imdb_id = ?", (imdb_id,)) row = cursor.fetchone() if row: omdb_dict["imdbID"] = row["imdb_id"] if row["imdb_id"] else None @@ -247,6 +251,9 @@ class Cache: omdb_dict["imdbVotes"] = row["imdb_votes"] if row["imdb_votes"] else None omdb_dict["Metascore"] = row["metacritic_rating"] if row["metacritic_rating"] else None omdb_dict["Type"] = row["type"] if row["type"] else None + omdb_dict["seriesID"] = row["series_id"] if row["series_id"] else None + omdb_dict["Season"] = row["season_num"] if row["season_num"] else None + omdb_dict["Episode"] = row["episode_num"] if row["episode_num"] else None omdb_dict["Response"] = "True" datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d") time_between_insertion = datetime.now() - datetime_object @@ -258,9 +265,14 @@ class Cache: 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 omdb_data(imdb_id) VALUES(?)", (omdb.imdb_id,)) - update_sql = "UPDATE omdb_data SET title = ?, year = ?, content_rating = ?, genres = ?, imdb_rating = ?, imdb_votes = ?, metacritic_rating = ?, type = ?, expiration_date = ? WHERE imdb_id = ?" - cursor.execute(update_sql, (omdb.title, omdb.year, omdb.content_rating, omdb.genres_str, omdb.imdb_rating, omdb.imdb_votes, omdb.metacritic_rating, omdb.type, expiration_date.strftime("%Y-%m-%d"), omdb.imdb_id)) + cursor.execute("INSERT OR IGNORE INTO omdb_data2(imdb_id) VALUES(?)", (omdb.imdb_id,)) + update_sql = "UPDATE omdb_data2 SET title = ?, year = ?, content_rating = ?, genres = ?, " \ + "imdb_rating = ?, imdb_votes = ?, metacritic_rating = ?, type = ?, series_id = ?, " \ + "season_num = ?, episode_num = ?, expiration_date = ? WHERE imdb_id = ?" + cursor.execute(update_sql, (omdb.title, omdb.year, omdb.content_rating, omdb.genres_str, + omdb.imdb_rating, omdb.imdb_votes, omdb.metacritic_rating, omdb.type, + omdb.series_id, omdb.season_num, omdb.episode_num, + expiration_date.strftime("%Y-%m-%d"), omdb.imdb_id)) def query_anime_map(self, anime_id, id_type): ids = None diff --git a/modules/omdb.py b/modules/omdb.py index e8d95a75..4b44f464 100644 --- a/modules/omdb.py +++ b/modules/omdb.py @@ -34,6 +34,19 @@ class OMDbObj: self.metacritic_rating = None self.imdb_id = data["imdbID"] self.type = data["Type"] + try: + self.series_id = data["seriesID"] + except (ValueError, TypeError, KeyError): + self.series_id = None + try: + self.season_num = int(data["Season"]) + except (ValueError, TypeError, KeyError): + self.season_num = None + try: + self.episode_num = int(data["Episode"]) + except (ValueError, TypeError, KeyError): + self.episode_num = None + class OMDb: def __init__(self, config, params):