get_subtitle: implement manual subtitle download

pull/292/head
panni 6 years ago
parent d9627ae99c
commit 1f485d0aa7

@ -17,8 +17,8 @@ from datetime import datetime, timedelta
from subzero.language import Language from subzero.language import Language
from subzero.video import parse_video from subzero.video import parse_video
from subliminal import region, Video, score as subliminal_scores, \ from subliminal import region, Video, score as subliminal_scores, \
list_subtitles, download_subtitles list_subtitles
from subliminal_patch.core import SZAsyncProviderPool, download_best_subtitles, save_subtitles from subliminal_patch.core import SZAsyncProviderPool, download_best_subtitles, save_subtitles, download_subtitles
from subliminal_patch.score import compute_score from subliminal_patch.score import compute_score
from subliminal.subtitle import get_subtitle_path from subliminal.subtitle import get_subtitle_path
from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2 from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2
@ -343,6 +343,7 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, titl
not_matched = scores - matches not_matched = scores - matches
score = compute_score(matches, s, video, hearing_impaired=hi) score = compute_score(matches, s, video, hearing_impaired=hi)
s.score = score
if score < min_score: if score < min_score:
continue continue
@ -359,64 +360,45 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, titl
return final_subtitles return final_subtitles
def manual_download_subtitle(path, language, hi, subtitle, provider, providers_auth, sceneName, media_type): def manual_download_subtitle(path, language, hi, subtitle, provider, providers_auth, sceneName, title, media_type):
logging.debug('BAZARR Manually downloading subtitles for this file: ' + path) logging.debug('BAZARR Manually downloading subtitles for this file: ' + path)
if hi == "True": if hi == "True":
hi = True hi = True
else: else:
hi = False hi = False
subtitle = pickle.loads(codecs.decode(subtitle.encode(), "base64")) subtitle = pickle.loads(codecs.decode(subtitle.encode(), "base64"))
if media_type == 'series':
type_of_score = 360
elif media_type == 'movie':
type_of_score = 120
use_scenename = get_general_settings()[9] use_scenename = get_general_settings()[9]
use_postprocessing = get_general_settings()[10] use_postprocessing = get_general_settings()[10]
postprocessing_cmd = get_general_settings()[11] postprocessing_cmd = get_general_settings()[11]
single = get_general_settings()[7]
language = alpha3_from_alpha2(language) video = get_video(path, title, sceneName, use_scenename, providers={provider}, media_type=media_type)
if language == 'pob': if video:
lang_obj = Language('por', 'BR') min_score, max_score, scores = get_scores(video, media_type)
else:
lang_obj = Language(language)
try:
if sceneName is None or not use_scenename:
used_sceneName = False
video = parse_video(path, None, providers={provider})
else:
used_sceneName = True
video = Video.fromname(sceneName)
except Exception as e:
logging.exception("BAZARR Error trying to get video information for this file: " + path)
pass
else:
try: try:
download_subtitles([subtitle], providers=provider, provider_configs=providers_auth) download_subtitles([subtitle], providers={provider}, provider_configs=providers_auth,
pool_class=SZAsyncProviderPool,
throttle_callback=None) # fixme
logging.debug('BAZARR Subtitles file downloaded for this file:' + path) logging.debug('BAZARR Subtitles file downloaded for this file:' + path)
except Exception as e: except Exception as e:
logging.exception('BAZARR Error downloading subtitles for this file ' + path) logging.exception('BAZARR Error downloading subtitles for this file ' + path)
return None return None
else: else:
single = get_general_settings()[7]
try: try:
score = round(float(compute_score(subtitle, video, hearing_impaired=hi)) / type_of_score * 100, 2) score = round(subtitle.score / max_score * 100, 2)
if used_sceneName == True: saved_subtitles = save_subtitles(video.name, [subtitle], single=single)
video = parse_video(path, None, providers={provider})
if single is True:
result = save_subtitles(video, [subtitle], single=True, encoding='utf-8')
else:
result = save_subtitles(video, [subtitle], encoding='utf-8')
except Exception as e: except Exception as e:
logging.exception('BAZARR Error saving subtitles file to disk for this file:' + path) logging.exception('BAZARR Error saving subtitles file to disk for this file:' + path)
return None return
else: else:
if len(result) > 0: if saved_subtitles:
downloaded_provider = result[0].provider_name for saved_subtitle in saved_subtitles:
downloaded_language = language_from_alpha3(result[0].language.alpha3) downloaded_provider = saved_subtitle.provider_name
downloaded_language_code2 = alpha2_from_alpha3(result[0].language.alpha3) downloaded_language = language_from_alpha3(saved_subtitle.language.alpha3)
downloaded_language_code3 = result[0].language.alpha3 downloaded_language_code2 = alpha2_from_alpha3(saved_subtitle.language.alpha3)
downloaded_path = get_subtitle_path(path, downloaded_language_code2) downloaded_language_code3 = saved_subtitle.language.alpha3
downloaded_path = saved_subtitle.storage_path
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path) logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode( message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
score) + "% using manual search." score) + "% using manual search."

