Fix for episodes being removed from DB if connection to Sonarr fail.

pull/543/head
Louis Vézina 5 years ago
parent 94474e8eae
commit 90609b6433

@ -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):

@ -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

@ -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

Loading…
Cancel
Save