reorg ratingkeys

pull/509/head
meisnate12 3 years ago
parent d866c0e3af
commit 6a53772f48

@ -1348,7 +1348,7 @@ class CollectionBuilder:
logger.debug("") logger.debug("")
logger.debug(f"Builder: {method}: {value}") logger.debug(f"Builder: {method}: {value}")
logger.info("") logger.info("")
rating_keys = [] items = []
ids = self.gather_ids(method, value) ids = self.gather_ids(method, value)
if len(ids) > 0: if len(ids) > 0:
total_ids = len(ids) total_ids = len(ids)
@ -1357,12 +1357,37 @@ class CollectionBuilder:
for i, input_data in enumerate(ids, 1): for i, input_data in enumerate(ids, 1):
input_id, id_type = input_data input_id, id_type = input_data
util.print_return(f"Parsing ID {i}/{total_ids}") util.print_return(f"Parsing ID {i}/{total_ids}")
if id_type == "tvdb_season" and self.collection_level == "season":
show_id, season_num = input_id.split("_")
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])
try:
items.append(show_item.season(season=int(season_num)))
except NotFound:
self.missing_parts.append(f"{show_item.title} Season: {season_num} Missing")
elif show_id not in self.missing_shows:
self.missing_shows.append(show_id)
elif id_type == "tvdb_episode" and self.collection_level == "episode":
show_id, season_num, episode_num = input_id.split("_")
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])
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:
rating_keys = []
if id_type == "ratingKey": if id_type == "ratingKey":
rating_keys.append(input_id) rating_keys = input_id
elif id_type == "tmdb" and not self.parts_collection: elif id_type == "tmdb" and not self.parts_collection:
if input_id not in self.ignore_ids: if input_id not in self.ignore_ids:
if input_id in self.library.movie_map: if input_id in self.library.movie_map:
rating_keys.extend(self.library.movie_map[input_id]) rating_keys = self.library.movie_map[input_id]
elif input_id not in self.missing_movies: elif input_id not in self.missing_movies:
self.missing_movies.append(input_id) self.missing_movies.append(input_id)
elif id_type in ["tvdb", "tmdb_show"] and not self.parts_collection: elif id_type in ["tvdb", "tmdb_show"] and not self.parts_collection:
@ -1374,13 +1399,13 @@ class CollectionBuilder:
continue continue
if input_id not in self.ignore_ids: if input_id not in self.ignore_ids:
if input_id in self.library.show_map: if input_id in self.library.show_map:
rating_keys.extend(self.library.show_map[input_id]) rating_keys = self.library.show_map[input_id]
elif input_id not in self.missing_shows: elif input_id not in self.missing_shows:
self.missing_shows.append(input_id) self.missing_shows.append(input_id)
elif id_type == "imdb" and not self.parts_collection: elif id_type == "imdb" and not self.parts_collection:
if input_id not in self.ignore_imdb_ids: if input_id not in self.ignore_imdb_ids:
if input_id in self.library.imdb_map: if input_id in self.library.imdb_map:
rating_keys.extend(self.library.imdb_map[input_id]) rating_keys = self.library.imdb_map[input_id]
elif self.do_missing: elif self.do_missing:
try: try:
tmdb_id, tmdb_type = self.config.Convert.imdb_to_tmdb(input_id, fail=True) tmdb_id, tmdb_type = self.config.Convert.imdb_to_tmdb(input_id, fail=True)
@ -1394,59 +1419,41 @@ class CollectionBuilder:
except Failed as e: except Failed as e:
logger.error(e) logger.error(e)
continue continue
elif id_type == "tvdb_season" and self.collection_level == "season": if not isinstance(rating_keys, list):
show_id, season_num = input_id.split("_") rating_keys = [rating_keys]
show_id = int(show_id) for rk in rating_keys:
if show_id in self.library.show_map:
show_item = self.library.fetchItem(self.library.show_map[show_id][0])
try:
season_item = show_item.season(season=int(season_num))
rating_keys.append(season_item.ratingKey)
except NotFound:
self.missing_parts.append(f"{show_item.title} Season: {season_num} Missing")
elif show_id not in self.missing_shows:
self.missing_shows.append(show_id)
elif id_type == "tvdb_episode" and self.collection_level == "episode":
show_id, season_num, episode_num = input_id.split("_")
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])
try: try:
episode_item = show_item.episode(season=int(season_num), episode=int(episode_num)) items.append(self.fetch_item(rk))
rating_keys.append(episode_item.ratingKey) except Failed as e:
except NotFound: logger.error(e)
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)
util.print_end() util.print_end()
if len(rating_keys) > 0: if len(items) > 0:
self.filter_and_save_items(items)
def filter_and_save_items(self, items):
name = self.obj.title if self.obj else self.name name = self.obj.title if self.obj else self.name
if not isinstance(rating_keys, list): total = len(items)
rating_keys = [rating_keys]
total = len(rating_keys)
max_length = len(str(total)) max_length = len(str(total))
if (self.filters or self.tmdb_filters) and self.details["show_filtered"] is True: if (self.filters or self.tmdb_filters) and self.details["show_filtered"] is True:
logger.info("") logger.info("")
logger.info("Filtering Builder:") logger.info("Filtering Builders:")
for i, key in enumerate(rating_keys, 1): for i, item in enumerate(items, 1):
if key not in self.rating_keys: if not isinstance(item, (Movie, Show, Season, Episode)):
if key in self.filtered_keys: logger.error(f"{self.Type} Error: Item: {item} must be Movie, Show, Season, or Episode")
continue
if item.ratingKey not in self.rating_keys:
if item.ratingKey in self.filtered_keys:
if self.details["show_filtered"] is True: if self.details["show_filtered"] is True:
logger.info(f"{name} Collection | X | {self.filtered_keys[key]}") logger.info(f"{name} {self.Type} | X | {self.filtered_keys[item.ratingKey]}")
else: else:
try: current_title = self.item_title(item)
current = self.fetch_item(key) if self.check_filters(item, f"{(' ' * (max_length - len(str(i))))}{i}/{total}"):
except Failed as e: self.rating_keys.append(item.ratingKey)
logger.error(e)
continue
current_title = self.item_title(current)
if self.check_filters(current, f"{(' ' * (max_length - len(str(i))))}{i}/{total}"):
self.rating_keys.append(key)
else: else:
self.filtered_keys[key] = current_title self.filtered_keys[item.ratingKey] = current_title
if self.details["show_filtered"] is True: if self.details["show_filtered"] is True:
logger.info(f"{name} Collection | X | {current_title}") logger.info(f"{name} {self.Type} | X | {current_title}")
def build_filter(self, method, plex_filter, smart=False, type_override=None): def build_filter(self, method, plex_filter, smart=False, type_override=None):
if smart: if smart:

