diff options
author | morpheus65535 <[email protected]> | 2024-10-12 16:45:05 -0400 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2024-10-12 16:45:05 -0400 |
commit | 4b9417c2e280ee42853c56ad14580be4dab48cfe (patch) | |
tree | 7a82af2e532f5e670cb0b56e2b04fdfbb5302745 | |
parent | 74249eeb4c826f55fc3ffa966c2d3881b9372c14 (diff) | |
download | bazarr-4b9417c2e280ee42853c56ad14580be4dab48cfe.tar.gz bazarr-4b9417c2e280ee42853c56ad14580be4dab48cfe.zip |
Fixed error while inserting episodes during sync process. #2700
-rw-r--r-- | bazarr/sonarr/sync/episodes.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/bazarr/sonarr/sync/episodes.py b/bazarr/sonarr/sync/episodes.py index ed1679ff8..b6979ad30 100644 --- a/bazarr/sonarr/sync/episodes.py +++ b/bazarr/sonarr/sync/episodes.py @@ -145,6 +145,20 @@ def sync_episodes(series_id, send_event=True): if send_event: event_stream(type='episode', action='delete', payload=removed_episode) + # Insert new episodes in DB + if len(episodes_to_add): + for added_episode in episodes_to_add: + try: + database.execute(insert(TableEpisodes).values(added_episode)) + except IntegrityError as e: + logging.error(f"BAZARR cannot insert episodes because of {e}. We'll try to update it instead.") + episodes_to_update.append(added_episode) + else: + store_subtitles(added_episode['path'], path_mappings.path_replace(added_episode['path'])) + + if send_event: + event_stream(type='episode', payload=added_episode['sonarrEpisodeId']) + # Update existing episodes in DB if len(episodes_to_update): for updated_episode in episodes_to_update: @@ -160,19 +174,6 @@ def sync_episodes(series_id, send_event=True): if send_event: event_stream(type='episode', action='update', payload=updated_episode['sonarrEpisodeId']) - # Insert new episodes in DB - if len(episodes_to_add): - for added_episode in episodes_to_add: - try: - database.execute(insert(TableEpisodes).values(added_episode)) - except IntegrityError as e: - logging.error(f"BAZARR cannot insert episodes because of {e}") - else: - store_subtitles(added_episode['path'], path_mappings.path_replace(added_episode['path'])) - - if send_event: - event_stream(type='episode', payload=added_episode['sonarrEpisodeId']) - logging.debug(f'BAZARR All episodes from series ID {series_id} synced from Sonarr into database.') |