mirror of
https://github.com/morpheus65535/bazarr.git
synced 2024-11-10 09:02:44 +08:00
Merge pull request #833 from JpF4E/master
Addition of audio language variables to post processing commands
This commit is contained in:
commit
04a0d5ffb2
4 changed files with 63 additions and 24 deletions
|
@ -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
|
||||
|
@ -368,7 +371,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)
|
||||
|
||||
|
@ -426,6 +429,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 ""
|
||||
|
@ -434,8 +439,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':
|
||||
|
@ -515,7 +520,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))
|
||||
|
@ -534,6 +539,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,
|
||||
|
@ -570,7 +576,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,))
|
||||
|
||||
|
@ -590,6 +596,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,
|
||||
|
@ -619,7 +626,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:
|
||||
|
@ -641,6 +648,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,
|
||||
|
@ -671,7 +679,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 "
|
||||
|
@ -704,6 +712,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,
|
||||
|
@ -727,7 +736,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),))
|
||||
|
||||
|
@ -757,6 +766,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,
|
||||
|
@ -960,7 +970,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, "
|
||||
|
@ -994,7 +1004,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 "
|
||||
|
@ -1057,6 +1067,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,
|
||||
|
@ -1108,6 +1119,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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -1745,7 +1745,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')
|
||||
|
@ -1754,12 +1754,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,), only_one=True)
|
||||
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]
|
||||
|
@ -1811,11 +1814,14 @@ def manual_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,), only_one=True)
|
||||
audio_language = data['audio_language']
|
||||
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
try:
|
||||
result = manual_download_subtitle(episodePath, language, hi, forced, subtitle, selected_provider,
|
||||
result = manual_download_subtitle(episodePath, language, audio_language, hi, forced, subtitle, selected_provider,
|
||||
providers_auth,
|
||||
sceneName, title, 'series')
|
||||
if result is not None:
|
||||
|
@ -1890,12 +1896,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,), only_one=True)
|
||||
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]
|
||||
|
@ -1946,11 +1955,14 @@ def manual_get_subtitle_movie():
|
|||
subtitle = request.forms.subtitle
|
||||
radarrId = request.forms.get('radarrId')
|
||||
title = request.forms.title
|
||||
|
||||
|
||||
data = database.execute("SELECT audio_language FROM table_movies WHERE radarrId=?", (radarrId,), only_one=True)
|
||||
audio_language = data['audio_language']
|
||||
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
try:
|
||||
result = manual_download_subtitle(moviePath, language, hi, forced, subtitle, selected_provider, providers_auth,
|
||||
result = manual_download_subtitle(moviePath, language, audio_language, hi, forced, subtitle, selected_provider, providers_auth,
|
||||
sceneName, title, 'movie')
|
||||
if result is not None:
|
||||
message = result[0]
|
||||
|
|
|
@ -608,6 +608,18 @@
|
|||
<div class="header">{{subtitles_language_code3}}</div>
|
||||
The 3-letter ISO-639 language code of the subtitles language.
|
||||
</div>
|
||||
<div class="item">
|
||||
<div class="header">{{episode_language}}</div>
|
||||
The audio language of the episode file.
|
||||
</div>
|
||||
<div class="item">
|
||||
<div class="header">{{episode_language_code2}}</div>
|
||||
The 2-letter ISO-639 language code of the episode audio language.
|
||||
</div>
|
||||
<div class="item">
|
||||
<div class="header">{{episode_language_code3}}</div>
|
||||
The 3-letter ISO-639 language code of the episode audio language.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue