From fe987babc520020996669cf5ead5e180dda01c96 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Tue, 24 Oct 2023 11:54:59 -0400 Subject: [PATCH] Fixed issues with SQlite older than 3.35. --- bazarr/radarr/sync/movies.py | 16 +++++++--------- bazarr/sonarr/sync/episodes.py | 22 +++++++++------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/bazarr/radarr/sync/movies.py b/bazarr/radarr/sync/movies.py index 17929ffb0..e35d08114 100644 --- a/bazarr/radarr/sync/movies.py +++ b/bazarr/radarr/sync/movies.py @@ -40,8 +40,7 @@ def update_movie(updated_movie, send_event): except IntegrityError as e: logging.error(f"BAZARR cannot update movie {updated_movie['path']} because of {e}") else: - store_subtitles_movie(updated_movie['path'], - path_mappings.path_replace_movie(updated_movie['path'])) + store_subtitles_movie(updated_movie['path'], path_mappings.path_replace_movie(updated_movie['path'])) if send_event: event_stream(type='movie', action='update', payload=updated_movie['radarrId']) @@ -56,8 +55,7 @@ def add_movie(added_movie, send_event): except IntegrityError as e: logging.error(f"BAZARR cannot insert movie {added_movie['path']} because of {e}") else: - store_subtitles_movie(added_movie['path'], - path_mappings.path_replace_movie(added_movie['path'])) + store_subtitles_movie(added_movie['path'], path_mappings.path_replace_movie(added_movie['path'])) if send_event: event_stream(type='movie', action='update', payload=int(added_movie['radarrId'])) @@ -109,15 +107,13 @@ def update_movies(send_event=True): if len(movies_to_delete): try: - removed_movies = database.execute(delete(TableMovies) - .where(TableMovies.tmdbId.in_(movies_to_delete)) - .returning(TableMovies.radarrId)) + database.execute(delete(TableMovies).where(TableMovies.tmdbId.in_(movies_to_delete))) except IntegrityError as e: logging.error(f"BAZARR cannot delete movies because of {e}") else: - for removed_movie in removed_movies: + for removed_movie in movies_to_delete: if send_event: - event_stream(type='movie', action='delete', payload=removed_movie.radarrId) + event_stream(type='movie', action='delete', payload=removed_movie) # Build new and updated movies movies_count = len(movies) @@ -240,6 +236,7 @@ def update_one_movie(movie_id, action, defer_search=False): logging.error(f"BAZARR cannot update movie {path_mappings.path_replace_movie(movie['path'])} because " f"of {e}") else: + store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path'])) event_stream(type='movie', action='update', payload=int(movie_id)) logging.debug( f'BAZARR updated this movie into the database:{path_mappings.path_replace_movie(movie["path"])}') @@ -254,6 +251,7 @@ def update_one_movie(movie_id, action, defer_search=False): logging.error(f"BAZARR cannot insert movie {path_mappings.path_replace_movie(movie['path'])} because " f"of {e}") else: + store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path'])) event_stream(type='movie', action='update', payload=int(movie_id)) logging.debug( f'BAZARR inserted this movie into the database:{path_mappings.path_replace_movie(movie["path"])}') diff --git a/bazarr/sonarr/sync/episodes.py b/bazarr/sonarr/sync/episodes.py index a0e2d0cd8..1ad0f558e 100644 --- a/bazarr/sonarr/sync/episodes.py +++ b/bazarr/sonarr/sync/episodes.py @@ -86,15 +86,13 @@ def sync_episodes(series_id, send_event=True): if len(episodes_to_delete): try: - removed_episodes = database.execute(delete(TableEpisodes) - .where(TableEpisodes.sonarrEpisodeId.in_(episodes_to_delete)) - .returning(TableEpisodes.sonarrEpisodeId)) + database.execute(delete(TableEpisodes).where(TableEpisodes.sonarrEpisodeId.in_(episodes_to_delete))) except IntegrityError as e: logging.error(f"BAZARR cannot delete episodes because of {e}") else: - for removed_episode in removed_episodes: + for removed_episode in episodes_to_delete: if send_event: - event_stream(type='episode', action='delete', payload=removed_episode.sonarrEpisodeId) + event_stream(type='episode', action='delete', payload=removed_episode) # Update existing episodes in DB if len(episodes_to_update): @@ -104,7 +102,6 @@ def sync_episodes(series_id, send_event=True): logging.error(f"BAZARR cannot update episodes because of {e}") else: for updated_episode in episodes_to_update: - # not using .returning() because it's not supported on executemany() with SQlite store_subtitles(updated_episode['path'], path_mappings.path_replace(updated_episode['path'])) if send_event: @@ -113,18 +110,15 @@ def sync_episodes(series_id, send_event=True): # Insert new episodes in DB if len(episodes_to_add): try: - added_episodes = database.execute( - insert(TableEpisodes) - .values(episodes_to_add) - .returning(TableEpisodes.sonarrEpisodeId, TableEpisodes.path, TableEpisodes.sonarrSeriesId)) + database.execute(insert(TableEpisodes).values(episodes_to_add)) except IntegrityError as e: logging.error(f"BAZARR cannot insert episodes because of {e}") else: - for added_episode in added_episodes: - store_subtitles(added_episode.path, path_mappings.path_replace(added_episode.path)) + for added_episode in episodes_to_add: + store_subtitles(added_episode['path'], path_mappings.path_replace(added_episode['path'])) if send_event: - event_stream(type='episode', payload=added_episode.sonarrEpisodeId) + event_stream(type='episode', payload=added_episode['sonarrEpisodeId']) logging.debug(f'BAZARR All episodes from series ID {series_id} synced from Sonarr into database.') @@ -187,6 +181,7 @@ def sync_one_episode(episode_id, defer_search=False): except IntegrityError as e: logging.error(f"BAZARR cannot update episode {episode['path']} because of {e}") else: + store_subtitles(episode['path'], path_mappings.path_replace(episode['path'])) event_stream(type='episode', action='update', payload=int(episode_id)) logging.debug( f'BAZARR updated this episode into the database:{path_mappings.path_replace(episode["path"])}') @@ -200,6 +195,7 @@ def sync_one_episode(episode_id, defer_search=False): except IntegrityError as e: logging.error(f"BAZARR cannot insert episode {episode['path']} because of {e}") else: + store_subtitles(episode['path'], path_mappings.path_replace(episode['path'])) event_stream(type='episode', action='update', payload=int(episode_id)) logging.debug( f'BAZARR inserted this episode into the database:{path_mappings.path_replace(episode["path"])}')