mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-26 01:27:07 +00:00
Added translation to history. #1827
This commit is contained in:
parent
d9e7c55aad
commit
3c53db7353
2 changed files with 21 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue