@ -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,101 +360,82 @@ 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
logging . debug ( ' BAZARR Subtitles file saved to disk: ' + downloaded_path )
downloaded_path = saved_subtitle . storage_path
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode (
logging . debug ( ' BAZARR Subtitles file saved to disk: ' + downloaded_path )
score ) + " % u sing manual search. "
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode (
score ) + " % u sing manual search. "
if use_postprocessing is True :
command = pp_replace ( postprocessing_cmd , path , downloaded_path , downloaded_language ,
if use_postprocessing is True :
downloaded_language_code2 , downloaded_language_code3 )
command = pp_replace ( postprocessing_cmd , path , downloaded_path , downloaded_language ,
try :
downloaded_language_code2 , downloaded_language_code3 )
if os . name == ' nt ' :
try :
codepage = subprocess . Popen ( " chcp " , shell = True , stdout = subprocess . PIPE ,
if os . name == ' nt ' :
stderr = subprocess . PIPE )
codepage = subprocess . Popen ( " chcp " , shell = True , stdout = subprocess . PIPE ,
# wait for the process to terminate
stderr = subprocess . PIPE )
out_codepage , err_codepage = codepage . communicate ( )
# wait for the process to terminate
encoding = out_codepage . split ( ' : ' ) [ - 1 ] . strip ( )
out_codepage , err_codepage = codepage . communicate ( )
encoding = out_codepage . split ( ' : ' ) [ - 1 ] . strip ( )
process = subprocess . Popen ( command , shell = True , stdout = subprocess . PIPE ,
process = subprocess . Popen ( command , shell = True , stdout = subprocess . PIPE ,
stderr = subprocess . PIPE )
stderr = subprocess . PIPE )
# wait for the process to terminate
# wait for the process to terminate
out , err = process . communicate ( )
out , err = process . communicate ( )
if os . name == ' nt ' :
if os . name == ' nt ' :
out = out . decode ( encoding )
out = out . decode ( encoding )
except :
except :
if out == " " :
if out == " " :
logging . error (
logging . error (
' BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution ' )
' BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution ' )
else :
else :
logging . error ( ' BAZARR Post-processing result for file ' + path + ' : ' + out )
logging . error ( ' BAZARR Post-processing result for file ' + path + ' : ' + out )
else :
if out == " " :
logging . info (
' BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution ' )
else :
else :
logging . info ( ' BAZARR Post-processing result for file ' + path + ' : ' + out )
if out == " " :
logging . info (
' BAZARR Post-processing result for file ' + path + ' : Nothing returned from command execution ' )
else :
logging . info ( ' BAZARR Post-processing result for file ' + path + ' : ' + out )
return message
return message
else :
else :
logging . error (
logging . error (
' BAZARR Tried to manually download a subtitles for file: ' + path + " but we weren ' t able to do (probably throttled by ' + str(subtitle.provider_name) + ' . Please retry later or select a subtitles from another provider. " )
' BAZARR Tried to manually download a subtitles for file: ' + path + " but we weren ' t able to do (probably throttled by ' + str(subtitle.provider_name) + ' . Please retry later or select a subtitles from another provider. " )