Skip to content

Commit 0374b9f

Browse files
committed
Improved subtitle update logic in movie sync to handle changes in path or movie_file_id only.
1 parent a365d4a commit 0374b9f

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

bazarr/radarr/sync/movies.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,32 @@ def get_movie_file_size_from_db(movie_path):
5050
# Update movies in DB
5151
def update_movie(updated_movie):
5252
try:
53+
previous_movie_data = database.execute(
54+
select(TableMovies.movie_file_id, TableMovies.path)
55+
.where(TableMovies.radarrId == updated_movie['radarrId'])
56+
).first()
57+
58+
previous_movie_id = updated_movie['radarrId']
59+
previous_movie_file_id = previous_movie_data.movie_file_id
60+
previous_movie_path = previous_movie_data.path
61+
5362
updated_movie['updated_at_timestamp'] = datetime.now()
5463
database.execute(
5564
update(TableMovies).values(updated_movie)
5665
.where(TableMovies.radarrId == updated_movie['radarrId']))
5766
except IntegrityError as e:
5867
logging.error(f"BAZARR cannot update movie {updated_movie['path']} because of {e}")
5968
else:
60-
store_subtitles_movie(updated_movie['path'], path_mappings.path_replace_movie(updated_movie['path']))
61-
event_stream(type='movie', action='update', payload=updated_movie['radarrId'])
69+
if (previous_movie_file_id != updated_movie['movie_file_id'] or
70+
previous_movie_path != updated_movie['path']):
71+
# Store subtitles for updated movie where path or movie_file_id changed
72+
logging.debug(f'BAZARR updating subtitles for movie {updated_movie["path"]}')
73+
store_subtitles_movie(updated_movie['path'], path_mappings.path_replace_movie(updated_movie['path']))
74+
else:
75+
logging.debug(f'BAZARR skipping subtitle update for movie {updated_movie["path"]} as path '
76+
f'and movie_file_id unchanged')
77+
78+
event_stream(type='movie', action='update', payload=previous_movie_id)
6279

6380

6481
def get_movie_monitored_status(movie_id):

0 commit comments

Comments
 (0)