diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 33ec6e1d1..674a756ea 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -127,69 +127,69 @@ def sync_episodes(): 'video_codec': videoCodec, 'audio_codec': audioCodec}) - # Update existing episodes in DB - episode_in_db_list = [] - episodes_in_db = TableEpisodes.select( - TableEpisodes.sonarr_series_id, - TableEpisodes.sonarr_episode_id, - TableEpisodes.title, - TableEpisodes.path, - TableEpisodes.season, - TableEpisodes.episode, - TableEpisodes.scene_name, - TableEpisodes.monitored, - TableEpisodes.format, - TableEpisodes.resolution, - TableEpisodes.video_codec, - TableEpisodes.audio_codec - ).dicts() - - for item in episodes_in_db: - episode_in_db_list.append(item) - - episodes_to_update_list = [i for i in episodes_to_update if i not in episode_in_db_list] - - for updated_episode in episodes_to_update_list: - TableEpisodes.update( - updated_episode - ).where( - TableEpisodes.sonarr_episode_id == updated_episode['sonarr_episode_id'] - ).execute() - altered_episodes.append([updated_episode['sonarr_episode_id'], - updated_episode['path'], - updated_episode['sonarr_series_id']]) - - # Insert new episodes in DB - for added_episode in episodes_to_add: - TableEpisodes.insert( - added_episode - ).on_conflict_ignore().execute() - altered_episodes.append([added_episode['sonarr_episode_id'], - added_episode['path'], - added_episode['sonarr_series_id']]) - - # Remove old episodes from DB - removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) - - for removed_episode in removed_episodes: - TableEpisodes.delete().where( - TableEpisodes.sonarr_episode_id == removed_episode - ).execute() - - # Store subtitles for added or modified episodes - for altered_episode in altered_episodes: - store_subtitles(path_replace(altered_episode[1])) - list_missing_subtitles(altered_episode[2]) - - logging.debug('BAZARR All episodes synced from Sonarr into database.') - - # Search for desired subtitles if no more than 5 episodes have been added. - if len(altered_episodes) <= 5: - logging.debug("BAZARR No more than 5 episodes were added during this sync then we'll search for subtitles.") - for altered_episode in altered_episodes: - episode_download_subtitles(altered_episode[0]) - else: - logging.debug("BAZARR More than 5 episodes were added during this sync then we wont search for subtitles right now.") + # Update existing episodes in DB + episode_in_db_list = [] + episodes_in_db = TableEpisodes.select( + TableEpisodes.sonarr_series_id, + TableEpisodes.sonarr_episode_id, + TableEpisodes.title, + TableEpisodes.path, + TableEpisodes.season, + TableEpisodes.episode, + TableEpisodes.scene_name, + TableEpisodes.monitored, + TableEpisodes.format, + TableEpisodes.resolution, + TableEpisodes.video_codec, + TableEpisodes.audio_codec + ).dicts() + + for item in episodes_in_db: + episode_in_db_list.append(item) + + episodes_to_update_list = [i for i in episodes_to_update if i not in episode_in_db_list] + + for updated_episode in episodes_to_update_list: + TableEpisodes.update( + updated_episode + ).where( + TableEpisodes.sonarr_episode_id == updated_episode['sonarr_episode_id'] + ).execute() + altered_episodes.append([updated_episode['sonarr_episode_id'], + updated_episode['path'], + updated_episode['sonarr_series_id']]) + + # Insert new episodes in DB + for added_episode in episodes_to_add: + TableEpisodes.insert( + added_episode + ).on_conflict_ignore().execute() + altered_episodes.append([added_episode['sonarr_episode_id'], + added_episode['path'], + added_episode['sonarr_series_id']]) + + # Remove old episodes from DB + removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) + + for removed_episode in removed_episodes: + TableEpisodes.delete().where( + TableEpisodes.sonarr_episode_id == removed_episode + ).execute() + + # Store subtitles for added or modified episodes + for altered_episode in altered_episodes: + store_subtitles(path_replace(altered_episode[1])) + list_missing_subtitles(altered_episode[2]) + + logging.debug('BAZARR All episodes synced from Sonarr into database.') + + # Search for desired subtitles if no more than 5 episodes have been added. + if len(altered_episodes) <= 5: + logging.debug("BAZARR No more than 5 episodes were added during this sync then we'll search for subtitles.") + for altered_episode in altered_episodes: + episode_download_subtitles(altered_episode[0]) + else: + logging.debug("BAZARR More than 5 episodes were added during this sync then we wont search for subtitles right now.") def SonarrFormatAudioCodec(audioCodec): diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index 4202fd077..6c2416f0a 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -261,6 +261,8 @@ def update_movies(): store_subtitles_movie(path_replace_movie(altered_movie[1])) list_missing_subtitles_movies(altered_movie[2]) + logging.debug('BAZARR All movies synced from Radarr into database.') + # Search for desired subtitles if no more than 5 movies have been added. if len(altered_movies) <= 5: logging.debug("BAZARR No more than 5 movies were added during this sync then we'll search for subtitles.") @@ -269,8 +271,6 @@ def update_movies(): else: logging.debug("BAZARR More than 5 movies were added during this sync then we wont search for subtitles.") - logging.debug('BAZARR All movies synced from Radarr into database.') - def get_profile_list(): apikey_radarr = settings.radarr.apikey diff --git a/bazarr/get_series.py b/bazarr/get_series.py index fd692d578..a50660dc0 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -161,6 +161,8 @@ def update_series(): TableShows.tvdb_id == series ).execute() + logging.debug('BAZARR All series synced from Sonarr into database.') + def get_profile_list(): apikey_sonarr = settings.sonarr.apikey