|
|
|
@ -2234,179 +2234,183 @@ class CollectionBuilder:
|
|
|
|
|
logger.trace(f"IDs: {ids}")
|
|
|
|
|
logger.debug("")
|
|
|
|
|
for i, input_data in enumerate(ids, 1):
|
|
|
|
|
input_id, id_type = input_data
|
|
|
|
|
logger.ghost(f"Parsing ID {i}/{total_ids}")
|
|
|
|
|
rating_keys = []
|
|
|
|
|
if id_type == "ratingKey":
|
|
|
|
|
rating_keys = int(input_id)
|
|
|
|
|
elif id_type == "imdb":
|
|
|
|
|
if input_id not in self.ignore_imdb_ids:
|
|
|
|
|
found = False
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if input_id in pl_library.imdb_map:
|
|
|
|
|
found = True
|
|
|
|
|
rating_keys = pl_library.imdb_map[input_id]
|
|
|
|
|
break
|
|
|
|
|
if not found and (self.builder_level == "episode" or self.playlist or self.do_missing):
|
|
|
|
|
try:
|
|
|
|
|
_id, tmdb_type = self.config.Convert.imdb_to_tmdb(input_id, fail=True)
|
|
|
|
|
if tmdb_type == "episode" and (self.builder_level == "episode" or self.playlist):
|
|
|
|
|
try:
|
|
|
|
|
tmdb_id, season_num, episode_num = _id.split("_")
|
|
|
|
|
tvdb_id = self.config.Convert.tmdb_to_tvdb(tmdb_id, fail=True)
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
except Failed as e:
|
|
|
|
|
try:
|
|
|
|
|
input_id, id_type = input_data
|
|
|
|
|
logger.ghost(f"Parsing ID {i}/{total_ids}")
|
|
|
|
|
rating_keys = []
|
|
|
|
|
if id_type == "ratingKey":
|
|
|
|
|
rating_keys = int(input_id)
|
|
|
|
|
elif id_type == "imdb":
|
|
|
|
|
if input_id not in self.ignore_imdb_ids:
|
|
|
|
|
found = False
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if input_id in pl_library.imdb_map:
|
|
|
|
|
found = True
|
|
|
|
|
rating_keys = pl_library.imdb_map[input_id]
|
|
|
|
|
break
|
|
|
|
|
if not found and (self.builder_level == "episode" or self.playlist or self.do_missing):
|
|
|
|
|
try:
|
|
|
|
|
_id, tmdb_type = self.config.Convert.imdb_to_tmdb(input_id, fail=True)
|
|
|
|
|
if tmdb_type == "episode" and (self.builder_level == "episode" or self.playlist):
|
|
|
|
|
try:
|
|
|
|
|
if not self.config.OMDb:
|
|
|
|
|
raise Failed("")
|
|
|
|
|
if self.config.OMDb.limit:
|
|
|
|
|
raise Failed(" and OMDb limit reached.")
|
|
|
|
|
omdb_item = self.config.OMDb.get_omdb(input_id)
|
|
|
|
|
tvdb_id = omdb_item.series_id
|
|
|
|
|
season_num = omdb_item.season_num
|
|
|
|
|
episode_num = omdb_item.episode_num
|
|
|
|
|
if not tvdb_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
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if tvdb_id in pl_library.show_map:
|
|
|
|
|
found = True
|
|
|
|
|
show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0])
|
|
|
|
|
tmdb_id, season_num, episode_num = _id.split("_")
|
|
|
|
|
tvdb_id = self.config.Convert.tmdb_to_tvdb(tmdb_id, fail=True)
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
except Failed as e:
|
|
|
|
|
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")
|
|
|
|
|
break
|
|
|
|
|
if not found and tvdb_id not in self.missing_shows and self.do_missing:
|
|
|
|
|
self.missing_shows.append(tvdb_id)
|
|
|
|
|
elif tmdb_type == "movie" and self.do_missing and _id not in self.missing_movies:
|
|
|
|
|
self.missing_movies.append(_id)
|
|
|
|
|
elif tmdb_type in ["show", "episode"] and self.do_missing:
|
|
|
|
|
if tmdb_type == "episode":
|
|
|
|
|
tmdb_id, _, _ = _id.split("_")
|
|
|
|
|
else:
|
|
|
|
|
tmdb_id = _id
|
|
|
|
|
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.warning(e)
|
|
|
|
|
continue
|
|
|
|
|
elif id_type == "tmdb" and not self.parts_collection:
|
|
|
|
|
input_id = int(input_id)
|
|
|
|
|
if input_id not in self.ignore_ids:
|
|
|
|
|
if not self.config.OMDb:
|
|
|
|
|
raise Failed("")
|
|
|
|
|
if self.config.OMDb.limit:
|
|
|
|
|
raise Failed(" and OMDb limit reached.")
|
|
|
|
|
omdb_item = self.config.OMDb.get_omdb(input_id)
|
|
|
|
|
tvdb_id = omdb_item.series_id
|
|
|
|
|
season_num = omdb_item.season_num
|
|
|
|
|
episode_num = omdb_item.episode_num
|
|
|
|
|
if not tvdb_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
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if tvdb_id in pl_library.show_map:
|
|
|
|
|
found = True
|
|
|
|
|
show_item = pl_library.fetch_item(pl_library.show_map[tvdb_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")
|
|
|
|
|
break
|
|
|
|
|
if not found and tvdb_id not in self.missing_shows and self.do_missing:
|
|
|
|
|
self.missing_shows.append(tvdb_id)
|
|
|
|
|
elif tmdb_type == "movie" and self.do_missing and _id not in self.missing_movies:
|
|
|
|
|
self.missing_movies.append(_id)
|
|
|
|
|
elif tmdb_type in ["show", "episode"] and self.do_missing:
|
|
|
|
|
if tmdb_type == "episode":
|
|
|
|
|
tmdb_id, _, _ = _id.split("_")
|
|
|
|
|
else:
|
|
|
|
|
tmdb_id = _id
|
|
|
|
|
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.warning(e)
|
|
|
|
|
continue
|
|
|
|
|
elif id_type == "tmdb" and not self.parts_collection:
|
|
|
|
|
input_id = int(input_id)
|
|
|
|
|
if input_id not in self.ignore_ids:
|
|
|
|
|
found = False
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if input_id in pl_library.movie_map:
|
|
|
|
|
found = True
|
|
|
|
|
rating_keys = pl_library.movie_map[input_id]
|
|
|
|
|
break
|
|
|
|
|
if not found and input_id not in self.missing_movies:
|
|
|
|
|
self.missing_movies.append(input_id)
|
|
|
|
|
elif id_type == "tvdb_season" and (self.builder_level == "season" or self.playlist):
|
|
|
|
|
tvdb_id, season_num = input_id.split("_")
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
found = False
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if input_id in pl_library.movie_map:
|
|
|
|
|
if tvdb_id in pl_library.show_map:
|
|
|
|
|
found = True
|
|
|
|
|
rating_keys = pl_library.movie_map[input_id]
|
|
|
|
|
show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0])
|
|
|
|
|
try:
|
|
|
|
|
season_obj = show_item.season(season=int(season_num))
|
|
|
|
|
if self.playlist:
|
|
|
|
|
items.extend(season_obj.episodes())
|
|
|
|
|
else:
|
|
|
|
|
items.append(season_obj)
|
|
|
|
|
except NotFound:
|
|
|
|
|
self.missing_parts.append(f"{show_item.title} Season: {season_num} Missing")
|
|
|
|
|
break
|
|
|
|
|
if not found and input_id not in self.missing_movies:
|
|
|
|
|
self.missing_movies.append(input_id)
|
|
|
|
|
elif id_type == "tvdb_season" and (self.builder_level == "season" or self.playlist):
|
|
|
|
|
tvdb_id, season_num = input_id.split("_")
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
found = False
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if tvdb_id in pl_library.show_map:
|
|
|
|
|
found = True
|
|
|
|
|
show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0])
|
|
|
|
|
try:
|
|
|
|
|
season_obj = show_item.season(season=int(season_num))
|
|
|
|
|
if self.playlist:
|
|
|
|
|
items.extend(season_obj.episodes())
|
|
|
|
|
else:
|
|
|
|
|
items.append(season_obj)
|
|
|
|
|
except NotFound:
|
|
|
|
|
self.missing_parts.append(f"{show_item.title} Season: {season_num} Missing")
|
|
|
|
|
break
|
|
|
|
|
if not found and tvdb_id not in self.missing_shows:
|
|
|
|
|
self.missing_shows.append(tvdb_id)
|
|
|
|
|
elif id_type == "tvdb_episode" and (self.builder_level == "episode" or self.playlist):
|
|
|
|
|
tvdb_id, season_num, episode_num = input_id.split("_")
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
found = False
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if tvdb_id in pl_library.show_map:
|
|
|
|
|
found = True
|
|
|
|
|
show_item = pl_library.fetch_item(pl_library.show_map[tvdb_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")
|
|
|
|
|
if not found and tvdb_id not in self.missing_shows and self.do_missing:
|
|
|
|
|
self.missing_shows.append(tvdb_id)
|
|
|
|
|
elif id_type in ["tvdb", "tmdb_show", "tvdb_season", "tvdb_episode"]:
|
|
|
|
|
tvdb_season = None
|
|
|
|
|
if id_type == "tmdb_show":
|
|
|
|
|
try:
|
|
|
|
|
tvdb_id = self.config.Convert.tmdb_to_tvdb(input_id, fail=True)
|
|
|
|
|
except Failed as e:
|
|
|
|
|
logger.warning(e)
|
|
|
|
|
continue
|
|
|
|
|
elif id_type == "tvdb_season":
|
|
|
|
|
tvdb_id, tvdb_season = input_id.split("_")
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
tvdb_season = int(tvdb_season)
|
|
|
|
|
elif id_type == "tvdb_episode":
|
|
|
|
|
tvdb_id, _, _ = input_id.split("_")
|
|
|
|
|
if not found and tvdb_id not in self.missing_shows:
|
|
|
|
|
self.missing_shows.append(tvdb_id)
|
|
|
|
|
elif id_type == "tvdb_episode" and (self.builder_level == "episode" or self.playlist):
|
|
|
|
|
tvdb_id, season_num, episode_num = input_id.split("_")
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
else:
|
|
|
|
|
tvdb_id = int(input_id)
|
|
|
|
|
if tvdb_id not in self.ignore_ids:
|
|
|
|
|
found_keys = None
|
|
|
|
|
found = False
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if tvdb_id in pl_library.show_map:
|
|
|
|
|
found_keys = pl_library.show_map[tvdb_id]
|
|
|
|
|
break
|
|
|
|
|
if not found_keys and tvdb_id not in self.missing_shows:
|
|
|
|
|
found = True
|
|
|
|
|
show_item = pl_library.fetch_item(pl_library.show_map[tvdb_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")
|
|
|
|
|
if not found and tvdb_id not in self.missing_shows and self.do_missing:
|
|
|
|
|
self.missing_shows.append(tvdb_id)
|
|
|
|
|
if found_keys:
|
|
|
|
|
if self.parts_collection:
|
|
|
|
|
rating_keys = []
|
|
|
|
|
for rk in found_keys:
|
|
|
|
|
try:
|
|
|
|
|
item = self.library.fetch_item(rk)
|
|
|
|
|
if self.builder_level == "episode" and isinstance(item, Show):
|
|
|
|
|
if tvdb_season is not None:
|
|
|
|
|
item = item.season(season=tvdb_season)
|
|
|
|
|
rating_keys.extend([k.ratingKey for k in item.episodes()])
|
|
|
|
|
elif self.builder_level == "season" and isinstance(item, Show):
|
|
|
|
|
rating_keys.extend([k.ratingKey for k in item.seasons()])
|
|
|
|
|
except Failed as e:
|
|
|
|
|
logger.error(e)
|
|
|
|
|
else:
|
|
|
|
|
rating_keys = found_keys
|
|
|
|
|
else:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if not isinstance(rating_keys, list):
|
|
|
|
|
rating_keys = [rating_keys]
|
|
|
|
|
for rk in rating_keys:
|
|
|
|
|
try:
|
|
|
|
|
item = self.library.fetch_item(rk)
|
|
|
|
|
if self.playlist and isinstance(item, (Show, Season)):
|
|
|
|
|
items.extend(item.episodes())
|
|
|
|
|
elif self.builder_level == "movie" and not isinstance(item, Movie):
|
|
|
|
|
logger.info(f"Item: {item} is not an Movie")
|
|
|
|
|
elif self.builder_level == "show" and not isinstance(item, Show):
|
|
|
|
|
logger.info(f"Item: {item} is not an Show")
|
|
|
|
|
elif self.builder_level == "episode" and not isinstance(item, Episode):
|
|
|
|
|
logger.info(f"Item: {item} is not an Episode")
|
|
|
|
|
elif self.builder_level == "season" and not isinstance(item, Season):
|
|
|
|
|
logger.info(f"Item: {item} is not a Season")
|
|
|
|
|
elif self.builder_level == "artist" and not isinstance(item, Artist):
|
|
|
|
|
logger.info(f"Item: {item} is not an Artist")
|
|
|
|
|
elif self.builder_level == "album" and not isinstance(item, Album):
|
|
|
|
|
logger.info(f"Item: {item} is not an Album")
|
|
|
|
|
elif self.builder_level == "track" and not isinstance(item, Track):
|
|
|
|
|
logger.info(f"Item: {item} is not a Track")
|
|
|
|
|
elif id_type in ["tvdb", "tmdb_show", "tvdb_season", "tvdb_episode"]:
|
|
|
|
|
tvdb_season = None
|
|
|
|
|
if id_type == "tmdb_show":
|
|
|
|
|
try:
|
|
|
|
|
tvdb_id = self.config.Convert.tmdb_to_tvdb(input_id, fail=True)
|
|
|
|
|
except Failed as e:
|
|
|
|
|
logger.warning(e)
|
|
|
|
|
continue
|
|
|
|
|
elif id_type == "tvdb_season":
|
|
|
|
|
tvdb_id, tvdb_season = input_id.split("_")
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
tvdb_season = int(tvdb_season)
|
|
|
|
|
elif id_type == "tvdb_episode":
|
|
|
|
|
tvdb_id, _, _ = input_id.split("_")
|
|
|
|
|
tvdb_id = int(tvdb_id)
|
|
|
|
|
else:
|
|
|
|
|
items.append(item)
|
|
|
|
|
except Failed as e:
|
|
|
|
|
logger.error(e)
|
|
|
|
|
tvdb_id = int(input_id)
|
|
|
|
|
if tvdb_id not in self.ignore_ids:
|
|
|
|
|
found_keys = None
|
|
|
|
|
for pl_library in self.libraries:
|
|
|
|
|
if tvdb_id in pl_library.show_map:
|
|
|
|
|
found_keys = pl_library.show_map[tvdb_id]
|
|
|
|
|
break
|
|
|
|
|
if not found_keys and tvdb_id not in self.missing_shows:
|
|
|
|
|
self.missing_shows.append(tvdb_id)
|
|
|
|
|
if found_keys:
|
|
|
|
|
if self.parts_collection:
|
|
|
|
|
rating_keys = []
|
|
|
|
|
for rk in found_keys:
|
|
|
|
|
try:
|
|
|
|
|
item = self.library.fetch_item(rk)
|
|
|
|
|
if self.builder_level == "episode" and isinstance(item, Show):
|
|
|
|
|
if tvdb_season is not None:
|
|
|
|
|
item = item.season(season=tvdb_season)
|
|
|
|
|
rating_keys.extend([k.ratingKey for k in item.episodes()])
|
|
|
|
|
elif self.builder_level == "season" and isinstance(item, Show):
|
|
|
|
|
rating_keys.extend([k.ratingKey for k in item.seasons()])
|
|
|
|
|
except Failed as e:
|
|
|
|
|
logger.error(e)
|
|
|
|
|
else:
|
|
|
|
|
rating_keys = found_keys
|
|
|
|
|
else:
|
|
|
|
|
continue
|
|
|
|
|
if not isinstance(rating_keys, list):
|
|
|
|
|
rating_keys = [rating_keys]
|
|
|
|
|
for rk in rating_keys:
|
|
|
|
|
try:
|
|
|
|
|
item = self.library.fetch_item(rk)
|
|
|
|
|
if self.playlist and isinstance(item, (Show, Season)):
|
|
|
|
|
items.extend(item.episodes())
|
|
|
|
|
elif self.builder_level == "movie" and not isinstance(item, Movie):
|
|
|
|
|
logger.info(f"Item: {item} is not an Movie")
|
|
|
|
|
elif self.builder_level == "show" and not isinstance(item, Show):
|
|
|
|
|
logger.info(f"Item: {item} is not an Show")
|
|
|
|
|
elif self.builder_level == "episode" and not isinstance(item, Episode):
|
|
|
|
|
logger.info(f"Item: {item} is not an Episode")
|
|
|
|
|
elif self.builder_level == "season" and not isinstance(item, Season):
|
|
|
|
|
logger.info(f"Item: {item} is not a Season")
|
|
|
|
|
elif self.builder_level == "artist" and not isinstance(item, Artist):
|
|
|
|
|
logger.info(f"Item: {item} is not an Artist")
|
|
|
|
|
elif self.builder_level == "album" and not isinstance(item, Album):
|
|
|
|
|
logger.info(f"Item: {item} is not an Album")
|
|
|
|
|
elif self.builder_level == "track" and not isinstance(item, Track):
|
|
|
|
|
logger.info(f"Item: {item} is not a Track")
|
|
|
|
|
else:
|
|
|
|
|
items.append(item)
|
|
|
|
|
except Failed as e:
|
|
|
|
|
logger.error(e)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.stacktrace()
|
|
|
|
|
logger.error(e)
|
|
|
|
|
logger.info(input_data)
|
|
|
|
|
logger.exorcise()
|
|
|
|
|
if not items:
|
|
|
|
|
return None
|
|
|
|
|