@ -5,7 +5,7 @@ import logging
import subprocess
import subprocess
from babelfish import *
from babelfish import *
from subliminal import *
from subliminal import *
from pycountry import *
from get_languages import *
from bs4 import UnicodeDammit
from bs4 import UnicodeDammit
from get_general_settings import *
from get_general_settings import *
from list_subtitles import *
from list_subtitles import *
@ -24,6 +24,12 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
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 ]
if language == ' pob ' :
lang_obj = Language ( ' por ' , ' BR ' )
else :
lang_obj = Language ( language )
try :
try :
if sceneName is None or use_scenename == " False " :
if sceneName is None or use_scenename == " False " :
used_sceneName = False
used_sceneName = False
@ -36,7 +42,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
return None
return None
else :
else :
try :
try :
best_subtitles = download_best_subtitles ( [ video ] , { Language( language ) } , providers = providers , min_score = minimum_score , hearing_impaired = hi , provider_configs = providers_auth )
best_subtitles = download_best_subtitles ( [ video ] , { lang_obj } , providers = providers , min_score = minimum_score , hearing_impaired = hi , provider_configs = providers_auth )
except Exception as e :
except Exception as e :
logging . exception ( ' Error trying to get the best subtitles for this file: ' + path )
logging . exception ( ' Error trying to get the best subtitles for this file: ' + path )
return None
return None
@ -61,9 +67,9 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
return None
return None
else :
else :
downloaded_provider = str ( result [ 0 ] [ 0 ] ) . strip ( ' <> ' ) . split ( ' ' ) [ 0 ] [ : - 8 ]
downloaded_provider = str ( result [ 0 ] [ 0 ] ) . strip ( ' <> ' ) . split ( ' ' ) [ 0 ] [ : - 8 ]
downloaded_language = pycountry. languages . lookup ( str ( str ( result [ 0 ] [ 0 ] ) . strip ( ' <> ' ) . split ( ' ' ) [ 2 ] . strip ( ' [] ' ) ) ) . name
downloaded_language = language_from_alpha3( language )
downloaded_language_code2 = pycountry. languages . lookup ( downloaded_language ) . alpha_2
downloaded_language_code2 = alpha2_from_alpha3( language )
downloaded_language_code3 = pycountry. languages. lookup ( downloaded_language ) . alpha_3
downloaded_language_code3 = language
downloaded_path = result [ 1 ]
downloaded_path = result [ 1 ]
if used_sceneName == True :
if used_sceneName == True :
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode ( score ) + " % u sing this scene name obtained from Sonarr: " + sceneName
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode ( score ) + " % u sing this scene name obtained from Sonarr: " + sceneName
@ -126,7 +132,7 @@ def series_download_subtitles(no):
for episode in episodes_details :
for episode in episodes_details :
for language in ast . literal_eval ( episode [ 1 ] ) :
for language in ast . literal_eval ( episode [ 1 ] ) :
message = download_subtitle ( path_replace ( episode [ 0 ] ) , str ( pycountry. languages . lookup ( language ) . alpha_3 ) , series_details [ 0 ] , providers_list , providers_auth , episode [ 3 ] , ' series ' )
message = download_subtitle ( path_replace ( episode [ 0 ] ) , str ( alpha3_from_alpha2( language ) ) , series_details [ 0 ] , providers_list , providers_auth , episode [ 3 ] , ' series ' )
if message is not None :
if message is not None :
store_subtitles ( path_replace ( episode [ 0 ] ) )
store_subtitles ( path_replace ( episode [ 0 ] ) )
history_log ( 1 , no , episode [ 2 ] , message )
history_log ( 1 , no , episode [ 2 ] , message )
@ -159,7 +165,7 @@ def movies_download_subtitles(no):
providers_auth = None
providers_auth = None
for language in ast . literal_eval ( movie [ 1 ] ) :
for language in ast . literal_eval ( movie [ 1 ] ) :
message = download_subtitle ( path_replace_movie ( movie [ 0 ] ) , str ( pycountry. languages . lookup ( language ) . alpha_3 ) , movie [ 4 ] , providers_list , providers_auth , movie [ 3 ] , ' movies ' )
message = download_subtitle ( path_replace_movie ( movie [ 0 ] ) , str ( alpha3_from_alpha2( language ) ) , movie [ 4 ] , providers_list , providers_auth , movie [ 3 ] , ' movies ' )
if message is not None :
if message is not None :
store_subtitles_movie ( path_replace_movie ( movie [ 0 ] ) )
store_subtitles_movie ( path_replace_movie ( movie [ 0 ] ) )
history_log_movie ( 1 , no , message )
history_log_movie ( 1 , no , message )
@ -193,7 +199,7 @@ def wanted_download_subtitles(path):
for episode in episodes_details :
for episode in episodes_details :
for language in ast . literal_eval ( episode [ 1 ] ) :
for language in ast . literal_eval ( episode [ 1 ] ) :
message = download_subtitle ( path_replace ( episode [ 0 ] ) , str ( pycountry. languages . lookup ( language ) . alpha_3 ) , episode [ 4 ] , providers_list , providers_auth , episode [ 5 ] , ' series ' )
message = download_subtitle ( path_replace ( episode [ 0 ] ) , str ( alpha3_from_alpha2( language ) ) , episode [ 4 ] , providers_list , providers_auth , episode [ 5 ] , ' series ' )
if message is not None :
if message is not None :
store_subtitles ( path_replace ( episode [ 0 ] ) )
store_subtitles ( path_replace ( episode [ 0 ] ) )
list_missing_subtitles ( episode [ 3 ] )
list_missing_subtitles ( episode [ 3 ] )
@ -227,7 +233,7 @@ def wanted_download_subtitles_movie(path):
for movie in movies_details :
for movie in movies_details :
for language in ast . literal_eval ( movie [ 1 ] ) :
for language in ast . literal_eval ( movie [ 1 ] ) :
message = download_subtitle ( path_replace_movie ( movie [ 0 ] ) , str ( pycountry. languages . lookup ( language ) . alpha_3 ) , movie [ 4 ] , providers_list , providers_auth , movie [ 5 ] , ' movies ' )
message = download_subtitle ( path_replace_movie ( movie [ 0 ] ) , str ( alpha3_from_alpha2( language ) ) , movie [ 4 ] , providers_list , providers_auth , movie [ 5 ] , ' movies ' )
if message is not None :
if message is not None :
store_subtitles_movie ( path_replace_movie ( movie [ 0 ] ) )
store_subtitles_movie ( path_replace_movie ( movie [ 0 ] ) )
list_missing_subtitles_movies ( movie [ 3 ] )
list_missing_subtitles_movies ( movie [ 3 ] )