@ -87,6 +87,7 @@ import math
import ast
import ast
import hashlib
import hashlib
import time
import time
import urllib
from get_languages import load_language_in_db , language_from_alpha3
from get_languages import load_language_in_db , language_from_alpha3
from get_providers import load_providers , get_providers , get_providers_auth
from get_providers import load_providers , get_providers , get_providers_auth
@ -199,7 +200,7 @@ def redirect_root():
@route ( base_url + ' shutdown ' )
@route ( base_url + ' shutdown ' )
def shutdown ( ) :
def shutdown ( ) :
try :
try :
stop_file = open ( os . path . join ( os. path . dirname ( os . path . dirname ( __file__ ) ) , " bazarr.stop " ) , " w " )
stop_file = open ( os . path . join ( config_dir , " bazarr.stop " ) , " w " )
except Exception as e :
except Exception as e :
logging . error ( ' Cannot create bazarr.stop file. ' )
logging . error ( ' Cannot create bazarr.stop file. ' )
else :
else :
@ -215,7 +216,7 @@ def restart():
logging . error ( ' Cannot stop CherryPy. ' )
logging . error ( ' Cannot stop CherryPy. ' )
else :
else :
try :
try :
restart_file = open ( os . path . join ( os. path . dirname ( os . path . dirname ( __file__ ) ) , " bazarr.restart " ) , " w " )
restart_file = open ( os . path . join ( config_dir , " bazarr.restart " ) , " w " )
except Exception as e :
except Exception as e :
logging . error ( ' Cannot create bazarr.restart file. ' )
logging . error ( ' Cannot create bazarr.restart file. ' )
else :
else :
@ -324,7 +325,7 @@ def series():
c . execute ( " SELECT table_shows.sonarrSeriesId, COUNT(table_episodes.missing_subtitles) FROM table_shows LEFT JOIN table_episodes ON table_shows.sonarrSeriesId=table_episodes.sonarrSeriesId WHERE table_shows.languages IS NOT ' None ' GROUP BY table_shows.sonarrSeriesId " )
c . execute ( " SELECT table_shows.sonarrSeriesId, COUNT(table_episodes.missing_subtitles) FROM table_shows LEFT JOIN table_episodes ON table_shows.sonarrSeriesId=table_episodes.sonarrSeriesId WHERE table_shows.languages IS NOT ' None ' GROUP BY table_shows.sonarrSeriesId " )
total_subtitles_list = c . fetchall ( )
total_subtitles_list = c . fetchall ( )
c . close ( )
c . close ( )
output = template ( ' series ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , missing_subtitles_list = missing_subtitles_list , total_subtitles_list = total_subtitles_list , languages = languages , missing_count = missing_count , page = page , max_page = max_page , base_url = base_url , single_language = single_language , page_size = page_size )
output = template ( ' series ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , missing_subtitles_list = missing_subtitles_list , total_subtitles_list = total_subtitles_list , languages = languages , missing_count = missing_count , page = page , max_page = max_page , base_url = base_url , single_language = single_language , page_size = page_size , current_port = port )
return output
return output
@route ( base_url + ' serieseditor ' )
@route ( base_url + ' serieseditor ' )
@ -346,7 +347,7 @@ def serieseditor():
c . execute ( " SELECT code2, name FROM table_settings_languages WHERE enabled = 1 " )
c . execute ( " SELECT code2, name FROM table_settings_languages WHERE enabled = 1 " )
languages = c . fetchall ( )
languages = c . fetchall ( )
c . close ( )
c . close ( )
output = template ( ' serieseditor ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , languages = languages , missing_count = missing_count , base_url = base_url , single_language = single_language )
output = template ( ' serieseditor ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , languages = languages , missing_count = missing_count , base_url = base_url , single_language = single_language , current_port = port )
return output
return output
@ -471,7 +472,7 @@ def episodes(no):
for key , season in itertools . groupby ( episodes , operator . itemgetter ( 2 ) ) :
for key , season in itertools . groupby ( episodes , operator . itemgetter ( 2 ) ) :
seasons_list . append ( list ( season ) )
seasons_list . append ( list ( season ) )
return template ( ' episodes ' , __file__ = __file__ , bazarr_version = bazarr_version , no = no , details = series_details , languages = languages , seasons = seasons_list , url_sonarr_short = url_sonarr_short , base_url = base_url , tvdbid = tvdbid , number = number )
return template ( ' episodes ' , __file__ = __file__ , bazarr_version = bazarr_version , no = no , details = series_details , languages = languages , seasons = seasons_list , url_sonarr_short = url_sonarr_short , base_url = base_url , tvdbid = tvdbid , number = number , current_port = port )
@route ( base_url + ' movies ' )
@route ( base_url + ' movies ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -498,7 +499,7 @@ def movies():
c . execute ( " SELECT code2, name FROM table_settings_languages WHERE enabled = 1 " )
c . execute ( " SELECT code2, name FROM table_settings_languages WHERE enabled = 1 " )
languages = c . fetchall ( )
languages = c . fetchall ( )
c . close ( )
c . close ( )
output = template ( ' movies ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , languages = languages , missing_count = missing_count , page = page , max_page = max_page , base_url = base_url , single_language = single_language , page_size = page_size )
output = template ( ' movies ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , languages = languages , missing_count = missing_count , page = page , max_page = max_page , base_url = base_url , single_language = single_language , page_size = page_size , current_port = port )
return output
return output
@route ( base_url + ' movieseditor ' )
@route ( base_url + ' movieseditor ' )
@ -520,7 +521,7 @@ def movieseditor():
c . execute ( " SELECT code2, name FROM table_settings_languages WHERE enabled = 1 " )
c . execute ( " SELECT code2, name FROM table_settings_languages WHERE enabled = 1 " )
languages = c . fetchall ( )
languages = c . fetchall ( )
c . close ( )
c . close ( )
output = template ( ' movieseditor ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , languages = languages , missing_count = missing_count , base_url = base_url , single_language = single_language )
output = template ( ' movieseditor ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , languages = languages , missing_count = missing_count , base_url = base_url , single_language = single_language , current_port = port )
return output
return output
@route ( base_url + ' edit_movieseditor ' , method = ' POST ' )
@route ( base_url + ' edit_movieseditor ' , method = ' POST ' )
@ -605,7 +606,7 @@ def movie(no):
languages = c . execute ( " SELECT code2, name FROM table_settings_languages WHERE enabled = 1 " ) . fetchall ( )
languages = c . execute ( " SELECT code2, name FROM table_settings_languages WHERE enabled = 1 " ) . fetchall ( )
c . close ( )
c . close ( )
return template ( ' movie ' , __file__ = __file__ , bazarr_version = bazarr_version , no = no , details = movies_details , languages = languages , url_radarr_short = url_radarr_short , base_url = base_url , tmdbid = tmdbid )
return template ( ' movie ' , __file__ = __file__ , bazarr_version = bazarr_version , no = no , details = movies_details , languages = languages , url_radarr_short = url_radarr_short , base_url = base_url , tmdbid = tmdbid , current_port = port )
@route ( base_url + ' scan_disk/<no:int> ' , method = ' GET ' )
@route ( base_url + ' scan_disk/<no:int> ' , method = ' GET ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -651,7 +652,7 @@ def search_missing_subtitles_movie(no):
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
def history ( ) :
def history ( ) :
authorize ( )
authorize ( )
return template ( ' history ' , __file__ = __file__ , bazarr_version = bazarr_version , base_url = base_url )
return template ( ' history ' , __file__ = __file__ , bazarr_version = bazarr_version , base_url = base_url , current_port = port )
@route ( base_url + ' historyseries ' )
@route ( base_url + ' historyseries ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -689,7 +690,7 @@ def historyseries():
data = c . fetchall ( )
data = c . fetchall ( )
c . close ( )
c . close ( )
data = reversed ( sorted ( data , key = operator . itemgetter ( 4 ) ) )
data = reversed ( sorted ( data , key = operator . itemgetter ( 4 ) ) )
return template ( ' historyseries ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , row_count = row_count , page = page , max_page = max_page , stats = stats , base_url = base_url , page_size = page_size )
return template ( ' historyseries ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , row_count = row_count , page = page , max_page = max_page , stats = stats , base_url = base_url , page_size = page_size , current_port = port )
@route ( base_url + ' historymovies ' )
@route ( base_url + ' historymovies ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -727,13 +728,13 @@ def historymovies():
data = c . fetchall ( )
data = c . fetchall ( )
c . close ( )
c . close ( )
data = reversed ( sorted ( data , key = operator . itemgetter ( 2 ) ) )
data = reversed ( sorted ( data , key = operator . itemgetter ( 2 ) ) )
return template ( ' historymovies ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , row_count = row_count , page = page , max_page = max_page , stats = stats , base_url = base_url , page_size = page_size )
return template ( ' historymovies ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , row_count = row_count , page = page , max_page = max_page , stats = stats , base_url = base_url , page_size = page_size , current_port = port )
@route ( base_url + ' wanted ' )
@route ( base_url + ' wanted ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
def wanted ( ) :
def wanted ( ) :
authorize ( )
authorize ( )
return template ( ' wanted ' , __file__ = __file__ , bazarr_version = bazarr_version , base_url = base_url )
return template ( ' wanted ' , __file__ = __file__ , bazarr_version = bazarr_version , base_url = base_url , current_port = port )
@route ( base_url + ' wantedseries ' )
@route ( base_url + ' wantedseries ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -761,7 +762,7 @@ def wantedseries():
c . execute ( " SELECT table_shows.title, table_episodes.season || ' x ' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles, table_episodes.sonarrSeriesId, path_substitution(table_episodes.path), table_shows.hearing_impaired, table_episodes.sonarrEpisodeId, table_episodes.scene_name FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != ' [] ' " + monitored_only_query_string + " ORDER BY table_episodes._rowid_ DESC LIMIT ? OFFSET ? " , ( page_size , offset , ) )
c . execute ( " SELECT table_shows.title, table_episodes.season || ' x ' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles, table_episodes.sonarrSeriesId, path_substitution(table_episodes.path), table_shows.hearing_impaired, table_episodes.sonarrEpisodeId, table_episodes.scene_name FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != ' [] ' " + monitored_only_query_string + " ORDER BY table_episodes._rowid_ DESC LIMIT ? OFFSET ? " , ( page_size , offset , ) )
data = c . fetchall ( )
data = c . fetchall ( )
c . close ( )
c . close ( )
return template ( ' wantedseries ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , missing_count = missing_count , page = page , max_page = max_page , base_url = base_url , page_size = page_size )
return template ( ' wantedseries ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , missing_count = missing_count , page = page , max_page = max_page , base_url = base_url , page_size = page_size , current_port = port )
@route ( base_url + ' wantedmovies ' )
@route ( base_url + ' wantedmovies ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -789,7 +790,7 @@ def wantedmovies():
c . execute ( " SELECT title, missing_subtitles, radarrId, path_substitution(path), hearing_impaired, sceneName FROM table_movies WHERE missing_subtitles != ' [] ' " + monitored_only_query_string + " ORDER BY _rowid_ DESC LIMIT ? OFFSET ? " , ( page_size , offset , ) )
c . execute ( " SELECT title, missing_subtitles, radarrId, path_substitution(path), hearing_impaired, sceneName FROM table_movies WHERE missing_subtitles != ' [] ' " + monitored_only_query_string + " ORDER BY _rowid_ DESC LIMIT ? OFFSET ? " , ( page_size , offset , ) )
data = c . fetchall ( )
data = c . fetchall ( )
c . close ( )
c . close ( )
return template ( ' wantedmovies ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , missing_count = missing_count , page = page , max_page = max_page , base_url = base_url , page_size = page_size )
return template ( ' wantedmovies ' , __file__ = __file__ , bazarr_version = bazarr_version , rows = data , missing_count = missing_count , page = page , max_page = max_page , base_url = base_url , page_size = page_size , current_port = port )
@route ( base_url + ' wanted_search_missing_subtitles ' )
@route ( base_url + ' wanted_search_missing_subtitles ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -822,7 +823,7 @@ def settings():
settings_sonarr = get_sonarr_settings ( )
settings_sonarr = get_sonarr_settings ( )
settings_radarr = get_radarr_settings ( )
settings_radarr = get_radarr_settings ( )
return template ( ' settings ' , __file__ = __file__ , bazarr_version = bazarr_version , settings_general = settings_general , settings_proxy = settings_proxy , settings_auth = settings_auth , settings_languages = settings_languages , settings_providers = settings_providers , settings_sonarr = settings_sonarr , settings_radarr = settings_radarr , settings_notifier = settings_notifier , base_url = base_url )
return template ( ' settings ' , __file__ = __file__ , bazarr_version = bazarr_version , settings_general = settings_general , settings_proxy = settings_proxy , settings_auth = settings_auth , settings_languages = settings_languages , settings_providers = settings_providers , settings_sonarr = settings_sonarr , settings_radarr = settings_radarr , settings_notifier = settings_notifier , base_url = base_url , current_port = port )
@route ( base_url + ' save_settings ' , method = ' POST ' )
@route ( base_url + ' save_settings ' , method = ' POST ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -1435,7 +1436,7 @@ def system():
for release in r . json ( ) :
for release in r . json ( ) :
releases . append ( [ release [ ' name ' ] , release [ ' body ' ] ] )
releases . append ( [ release [ ' name ' ] , release [ ' body ' ] ] )
return template ( ' system ' , __file__ = __file__ , bazarr_version = bazarr_version , base_url = base_url , task_list = task_list , row_count = row_count , max_page = max_page , page_size = page_size , releases = releases )
return template ( ' system ' , __file__ = __file__ , bazarr_version = bazarr_version , base_url = base_url , task_list = task_list , row_count = row_count , max_page = max_page , page_size = page_size , releases = releases , current_port = port )
@route ( base_url + ' logs/<page:int> ' )
@route ( base_url + ' logs/<page:int> ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -1449,7 +1450,7 @@ def get_logs(page):
logs_complete . append ( line . rstrip ( ) )
logs_complete . append ( line . rstrip ( ) )
logs = logs_complete [ begin : end ]
logs = logs_complete [ begin : end ]
return template ( ' logs ' , logs = logs , base_url = base_url )
return template ( ' logs ' , logs = logs , base_url = base_url , current_port = port )
@route ( base_url + ' execute/<taskid> ' )
@route ( base_url + ' execute/<taskid> ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
@ -1689,6 +1690,7 @@ def api_history():
@route ( base_url + ' test_url/<protocol>/<url:path> ' , method = ' GET ' )
@route ( base_url + ' test_url/<protocol>/<url:path> ' , method = ' GET ' )
@custom_auth_basic ( check_credentials )
@custom_auth_basic ( check_credentials )
def test_url ( protocol , url ) :
def test_url ( protocol , url ) :
url = urllib . unquote ( url )
try :
try :
result = requests . get ( protocol + " :// " + url , allow_redirects = False ) . json ( ) [ ' version ' ]
result = requests . get ( protocol + " :// " + url , allow_redirects = False ) . json ( ) [ ' version ' ]
except :
except :