@ -1675,13 +1675,14 @@ def manual_get_subtitle():
subtitle = request.forms.get('subtitle') subtitle = request.forms.get('subtitle')
sonarrSeriesId = request.forms.get('sonarrSeriesId') sonarrSeriesId = request.forms.get('sonarrSeriesId')
sonarrEpisodeId = request.forms.get('sonarrEpisodeId') sonarrEpisodeId = request.forms.get('sonarrEpisodeId')
title = request.forms.get('title')
providers_list = get_providers() providers_list = get_providers()
providers_auth = get_providers_auth() providers_auth = get_providers_auth()
try: try:
result = manual_download_subtitle(episodePath, language, hi, subtitle, selected_provider, providers_auth, result = manual_download_subtitle(episodePath, language, hi, subtitle, selected_provider, providers_auth,
sceneName, 'series') sceneName, title, 'series')
if result is not None: if result is not None:
history_log(1, sonarrSeriesId, sonarrEpisodeId, result) history_log(1, sonarrSeriesId, sonarrEpisodeId, result)
send_notifications(sonarrSeriesId, sonarrEpisodeId, result) send_notifications(sonarrSeriesId, sonarrEpisodeId, result)
@ -1753,13 +1754,14 @@ def manual_get_subtitle_movie():
selected_provider = request.forms.get('provider') selected_provider = request.forms.get('provider')
subtitle = request.forms.get('subtitle') subtitle = request.forms.get('subtitle')
radarrId = request.forms.get('radarrId') radarrId = request.forms.get('radarrId')
title = request.forms.get('title')
providers_list = get_providers() providers_list = get_providers()
providers_auth = get_providers_auth() providers_auth = get_providers_auth()
try: try:
result = manual_download_subtitle(moviePath, language, hi, subtitle, selected_provider, providers_auth, result = manual_download_subtitle(moviePath, language, hi, subtitle, selected_provider, providers_auth,
sceneName, 'movie') sceneName, title, 'movie')
if result is not None: if result is not None:
history_log_movie(1, radarrId, result) history_log_movie(1, radarrId, result)
send_notifications_movie(radarrId, result) send_notifications_movie(radarrId, result)

@ -558,7 +558,8 @@
language: $(button).attr("data-language"), language: $(button).attr("data-language"),
hi: hi, hi: hi,
sonarrSeriesId: sonarrSeriesId, sonarrSeriesId: sonarrSeriesId,
sonarrEpisodeId: sonarrEpisodeId sonarrEpisodeId: sonarrEpisodeId,
title: '{{!details[0].replace("'", "\\'")}}'
}; };
$('#loader_text').text("Downloading subtitle to disk..."); $('#loader_text').text("Downloading subtitle to disk...");

@ -500,7 +500,8 @@
sceneName: sceneName, sceneName: sceneName,
language: $(button).attr("data-language"), language: $(button).attr("data-language"),
hi: hi, hi: hi,
radarrId: radarrId radarrId: radarrId,
title: '{{!details[0].replace("'", "\\'")}}'
}; };
$('#loader_text').text("Downloading subtitle to disk..."); $('#loader_text').text("Downloading subtitle to disk...");

Loading…
Cancel
Save