From e5ecd17f80fcf7149004dacb689b4e1f72262602 Mon Sep 17 00:00:00 2001 From: JpF4E Date: Sat, 22 Feb 2020 19:29:04 +0000 Subject: [PATCH] Added audio language variables to post processing command. Required to use with subsync. --- bazarr/get_subtitle.py | 40 +++++++++++++++++++++++++------------- bazarr/helper.py | 5 ++++- bazarr/main.py | 16 ++++++++++----- views/settings_general.tpl | 12 ++++++++++++ 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index 8b078f439..ab2afb31c 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -23,7 +23,8 @@ from subliminal_patch.core import SZAsyncProviderPool, download_best_subtitles, list_all_subtitles, get_subtitle_path from subliminal_patch.score import compute_score from subliminal.refiners.tvdb import series_re -from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2, language_from_alpha2 +from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2, language_from_alpha2, \ + alpha2_from_language, alpha3_from_language from config import settings from helper import path_replace, path_replace_movie, path_replace_reverse, \ path_replace_reverse_movie, pp_replace, get_target_folder, force_unicode @@ -106,7 +107,7 @@ def get_scores(video, media_type, min_score_movie_perc=60 * 100 / 120.0, min_sco return min_score, max_score, set(scores) -def download_subtitle(path, language, hi, forced, providers, providers_auth, sceneName, title, media_type, +def download_subtitle(path, language, audio_language, hi, forced, providers, providers_auth, sceneName, title, media_type, forced_minimum_score=None, is_upgrade=False): # fixme: supply all missing languages, not only one, to hit providers only once who support multiple languages in # one query @@ -217,6 +218,8 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce downloaded_language_code3 = subtitle.language.alpha3 downloaded_language = language_from_alpha3(downloaded_language_code3) downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3) + audio_language_code2 = alpha2_from_language(audio_language) + audio_language_code3 = alpha3_from_language(audio_language) downloaded_path = subtitle.storage_path is_forced_string = " forced" if subtitle.language.forced else "" logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path) @@ -233,8 +236,8 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce if use_postprocessing is True: command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, - downloaded_language_code2, downloaded_language_code3, - subtitle.language.forced) + downloaded_language_code2, downloaded_language_code3, audio_language, + audio_language_code2, audio_language_code3, subtitle.language.forced) postprocessing(command, path) # fixme: support multiple languages at once @@ -365,7 +368,7 @@ def manual_search(path, language, hi, forced, providers, providers_auth, sceneNa return final_subtitles -def manual_download_subtitle(path, language, hi, forced, subtitle, provider, providers_auth, sceneName, title, +def manual_download_subtitle(path, language, audio_language, hi, forced, subtitle, provider, providers_auth, sceneName, title, media_type): logging.debug('BAZARR Manually downloading Subtitles for this file: ' + path) @@ -423,6 +426,8 @@ def manual_download_subtitle(path, language, hi, forced, subtitle, provider, pro downloaded_language_code3 = subtitle.language.alpha3 downloaded_language = language_from_alpha3(downloaded_language_code3) downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3) + audio_language_code2 = alpha2_from_language(audio_language) + audio_language_code3 = alpha3_from_language(audio_language) downloaded_path = saved_subtitle.storage_path logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path) is_forced_string = " forced" if subtitle.language.forced else "" @@ -431,8 +436,8 @@ def manual_download_subtitle(path, language, hi, forced, subtitle, provider, pro if use_postprocessing is True: command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, - downloaded_language_code2, downloaded_language_code3, - subtitle.language.forced) + downloaded_language_code2, downloaded_language_code3, audio_language, + audio_language_code2, audio_language_code3, subtitle.language.forced) postprocessing(command, path) if media_type == 'series': @@ -512,7 +517,7 @@ def series_download_subtitles(no): logging.debug("BAZARR no episode for that sonarrSeriesId can be found in database:", str(no)) return - series_details = database.execute("SELECT hearing_impaired, title, forced FROM table_shows WHERE sonarrSeriesId=?", + series_details = database.execute("SELECT hearing_impaired, audio_language, title, forced FROM table_shows WHERE sonarrSeriesId=?", (no,), only_one=True) if not series_details: logging.debug("BAZARR no series with that sonarrSeriesId can be found in database:", str(no)) @@ -531,6 +536,7 @@ def series_download_subtitles(no): length=count_episodes_details) result = download_subtitle(path_replace(episode['path']), str(alpha3_from_alpha2(language.split(':')[0])), + series_details['audio_language'], series_details['hearing_impaired'], "True" if len(language.split(':')) > 1 else "False", providers_list, @@ -567,7 +573,7 @@ def episode_download_subtitles(no): episodes_details = database.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, " "table_episodes.sonarrEpisodeId, table_episodes.scene_name, " "table_shows.hearing_impaired, table_shows.title, table_shows.sonarrSeriesId, " - "table_shows.forced FROM table_episodes LEFT JOIN table_shows on " + "table_shows.forced, table_shows.audio_language FROM table_episodes LEFT JOIN table_shows on " "table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId " "WHERE sonarrEpisodeId=?" + episodes_details_clause, (no,)) @@ -587,6 +593,7 @@ def episode_download_subtitles(no): path_replace(episode['path']), queue='get_subtitle') result = download_subtitle(path_replace(episode['path']), str(alpha3_from_alpha2(language.split(':')[0])), + episode['audio_language'], episode['hearing_impaired'], "True" if len(language.split(':')) > 1 else "False", providers_list, @@ -616,7 +623,7 @@ def movies_download_subtitles(no): else: movie_details_clause = '' - movie = database.execute("SELECT path, missing_subtitles, radarrId, sceneName, hearing_impaired, title, forced " + movie = database.execute("SELECT path, missing_subtitles, audio_language, radarrId, sceneName, hearing_impaired, title, forced " "FROM table_movies WHERE radarrId=?" + movie_details_clause, (no,), only_one=True) if not movie: @@ -638,6 +645,7 @@ def movies_download_subtitles(no): length=count_movie) result = download_subtitle(path_replace_movie(movie['path']), str(alpha3_from_alpha2(language.split(':')[0])), + movie['audio_language'], movie['hearing_impaired'], "True" if len(language.split(':')) > 1 else "False", providers_list, @@ -668,7 +676,7 @@ def movies_download_subtitles(no): def wanted_download_subtitles(path, l, count_episodes): episodes_details = database.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, " "table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, " - "table_shows.hearing_impaired, table_episodes.scene_name," + "table_shows.hearing_impaired, table_shows.audio_language, table_episodes.scene_name," "table_episodes.failedAttempts, table_shows.title, table_shows.forced " "FROM table_episodes LEFT JOIN table_shows on " "table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId " @@ -701,6 +709,7 @@ def wanted_download_subtitles(path, l, count_episodes): length=count_episodes) result = download_subtitle(path_replace(episode['path']), str(alpha3_from_alpha2(language.split(':')[0])), + episode['audio_language'], episode['hearing_impaired'], "True" if len(language.split(':')) > 1 else "False", providers_list, @@ -724,7 +733,7 @@ def wanted_download_subtitles(path, l, count_episodes): def wanted_download_subtitles_movie(path, l, count_movies): - movies_details = database.execute("SELECT path, missing_subtitles, radarrId, hearing_impaired, sceneName, " + movies_details = database.execute("SELECT path, missing_subtitles, radarrId, hearing_impaired, audio_language, sceneName, " "failedAttempts, title, forced FROM table_movies WHERE path = ? " "AND missing_subtitles != '[]'", (path_replace_reverse_movie(path),)) @@ -754,6 +763,7 @@ def wanted_download_subtitles_movie(path, l, count_movies): length=count_movies) result = download_subtitle(path_replace_movie(movie['path']), str(alpha3_from_alpha2(language.split(':')[0])), + movie['audio_language'], movie['hearing_impaired'], "True" if len(language.split(':')) > 1 else "False", providers_list, @@ -957,7 +967,7 @@ def upgrade_subtitles(): if settings.general.getboolean('use_sonarr'): upgradable_episodes = database.execute("SELECT table_history.video_path, table_history.language, " - "table_history.score, table_shows.hearing_impaired, " + "table_history.score, table_shows.hearing_impaired, table_shows.audio_language, " "table_episodes.scene_name, table_episodes.title," "table_episodes.sonarrSeriesId, table_episodes.sonarrEpisodeId," "MAX(table_history.timestamp) as timestamp, " @@ -991,7 +1001,7 @@ def upgrade_subtitles(): if settings.general.getboolean('use_radarr'): upgradable_movies = database.execute("SELECT table_history_movie.video_path, table_history_movie.language, " - "table_history_movie.score, table_movies.hearing_impaired, " + "table_history_movie.score, table_movies.hearing_impaired, table_movies.audio_language, " "table_movies.sceneName, table_movies.title, table_movies.radarrId, " "MAX(table_history_movie.timestamp) as timestamp, table_movies.languages, " "table_movies.forced FROM table_history_movie INNER JOIN " @@ -1054,6 +1064,7 @@ def upgrade_subtitles(): result = download_subtitle(path_replace(episode['video_path']), str(alpha3_from_alpha2(language)), + episode['audio_language'], episode['hearing_impaired'], is_forced, providers_list, @@ -1105,6 +1116,7 @@ def upgrade_subtitles(): result = download_subtitle(path_replace_movie(movie['video_path']), str(alpha3_from_alpha2(language)), + movie['audio_language'], movie['hearing_impaired'], is_forced, providers_list, diff --git a/bazarr/helper.py b/bazarr/helper.py index feef91067..5124b2877 100644 --- a/bazarr/helper.py +++ b/bazarr/helper.py @@ -95,7 +95,7 @@ def path_replace_reverse_movie(path): return path -def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3, forced): +def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3, episode_language, episode_language_code2, episode_language_code3, forced): is_forced = ":forced" if forced else "" is_forced_string = " forced" if forced else "" pp_command = pp_command.replace('{{directory}}', os.path.dirname(episode)) @@ -105,6 +105,9 @@ def pp_replace(pp_command, episode, subtitles, language, language_code2, languag pp_command = pp_command.replace('{{subtitles_language}}', language + is_forced_string) pp_command = pp_command.replace('{{subtitles_language_code2}}', language_code2 + is_forced) pp_command = pp_command.replace('{{subtitles_language_code3}}', language_code3 + is_forced) + pp_command = pp_command.replace('{{episode_language}}', episode_language) + pp_command = pp_command.replace('{{episode_language_code2}}', episode_language_code2) + pp_command = pp_command.replace('{{episode_language_code3}}', episode_language_code3) return pp_command diff --git a/bazarr/main.py b/bazarr/main.py index cac891428..ec314ecfb 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1797,7 +1797,7 @@ def remove_subtitles_movie(): def get_subtitle(): authorize() ref = request.environ['HTTP_REFERER'] - + episodePath = request.forms.episodePath sceneName = request.forms.sceneName language = request.forms.get('language') @@ -1806,12 +1806,15 @@ def get_subtitle(): sonarrSeriesId = request.forms.get('sonarrSeriesId') sonarrEpisodeId = request.forms.get('sonarrEpisodeId') title = request.forms.title - + + data = database.execute("SELECT audio_language FROM table_shows WHERE sonarrSeriesId=?", (sonarrSeriesId,)) + audio_language = data['audio_language'] + providers_list = get_providers() providers_auth = get_providers_auth() try: - result = download_subtitle(episodePath, language, hi, forced, providers_list, providers_auth, sceneName, title, + result = download_subtitle(episodePath, language, audio_language, hi, forced, providers_list, providers_auth, sceneName, title, 'series') if result is not None: message = result[0] @@ -1942,12 +1945,15 @@ def get_subtitle_movie(): forced = request.forms.get('forced') radarrId = request.forms.get('radarrId') title = request.forms.title - + + data = database.execute("SELECT audio_language FROM table_movies WHERE radarrId=?", (radarrId,)) + audio_language = data['audio_language'] + providers_list = get_providers() providers_auth = get_providers_auth() try: - result = download_subtitle(moviePath, language, hi, forced, providers_list, providers_auth, sceneName, title, + result = download_subtitle(moviePath, language, audio_language, hi, forced, providers_list, providers_auth, sceneName, title, 'movie') if result is not None: message = result[0] diff --git a/views/settings_general.tpl b/views/settings_general.tpl index 2e4998eb0..40a2af5b4 100644 --- a/views/settings_general.tpl +++ b/views/settings_general.tpl @@ -608,6 +608,18 @@
{{subtitles_language_code3}}
The 3-letter ISO-639 language code of the subtitles language. +
+
{{episode_language}}
+ The audio language of the episode file. +
+
+
{{episode_language_code2}}
+ The 2-letter ISO-639 language code of the episode audio language. +
+
+
{{episode_language_code3}}
+ The 3-letter ISO-639 language code of the episode audio language. +