1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-27 10:07:22 +00:00

Added translation to history. #1827

This commit is contained in:
morpheus65535 2022-06-11 07:44:38 -04:00
parent d9e7c55aad
commit 3c53db7353
2 changed files with 21 additions and 5 deletions

View file

@ -60,12 +60,16 @@ class Subtitles(Resource):
del subsync del subsync
gc.collect() gc.collect()
elif action == 'translate': elif action == 'translate':
from_language = os.path.splitext(subtitles_path)[0].rsplit(".", 1)[1].replace('_', '-')
dest_language = language dest_language = language
forced = True if request.form.get('forced') == 'true' else False forced = True if request.form.get('forced') == 'true' else False
hi = True if request.form.get('hi') == '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, translate_subtitles_file(video_path=video_path, source_srt_file=subtitles_path,
to_lang=dest_language, from_lang=from_language, to_lang=dest_language, forced=forced, hi=hi,
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: else:
use_original_format = True if request.form.get('original_format') == 'true' else False use_original_format = True if request.form.get('original_format') == 'true' else False
subtitles_apply_mods(language, subtitles_path, [action], use_original_format) subtitles_apply_mods(language, subtitles_path, [action], use_original_format)

View file

@ -8,10 +8,13 @@ from subzero.language import Language
from deep_translator import GoogleTranslator from deep_translator import GoogleTranslator
from languages.custom_lang import CustomLanguage 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 = { language_code_convert_dict = {
'he': 'iw', 'he': 'iw',
'zt': 'zh-CN', 'zt': 'zh-CN',
@ -79,4 +82,13 @@ def translate_subtitles_file(video_path, source_srt_file, to_lang, forced, hi):
return False return False
subs.save(dest_srt_file) 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 return dest_srt_file