@ -778,11 +778,11 @@ try:
while True: while True:
schedule.run_pending() schedule.run_pending()
if not no_countdown: if not no_countdown:
current = datetime.now().strftime("%H:%M") current_time = datetime.now().strftime("%H:%M")
seconds = None seconds = None
og_time_str = "" og_time_str = ""
for time_to_run in valid_times: for time_to_run in valid_times:
new_seconds = (datetime.strptime(time_to_run, "%H:%M") - datetime.strptime(current, "%H:%M")).total_seconds() new_seconds = (datetime.strptime(time_to_run, "%H:%M") - datetime.strptime(current_time, "%H:%M")).total_seconds()
if new_seconds < 0: if new_seconds < 0:
new_seconds += 86400 new_seconds += 86400
if (seconds is None or new_seconds < seconds) and new_seconds > 0: if (seconds is None or new_seconds < seconds) and new_seconds > 0:
@ -793,7 +793,7 @@ try:
minutes = int((seconds % 3600) // 60) minutes = int((seconds % 3600) // 60)
time_str = f"{hours} Hour{'s' if hours > 1 else ''} and " if hours > 0 else "" time_str = f"{hours} Hour{'s' if hours > 1 else ''} and " if hours > 0 else ""
time_str += f"{minutes} Minute{'s' if minutes > 1 else ''}" time_str += f"{minutes} Minute{'s' if minutes > 1 else ''}"
util.print_return(f"Current Time: {current} | {time_str} until the next run at {og_time_str} | Runs: {', '.join(times_to_run)}") util.print_return(f"Current Time: {current_time} | {time_str} until the next run at {og_time_str} | Runs: {', '.join(times_to_run)}")
else: else:
logger.error(f"Time Error: {valid_times}") logger.error(f"Time Error: {valid_times}")
time.sleep(60) time.sleep(60)

Loading…
Cancel
Save