diff options
-rw-r--r-- | bazarr/api/episodes/history.py | 2 | ||||
-rw-r--r-- | bazarr/api/movies/history.py | 2 | ||||
-rw-r--r-- | bazarr/subtitles/upgrade.py | 15 |
3 files changed, 14 insertions, 5 deletions
diff --git a/bazarr/api/episodes/history.py b/bazarr/api/episodes/history.py index 026397363..6ea13fb48 100644 --- a/bazarr/api/episodes/history.py +++ b/bazarr/api/episodes/history.py @@ -129,7 +129,7 @@ class EpisodesHistory(Resource): 'provider': x.provider, 'matches': x.matched, 'dont_matches': x.not_matched, - 'external_subtitles': [y[1] for y in ast.literal_eval(x.external_subtitles) if y[1]], + 'external_subtitles': [ast.literal_eval(f'"{y[1]}"') for y in ast.literal_eval(x.external_subtitles) if y[1]], 'upgradable': bool(x.upgradable) if _language_still_desired(x.language, x.profileId) else False, 'blacklisted': bool(x.blacklisted), } for x in database.execute(stmt).all()] diff --git a/bazarr/api/movies/history.py b/bazarr/api/movies/history.py index d7e7d6783..a5c4a802c 100644 --- a/bazarr/api/movies/history.py +++ b/bazarr/api/movies/history.py @@ -120,7 +120,7 @@ class MoviesHistory(Resource): 'video_path': x.video_path, 'matches': x.matched, 'dont_matches': x.not_matched, - 'external_subtitles': [y[1] for y in ast.literal_eval(x.external_subtitles) if y[1]], + 'external_subtitles': [ast.literal_eval(f'"{y[1]}"') for y in ast.literal_eval(x.external_subtitles) if y[1]], 'upgradable': bool(x.upgradable) if _language_still_desired(x.language, x.profileId) else False, 'blacklisted': bool(x.blacklisted), } for x in database.execute(stmt).all()] diff --git a/bazarr/subtitles/upgrade.py b/bazarr/subtitles/upgrade.py index d094d7caa..8c2f3f5b6 100644 --- a/bazarr/subtitles/upgrade.py +++ b/bazarr/subtitles/upgrade.py @@ -45,7 +45,7 @@ def upgrade_subtitles(): 'subtitles_path': x.subtitles_path, 'path': x.path, 'profileId': x.profileId, - 'external_subtitles': [y[1] for y in ast.literal_eval(x.external_subtitles) if y[1]], + 'external_subtitles': [ast.literal_eval(f'"{y[1]}"') for y in ast.literal_eval(x.external_subtitles) if y[1]], 'upgradable': bool(x.upgradable), } for x in database.execute( select(TableHistory.id, @@ -76,6 +76,11 @@ def upgrade_subtitles(): ] for item in episodes_data: + # do not consider subtitles that do not exist on disk anymore + if item['subtitles_path'] not in item['external_subtitles']: + episodes_data.remove(item) + + # cleanup the unused attributes del item['path'] del item['external_subtitles'] @@ -138,7 +143,7 @@ def upgrade_subtitles(): 'path': x.path, 'profileId': x.profileId, 'subtitles_path': x.subtitles_path, - 'external_subtitles': [y[1] for y in ast.literal_eval(x.external_subtitles) if y[1]], + 'external_subtitles': [ast.literal_eval(f'"{y[1]}"') for y in ast.literal_eval(x.external_subtitles) if y[1]], 'upgradable': bool(x.upgradable), } for x in database.execute( select(TableMovies.title, @@ -158,11 +163,15 @@ def upgrade_subtitles(): .join(movies_to_upgrade, onclause=TableHistoryMovie.id == movies_to_upgrade.c.id, isouter=True) .where(movies_to_upgrade.c.id.is_not(None))) .all() if _language_still_desired(x.language, x.profileId) and - x.subtitles_path in x.external_subtitles and x.video_path == x.path ] for item in movies_data: + # do not consider subtitles that do not exist on disk anymore + if item['subtitles_path'] not in item['external_subtitles']: + movies_data.remove(item) + + # cleanup the unused attributes del item['path'] del item['external_subtitles'] |