@ -65,7 +65,7 @@ def get_video(path, title, sceneName, use_scenename, providers=None, media_type=
video . used_scene_name = dont_use_actual_file
video . original_name = original_name
video . original_path = original_path
refine_from_db ( original_path , video )
refine_from_db ( original_path , video )
logging . debug ( ' BAZARR is using those video object properties: %s ' , vars ( video ) )
return video
@ -100,7 +100,8 @@ 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 , forced_minimum_score = None , is_upgrade = False ) :
def download_subtitle ( path , 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
@ -187,7 +188,8 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce
try :
fld = get_target_folder ( path )
chmod = int ( settings . general . chmod , 8 ) if not sys . platform . startswith ( ' win ' ) and settings . general . getboolean ( ' chmod_enabled ' ) else None
chmod = int ( settings . general . chmod , 8 ) if not sys . platform . startswith (
' win ' ) and settings . general . getboolean ( ' chmod_enabled ' ) else None
saved_subtitles = save_subtitles ( video . original_path , subtitles , single = single ,
tags = None , # fixme
directory = fld ,
@ -224,7 +226,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 ,
subtitle . language . forced )
try :
if os . name == ' nt ' :
codepage = subprocess . Popen ( " chcp " , shell = True , stdout = subprocess . PIPE ,
@ -359,7 +362,8 @@ 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 , media_type ) :
def manual_download_subtitle ( path , language , hi , forced , subtitle , provider , providers_auth , sceneName , title ,
media_type ) :
logging . debug ( ' BAZARR Manually downloading subtitles for this file: ' + path )
if settings . general . getboolean ( ' utf8_encode ' ) :
@ -394,7 +398,8 @@ def manual_download_subtitle(path, language, hi, forced, subtitle, provider, pro
try :
score = round ( subtitle . score / max_score * 100 , 2 )
fld = get_target_folder ( path )
chmod = int ( settings . general . chmod , 8 ) if not sys . platform . startswith ( ' win ' ) and settings . general . getboolean ( ' chmod_enabled ' ) else None
chmod = int ( settings . general . chmod , 8 ) if not sys . platform . startswith (
' win ' ) and settings . general . getboolean ( ' chmod_enabled ' ) else None
saved_subtitles = save_subtitles ( video . original_path , [ subtitle ] , single = single ,
tags = None , # fixme
directory = fld ,
@ -423,7 +428,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 ,
subtitle . language . forced )
try :
if os . name == ' nt ' :
codepage = subprocess . Popen ( " chcp " , shell = True , stdout = subprocess . PIPE ,
@ -490,7 +496,8 @@ def series_download_subtitles(no):
for i , episode in enumerate ( episodes_details , 1 ) :
for language in ast . literal_eval ( episode [ 1 ] ) :
if language is not None :
notifications . write ( msg = ' Searching for series subtitles... ' , queue = ' get_subtitle ' , item = i , length = count_episodes_details )
notifications . write ( msg = ' Searching for series subtitles... ' , queue = ' get_subtitle ' , item = i ,
length = count_episodes_details )
result = download_subtitle ( path_replace ( episode [ 0 ] ) , str ( alpha3_from_alpha2 ( language ) ) ,
series_details [ 0 ] , series_details [ 2 ] , providers_list ,
providers_auth , str ( episode [ 3 ] ) , series_details [ 1 ] , ' series ' )
@ -507,7 +514,8 @@ def series_download_subtitles(no):
list_missing_subtitles ( no )
if count_episodes_details :
notifications . write ( msg = ' Searching completed. Please reload the page. ' , type = ' success ' , duration = ' permanent ' , button = ' refresh ' , queue = ' get_subtitle ' )
notifications . write ( msg = ' Searching completed. Please reload the page. ' , type = ' success ' , duration = ' permanent ' ,
button = ' refresh ' , queue = ' get_subtitle ' )
def episode_download_subtitles ( no ) :
@ -519,7 +527,8 @@ def episode_download_subtitles(no):
conn_db = sqlite3 . connect ( os . path . join ( args . config_dir , ' db ' , ' bazarr.db ' ) , timeout = 30 )
c_db = conn_db . cursor ( )
episodes_details = c_db . 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 INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.sonarrEpisodeId = ? ' + monitored_only_query_string , ( no , ) ) . fetchall ( )
' 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 INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.sonarrEpisodeId = ? ' + monitored_only_query_string ,
( no , ) ) . fetchall ( )
c_db . close ( )
providers_list = get_providers ( )
@ -579,7 +588,8 @@ def movies_download_subtitles(no):
list_missing_subtitles_movies ( no )
if count_movie :
notifications . write ( msg = ' Searching completed. Please reload the page. ' , type = ' success ' , duration = ' permanent ' , button = ' refresh ' , queue = ' get_subtitle ' )
notifications . write ( msg = ' Searching completed. Please reload the page. ' , type = ' success ' , duration = ' permanent ' ,
button = ' refresh ' , queue = ' get_subtitle ' )
def wanted_download_subtitles ( path , l , count_episodes ) :
@ -617,7 +627,8 @@ def wanted_download_subtitles(path, l, count_episodes):
if attempt [ i ] [ 0 ] == language :
language = language . split ( ' : ' ) [ 0 ]
if search_active ( attempt [ i ] [ 1 ] ) :
notifications . write ( msg = ' Searching for series subtitles... ' , queue = ' get_subtitle ' , item = l , length = count_episodes )
notifications . write ( msg = ' Searching for series subtitles... ' , queue = ' get_subtitle ' , item = l ,
length = count_episodes )
result = download_subtitle ( path_replace ( episode [ 0 ] ) , str ( alpha3_from_alpha2 ( language ) ) ,
episode [ 4 ] , episode [ 8 ] , providers_list , providers_auth ,
str ( episode [ 5 ] ) , episode [ 7 ] , ' series ' )
@ -671,7 +682,8 @@ def wanted_download_subtitles_movie(path, l, count_movies):
if attempt [ i ] [ 0 ] == language :
language = language . split ( ' : ' ) [ 0 ]
if search_active ( attempt [ i ] [ 1 ] ) is True :
notifications . write ( msg = ' Searching for movies subtitles... ' , queue = ' get_subtitle ' , item = l , length = count_movies )
notifications . write ( msg = ' Searching for movies subtitles... ' , queue = ' get_subtitle ' , item = l ,
length = count_movies )
result = download_subtitle ( path_replace_movie ( movie [ 0 ] ) , str ( alpha3_from_alpha2 ( language ) ) ,
movie [ 4 ] , movie [ 8 ] , providers_list , providers_auth , str ( movie [ 5 ] ) ,
movie [ 7 ] , ' movie ' )
@ -719,7 +731,7 @@ def wanted_search_missing_subtitles():
providers = get_providers ( )
if settings . general . getboolean ( ' use_sonarr ' ) :
if providers :
count_episodes = len ( episodes )
count_episodes = len ( episodes )
for i , episode in enumerate ( episodes , 1 ) :
wanted_download_subtitles ( episode [ 0 ] , i , count_episodes )
else :
@ -737,7 +749,8 @@ def wanted_search_missing_subtitles():
logging . info ( ' BAZARR Finished searching for missing subtitles. Check histories for more information. ' )
notifications . write ( msg = ' Searching completed. Please reload the page. ' , type = ' success ' , duration = ' permanent ' , button = ' refresh ' , queue = ' get_subtitle ' )
notifications . write ( msg = ' Searching completed. Please reload the page. ' , type = ' success ' , duration = ' permanent ' ,
button = ' refresh ' , queue = ' get_subtitle ' )
def search_active ( timestamp ) :
@ -763,7 +776,9 @@ def refine_from_db(path, video):
if isinstance ( video , Episode ) :
db = sqlite3 . connect ( os . path . join ( args . config_dir , ' db ' , ' bazarr.db ' ) , timeout = 30 )
c = db . cursor ( )
data = c . execute ( " SELECT table_shows.title, table_episodes.season, table_episodes.episode, table_episodes.title, table_shows.year, table_shows.tvdbId, table_shows.alternateTitles, table_episodes.format, table_episodes.resolution, table_episodes.video_codec, table_episodes.audio_codec FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? " , ( unicode ( path_replace_reverse ( path ) ) , ) ) . fetchone ( )
data = c . execute (
" SELECT table_shows.title, table_episodes.season, table_episodes.episode, table_episodes.title, table_shows.year, table_shows.tvdbId, table_shows.alternateTitles, table_episodes.format, table_episodes.resolution, table_episodes.video_codec, table_episodes.audio_codec FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? " ,
( unicode ( path_replace_reverse ( path ) ) , ) ) . fetchone ( )
db . close ( )
if data :
video . series , year , country = series_re . match ( data [ 0 ] ) . groups ( )
@ -785,10 +800,12 @@ def refine_from_db(path, video):
elif isinstance ( video , Movie ) :
db = sqlite3 . connect ( os . path . join ( args . config_dir , ' db ' , ' bazarr.db ' ) , timeout = 30 )
c = db . cursor ( )
data = c . execute ( " SELECT title, year, alternativeTitles, format, resolution, video_codec, audio_codec, imdbId FROM table_movies WHERE path = ? " , ( unicode ( path_replace_reverse_movie ( path ) ) , ) ) . fetchone ( )
data = c . execute (
" SELECT title, year, alternativeTitles, format, resolution, video_codec, audio_codec, imdbId FROM table_movies WHERE path = ? " ,
( unicode ( path_replace_reverse_movie ( path ) ) , ) ) . fetchone ( )
db . close ( )
if data :
video . title = re . sub ( r ' ( \ ( \ d \ d \ d \ d \ )) ' , ' ' , data [ 0 ] )
video . title = re . sub ( r ' ( \ ( \ d \ d \ d \ d \ )) ' , ' ' , data [ 0 ] )
if data [ 1 ] :
if int ( data [ 1 ] ) > 0 : video . year = int ( data [ 1 ] )
if data [ 7 ] : video . imdb_id = data [ 7 ]