Skip to content

Commit

Permalink
Fixed issue with subtitles upgrade process on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus65535 committed Oct 17, 2024
1 parent 5139fca commit de9ce4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bazarr/api/episodes/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def get(self):
'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()]
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/movies/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get(self):
'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()]
Expand Down
15 changes: 12 additions & 3 deletions bazarr/subtitles/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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,
Expand All @@ -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']

Expand Down

0 comments on commit de9ce4d

Please sign in to comment.