diff options
author | morpheus65535 <[email protected]> | 2022-06-11 07:44:38 -0400 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2022-06-11 07:44:38 -0400 |
commit | 3c53db7353137257e185e0361078b2a2eafb3701 (patch) | |
tree | 638040454c9fb140463a56ebd973a6b7918c95eb | |
parent | d9e7c55aad46a16d68c2278d36b149b42339a0f9 (diff) | |
download | bazarr-3c53db7353137257e185e0361078b2a2eafb3701.tar.gz bazarr-3c53db7353137257e185e0361078b2a2eafb3701.zip |
Added translation to history. #1827
-rw-r--r-- | bazarr/api/subtitles/subtitles.py | 10 | ||||
-rw-r--r-- | bazarr/subtitles/tools/translate.py | 16 |
2 files changed, 21 insertions, 5 deletions
diff --git a/bazarr/api/subtitles/subtitles.py b/bazarr/api/subtitles/subtitles.py index b594e26f4..2e58c2cf5 100644 --- a/bazarr/api/subtitles/subtitles.py +++ b/bazarr/api/subtitles/subtitles.py @@ -60,12 +60,16 @@ class Subtitles(Resource): del subsync gc.collect() elif action == 'translate': + from_language = os.path.splitext(subtitles_path)[0].rsplit(".", 1)[1].replace('_', '-') dest_language = language forced = True if request.form.get('forced') == 'true' else False hi = True if request.form.get('hi') == 'true' else False - result = translate_subtitles_file(video_path=video_path, source_srt_file=subtitles_path, - to_lang=dest_language, - forced=forced, hi=hi) + translate_subtitles_file(video_path=video_path, source_srt_file=subtitles_path, + from_lang=from_language, to_lang=dest_language, forced=forced, hi=hi, + media_type="series" if media_type == "episode" else "movies", + sonarr_series_id=metadata.get('sonarrSeriesId'), + sonarr_episode_id=int(id), + radarr_id=id) else: use_original_format = True if request.form.get('original_format') == 'true' else False subtitles_apply_mods(language, subtitles_path, [action], use_original_format) diff --git a/bazarr/subtitles/tools/translate.py b/bazarr/subtitles/tools/translate.py index 4214bc1a0..5a0570f49 100644 --- a/bazarr/subtitles/tools/translate.py +++ b/bazarr/subtitles/tools/translate.py @@ -8,10 +8,13 @@ from subzero.language import Language from deep_translator import GoogleTranslator from languages.custom_lang import CustomLanguage -from languages.get_languages import alpha3_from_alpha2 +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 -def translate_subtitles_file(video_path, source_srt_file, to_lang, forced, hi): +def translate_subtitles_file(video_path, source_srt_file, from_lang, to_lang, forced, hi, media_type, sonarr_series_id, + sonarr_episode_id, radarr_id): language_code_convert_dict = { 'he': 'iw', 'zt': 'zh-CN', @@ -79,4 +82,13 @@ def translate_subtitles_file(video_path, source_srt_file, to_lang, forced, hi): return False subs.save(dest_srt_file) + message = f"{language_from_alpha2(from_lang)} subtitles translated to {language_from_alpha3(to_lang)}." + + 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) + else: + history_log_movie(action=6, radarr_id=radarr_id, description=message, + video_path=video_path, language=to_lang, subtitles_path=dest_srt_file) + return dest_srt_file |