diff options
author | morpheus65535 <[email protected]> | 2023-02-24 22:19:43 -0500 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2023-02-24 22:19:43 -0500 |
commit | 019613958e5736a5adfdfc2527ebc753805e6c9c (patch) | |
tree | 2cc71f16e4e2be30d6f9e55546278f55e55a0370 | |
parent | 5dc4e782ae31ed36aaf4d27d9a46af3e494c7491 (diff) | |
download | bazarr-019613958e5736a5adfdfc2527ebc753805e6c9c.tar.gz bazarr-019613958e5736a5adfdfc2527ebc753805e6c9c.zip |
Fixed some issues after subtitles upgrade refactor.v1.1.5-beta.24
-rw-r--r-- | bazarr/api/subtitles/subtitles.py | 25 | ||||
-rw-r--r-- | bazarr/subtitles/processing.py | 5 | ||||
-rw-r--r-- | bazarr/subtitles/tools/delete.py | 19 | ||||
-rw-r--r-- | bazarr/subtitles/tools/subsyncer.py | 18 | ||||
-rw-r--r-- | bazarr/subtitles/tools/translate.py | 17 |
5 files changed, 66 insertions, 18 deletions
diff --git a/bazarr/api/subtitles/subtitles.py b/bazarr/api/subtitles/subtitles.py index 6ead0c833..805d74a17 100644 --- a/bazarr/api/subtitles/subtitles.py +++ b/bazarr/api/subtitles/subtitles.py @@ -7,6 +7,7 @@ import gc from flask_restx import Resource, Namespace, reqparse from app.database import TableEpisodes, TableMovies +from languages.get_languages import alpha3_from_alpha2 from utilities.path_mappings import path_mappings from subtitles.tools.subsyncer import SubSyncer from subtitles.tools.translate import translate_subtitles_file @@ -81,7 +82,7 @@ class Subtitles(Resource): del subsync gc.collect() elif action == 'translate': - from_language = os.path.splitext(subtitles_path)[0].rsplit(".", 1)[1].replace('_', '-') + from_language = subtitles_lang_from_filename(subtitles_path) dest_language = language forced = True if args.get('forced') == 'true' else False hi = True if args.get('hi') == 'true' else False @@ -110,3 +111,25 @@ class Subtitles(Resource): event_stream(type='movie', payload=int(id)) return '', 204 + + +def subtitles_lang_from_filename(path): + split_extensionless_path = os.path.splitext(path.lower())[0].rsplit(".", 2) + + if len(split_extensionless_path) < 2: + return None + elif len(split_extensionless_path) == 2: + return_lang = split_extensionless_path[-1] + else: + first_ext = split_extensionless_path[-1] + second_ext = split_extensionless_path[-2] + + if first_ext in ['hi', 'sdh', 'cc']: + if alpha3_from_alpha2(second_ext): + return_lang = second_ext + else: + return first_ext + else: + return_lang = first_ext + + return return_lang.replace('_', '-') diff --git a/bazarr/subtitles/processing.py b/bazarr/subtitles/processing.py index c6312e66e..c0449efb1 100644 --- a/bazarr/subtitles/processing.py +++ b/bazarr/subtitles/processing.py @@ -14,7 +14,6 @@ from sonarr.notify import notify_sonarr from app.event_handler import event_stream from .utils import _get_download_code3 -from .sync import sync_subtitles from .post_processing import postprocessing @@ -77,6 +76,8 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u return series_id = episode_metadata['sonarrSeriesId'] episode_id = episode_metadata['sonarrEpisodeId'] + + from .sync import sync_subtitles sync_subtitles(video_path=path, srt_path=downloaded_path, forced=subtitle.language.forced, srt_lang=downloaded_language_code2, media_type=media_type, @@ -92,6 +93,8 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u return series_id = "" episode_id = movie_metadata['radarrId'] + + from .sync import sync_subtitles sync_subtitles(video_path=path, srt_path=downloaded_path, forced=subtitle.language.forced, srt_lang=downloaded_language_code2, media_type=media_type, diff --git a/bazarr/subtitles/tools/delete.py b/bazarr/subtitles/tools/delete.py index c04c8524d..622cf965a 100644 --- a/bazarr/subtitles/tools/delete.py +++ b/bazarr/subtitles/tools/delete.py @@ -10,6 +10,7 @@ from languages.get_languages import language_from_alpha2 from utilities.path_mappings import path_mappings from subtitles.indexer.series import store_subtitles from subtitles.indexer.movies import store_subtitles_movie +from subtitles.processing import ProcessSubtitlesResult from sonarr.history import history_log from radarr.history import history_log_movie from sonarr.notify import notify_sonarr @@ -35,7 +36,15 @@ def delete_subtitles(media_type, language, forced, hi, media_path, subtitles_pat language_log += ':forced' language_string += ' forced' - result = language_string + " subtitles deleted from disk." + result = ProcessSubtitlesResult(message=language_string + " subtitles deleted from disk.", + reversed_path=path_mappings.path_replace_reverse(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), + hearing_impaired=None) if media_type == 'series': try: @@ -45,9 +54,7 @@ def delete_subtitles(media_type, language, forced, hi, media_path, subtitles_pat store_subtitles(path_mappings.path_replace_reverse(media_path), media_path) return False else: - history_log(0, sonarr_series_id, sonarr_episode_id, result, language=language_log, - video_path=path_mappings.path_replace_reverse(media_path), - subtitles_path=path_mappings.path_replace_reverse(subtitles_path)) + history_log(0, sonarr_series_id, sonarr_episode_id, result) store_subtitles(path_mappings.path_replace_reverse(media_path), media_path) notify_sonarr(sonarr_series_id) event_stream(type='series', action='update', payload=sonarr_series_id) @@ -61,9 +68,7 @@ def delete_subtitles(media_type, language, forced, hi, media_path, subtitles_pat store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path) return False else: - history_log_movie(0, radarr_id, result, language=language_log, - video_path=path_mappings.path_replace_reverse_movie(media_path), - subtitles_path=path_mappings.path_replace_reverse_movie(subtitles_path)) + history_log_movie(0, radarr_id, result) store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path) notify_radarr(radarr_id) event_stream(type='movie-wanted', action='update', payload=radarr_id) diff --git a/bazarr/subtitles/tools/subsyncer.py b/bazarr/subtitles/tools/subsyncer.py index 5200ee105..5667622ac 100644 --- a/bazarr/subtitles/tools/subsyncer.py +++ b/bazarr/subtitles/tools/subsyncer.py @@ -8,6 +8,7 @@ from ffsubsync.ffsubsync import run, make_parser from utilities.binaries import get_binary from radarr.history import history_log_movie from sonarr.history import history_log +from subtitles.processing import ProcessSubtitlesResult from languages.get_languages import language_from_alpha2 from utilities.path_mappings import path_mappings from app.config import settings @@ -83,14 +84,21 @@ class SubSyncer: "scale factor of {2}.".format(language_from_alpha2(srt_lang), offset_seconds, "{:.2f}".format(framerate_scale_factor)) + result = ProcessSubtitlesResult(message=message, + reversed_path=path_mappings.path_replace_reverse(self.reference), + downloaded_language_code2=srt_lang, + downloaded_provider=None, + score=None, + forced=None, + subtitle_id=None, + reversed_subtitles_path=srt_path, + hearing_impaired=None) + if media_type == 'series': history_log(action=5, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id, - description=message, video_path=path_mappings.path_replace_reverse(self.reference), - language=srt_lang, subtitles_path=srt_path) + result=result) else: - history_log_movie(action=5, radarr_id=radarr_id, description=message, - video_path=path_mappings.path_replace_reverse_movie(self.reference), - language=srt_lang, subtitles_path=srt_path) + history_log_movie(action=5, radarr_id=radarr_id, result=result) else: logging.error('BAZARR unable to sync subtitles: {0}'.format(self.srtin)) diff --git a/bazarr/subtitles/tools/translate.py b/bazarr/subtitles/tools/translate.py index 5a0570f49..b00040dce 100644 --- a/bazarr/subtitles/tools/translate.py +++ b/bazarr/subtitles/tools/translate.py @@ -11,6 +11,7 @@ from languages.custom_lang import CustomLanguage from languages.get_languages import alpha3_from_alpha2, language_from_alpha2, language_from_alpha3 from radarr.history import history_log_movie from sonarr.history import history_log +from subtitles.processing import ProcessSubtitlesResult def translate_subtitles_file(video_path, source_srt_file, from_lang, to_lang, forced, hi, media_type, sonarr_series_id, @@ -84,11 +85,19 @@ def translate_subtitles_file(video_path, source_srt_file, from_lang, to_lang, fo message = f"{language_from_alpha2(from_lang)} subtitles translated to {language_from_alpha3(to_lang)}." + result = ProcessSubtitlesResult(message=message, + reversed_path=video_path, + downloaded_language_code2=to_lang, + downloaded_provider=None, + score=None, + forced=None, + subtitle_id=None, + reversed_subtitles_path=dest_srt_file, + hearing_impaired=None) + if media_type == 'series': - history_log(action=6, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id, - description=message, video_path=video_path, language=to_lang, subtitles_path=dest_srt_file) + history_log(action=6, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id, result=result) else: - history_log_movie(action=6, radarr_id=radarr_id, description=message, - video_path=video_path, language=to_lang, subtitles_path=dest_srt_file) + history_log_movie(action=6, radarr_id=radarr_id, result=result) return dest_srt_file |