Skip to content

Commit

Permalink
Fixed improper paths history logging for different tools
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus65535 committed Sep 27, 2024
1 parent 6297b4b commit 0200bb9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
23 changes: 15 additions & 8 deletions bazarr/subtitles/tools/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,47 @@ def delete_subtitles(media_type, language, forced, hi, media_path, subtitles_pat
language_log += ':forced'
language_string += ' forced'

if media_type == 'series':
pr = path_mappings.path_replace
prr = path_mappings.path_replace_reverse
else:
pr = path_mappings.path_replace_movie
prr = path_mappings.path_replace_reverse_movie

result = ProcessSubtitlesResult(message=f"{language_string} subtitles deleted from disk.",
reversed_path=path_mappings.path_replace_reverse(media_path),
reversed_path=prr(media_path),
downloaded_language_code2=language_log,
downloaded_provider=None,
score=None,
forced=None,
subtitle_id=None,
reversed_subtitles_path=path_mappings.path_replace_reverse(subtitles_path),
reversed_subtitles_path=prr(subtitles_path),
hearing_impaired=None)

if media_type == 'series':
try:
os.remove(path_mappings.path_replace(subtitles_path))
os.remove(pr(subtitles_path))
except OSError:
logging.exception(f'BAZARR cannot delete subtitles file: {subtitles_path}')
store_subtitles(path_mappings.path_replace_reverse(media_path), media_path)
store_subtitles(prr(media_path), media_path)
return False
else:
history_log(0, sonarr_series_id, sonarr_episode_id, result)
store_subtitles(path_mappings.path_replace_reverse(media_path), media_path)
store_subtitles(prr(media_path), media_path)
notify_sonarr(sonarr_series_id)
event_stream(type='series', action='update', payload=sonarr_series_id)
event_stream(type='episode-wanted', action='update', payload=sonarr_episode_id)
return True
else:
try:
os.remove(path_mappings.path_replace_movie(subtitles_path))
os.remove(pr(subtitles_path))
except OSError:
logging.exception(f'BAZARR cannot delete subtitles file: {subtitles_path}')
store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path)
store_subtitles_movie(prr(media_path), media_path)
return False
else:
history_log_movie(0, radarr_id, result)
store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path)
store_subtitles_movie(prr(media_path), media_path)
notify_radarr(radarr_id)
event_stream(type='movie-wanted', action='update', payload=radarr_id)
return True
9 changes: 7 additions & 2 deletions bazarr/subtitles/tools/subsyncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,19 @@ def sync(self, video_path, srt_path, srt_lang, hi, forced,
f"{offset_seconds} seconds and a framerate scale factor of "
f"{f'{framerate_scale_factor:.2f}'}.")

if sonarr_series_id:
prr = path_mappings.path_replace_reverse
else:
prr = path_mappings.path_replace_reverse_movie

result = ProcessSubtitlesResult(message=message,
reversed_path=path_mappings.path_replace_reverse(self.reference),
reversed_path=prr(self.reference),
downloaded_language_code2=srt_lang,
downloaded_provider=None,
score=None,
forced=forced,
subtitle_id=None,
reversed_subtitles_path=srt_path,
reversed_subtitles_path=prr(self.srtin),
hearing_impaired=hi)

if sonarr_episode_id:
Expand Down
10 changes: 8 additions & 2 deletions bazarr/subtitles/tools/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sonarr.history import history_log
from subtitles.processing import ProcessSubtitlesResult
from app.event_handler import show_progress, hide_progress
from utilities.path_mappings import path_mappings


def translate_subtitles_file(video_path, source_srt_file, from_lang, to_lang, forced, hi, media_type, sonarr_series_id,
Expand Down Expand Up @@ -104,14 +105,19 @@ def translate_line(id, line, attempt):

message = f"{language_from_alpha2(from_lang)} subtitles translated to {language_from_alpha3(to_lang)}."

if media_type == 'series':
prr = path_mappings.path_replace_reverse
else:
prr = path_mappings.path_replace_reverse_movie

result = ProcessSubtitlesResult(message=message,
reversed_path=video_path,
reversed_path=prr(video_path),
downloaded_language_code2=to_lang,
downloaded_provider=None,
score=None,
forced=forced,
subtitle_id=None,
reversed_subtitles_path=dest_srt_file,
reversed_subtitles_path=prr(dest_srt_file),
hearing_impaired=hi)

if media_type == 'series':
Expand Down

0 comments on commit 0200bb9

Please sign in to comment.