1- bazarr_version = '0.6.4 '
1+ bazarr_version = '0.6.5 '
22
33import gc
44gc .enable ()
@@ -85,7 +85,8 @@ def configure_logging():
8585import time
8686
8787from get_languages import load_language_in_db , language_from_alpha3
88- from get_providers import *
88+ from get_providers import load_providers , get_providers , get_providers_auth
89+ load_providers ()
8990
9091from get_series import *
9192from get_episodes import *
@@ -312,26 +313,29 @@ def serieseditor():
312313 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 )
313314 return output
314315
316+
315317@route (base_url + 'search_json/<query>' , method = 'GET' )
316318@custom_auth_basic (check_credentials )
317319def search_json (query ):
318320 authorize ()
319321 db = sqlite3 .connect (os .path .join (config_dir , 'db/bazarr.db' ), timeout = 30 )
320322 c = db .cursor ()
321-
322- c .execute ("SELECT title, sonarrSeriesId FROM table_shows WHERE title LIKE ? ORDER BY title" , ('%' + query + '%' ,))
323- series = c .fetchall ()
324-
325- c .execute ("SELECT title, radarrId FROM table_movies WHERE title LIKE ? ORDER BY title" , ('%' + query + '%' ,))
326- movies = c .fetchall ()
327-
323+
328324 search_list = []
329- for serie in series :
330- search_list .append (dict ([('name' , serie [0 ]), ('url' , base_url + 'episodes/' + str (serie [1 ]))]))
331-
332- for movie in movies :
333- search_list .append (dict ([('name' , movie [0 ]), ('url' , base_url + 'movie/' + str (movie [1 ]))]))
334-
325+ if get_general_settings ()[12 ] is True :
326+ c .execute ("SELECT title, sonarrSeriesId FROM table_shows WHERE title LIKE ? ORDER BY title" ,
327+ ('%' + query + '%' ,))
328+ series = c .fetchall ()
329+ for serie in series :
330+ search_list .append (dict ([('name' , serie [0 ]), ('url' , base_url + 'episodes/' + str (serie [1 ]))]))
331+
332+ if get_general_settings ()[13 ] is True :
333+ c .execute ("SELECT title, radarrId FROM table_movies WHERE title LIKE ? ORDER BY title" , ('%' + query + '%' ,))
334+ movies = c .fetchall ()
335+ for movie in movies :
336+ search_list .append (dict ([('name' , movie [0 ]), ('url' , base_url + 'movie/' + str (movie [1 ]))]))
337+ c .close ()
338+
335339 response .content_type = 'application/json'
336340 return dict (items = search_list )
337341
@@ -796,6 +800,8 @@ def save_settings():
796800 settings_general_ip = request .forms .get ('settings_general_ip' )
797801 settings_general_port = request .forms .get ('settings_general_port' )
798802 settings_general_baseurl = request .forms .get ('settings_general_baseurl' )
803+ if settings_general_baseurl .endswith ('/' ) is False :
804+ settings_general_baseurl += '/'
799805 settings_general_loglevel = request .forms .get ('settings_general_loglevel' )
800806 settings_general_sourcepath = request .forms .getall ('settings_general_sourcepath' )
801807 settings_general_destpath = request .forms .getall ('settings_general_destpath' )
@@ -1473,28 +1479,8 @@ def get_subtitle():
14731479 sonarrEpisodeId = request .forms .get ('sonarrEpisodeId' )
14741480 # tvdbid = request.forms.get('tvdbid')
14751481
1476- db = sqlite3 .connect (os .path .join (config_dir , 'db/bazarr.db' ), timeout = 30 )
1477- c = db .cursor ()
1478- c .execute ("SELECT * FROM table_settings_providers WHERE enabled = 1" )
1479- enabled_providers = c .fetchall ()
1480- c .close ()
1481-
1482- providers_list = []
1483- providers_auth = {}
1484- if len (enabled_providers ) > 0 :
1485- for provider in enabled_providers :
1486- providers_list .append (provider [0 ])
1487- try :
1488- if provider [2 ] is not '' and provider [3 ] is not '' :
1489- provider_auth = providers_auth .append (provider [0 ])
1490- provider_auth .update ({'username' :providers [2 ], 'password' :providers [3 ]})
1491- else :
1492- providers_auth = None
1493- except :
1494- providers_auth = None
1495- else :
1496- providers_list = None
1497- providers_auth = None
1482+ providers_list = get_providers ()
1483+ providers_auth = get_providers_auth ()
14981484
14991485 try :
15001486 result = download_subtitle (episodePath , language , hi , providers_list , providers_auth , sceneName , 'series' )
@@ -1518,28 +1504,8 @@ def manual_search_json():
15181504 language = request .forms .get ('language' )
15191505 hi = request .forms .get ('hi' )
15201506
1521- db = sqlite3 .connect (os .path .join (config_dir , 'db/bazarr.db' ), timeout = 30 )
1522- c = db .cursor ()
1523- c .execute ("SELECT * FROM table_settings_providers WHERE enabled = 1" )
1524- enabled_providers = c .fetchall ()
1525- c .close ()
1526-
1527- providers_list = []
1528- providers_auth = {}
1529- if len (enabled_providers ) > 0 :
1530- for provider in enabled_providers :
1531- providers_list .append (provider [0 ])
1532- try :
1533- if provider [2 ] is not '' and provider [3 ] is not '' :
1534- provider_auth = providers_auth .append (provider [0 ])
1535- provider_auth .update ({'username' :providers [2 ], 'password' :providers [3 ]})
1536- else :
1537- providers_auth = None
1538- except :
1539- providers_auth = None
1540- else :
1541- providers_list = None
1542- providers_auth = None
1507+ providers_list = get_providers ()
1508+ providers_auth = get_providers_auth ()
15431509
15441510 data = manual_search (episodePath , language , hi , providers_list , providers_auth , sceneName , 'series' )
15451511 return dict (data = data )
@@ -1559,19 +1525,8 @@ def manual_get_subtitle():
15591525 sonarrSeriesId = request .forms .get ('sonarrSeriesId' )
15601526 sonarrEpisodeId = request .forms .get ('sonarrEpisodeId' )
15611527
1562- db = sqlite3 .connect (os .path .join (config_dir , 'db/bazarr.db' ), timeout = 30 )
1563- c = db .cursor ()
1564- provider = c .execute ("SELECT * FROM table_settings_providers WHERE name = ?" ,(selected_provider ,)).fetchone ()
1565- c .close ()
1566- providers_auth = {}
1567- try :
1568- if provider [2 ] is not '' and provider [3 ] is not '' :
1569- provider_auth = providers_auth .append (provider [0 ])
1570- provider_auth .update ({'username' :providers [2 ], 'password' :providers [3 ]})
1571- else :
1572- providers_auth = None
1573- except :
1574- providers_auth = None
1528+ providers_list = get_providers ()
1529+ providers_auth = get_providers_auth ()
15751530
15761531 try :
15771532 result = manual_download_subtitle (episodePath , language , hi , subtitle , selected_provider , providers_auth , sceneName , 'series' )
@@ -1597,28 +1552,8 @@ def get_subtitle_movie():
15971552 radarrId = request .forms .get ('radarrId' )
15981553 # tmdbid = request.forms.get('tmdbid')
15991554
1600- db = sqlite3 .connect (os .path .join (config_dir , 'db/bazarr.db' ), timeout = 30 )
1601- c = db .cursor ()
1602- c .execute ("SELECT * FROM table_settings_providers WHERE enabled = 1" )
1603- enabled_providers = c .fetchall ()
1604- c .close ()
1605-
1606- providers_list = []
1607- providers_auth = {}
1608- if len (enabled_providers ) > 0 :
1609- for provider in enabled_providers :
1610- providers_list .append (provider [0 ])
1611- try :
1612- if provider [2 ] is not '' and provider [3 ] is not '' :
1613- provider_auth = providers_auth .append (provider [0 ])
1614- provider_auth .update ({'username' :providers [2 ], 'password' :providers [3 ]})
1615- else :
1616- providers_auth = None
1617- except :
1618- providers_auth = None
1619- else :
1620- providers_list = None
1621- providers_auth = None
1555+ providers_list = get_providers ()
1556+ providers_auth = get_providers_auth ()
16221557
16231558 try :
16241559 result = download_subtitle (moviePath , language , hi , providers_list , providers_auth , sceneName , 'movie' )
@@ -1642,28 +1577,8 @@ def manual_search_movie_json():
16421577 language = request .forms .get ('language' )
16431578 hi = request .forms .get ('hi' )
16441579
1645- db = sqlite3 .connect (os .path .join (config_dir , 'db/bazarr.db' ), timeout = 30 )
1646- c = db .cursor ()
1647- c .execute ("SELECT * FROM table_settings_providers WHERE enabled = 1" )
1648- enabled_providers = c .fetchall ()
1649- c .close ()
1650-
1651- providers_list = []
1652- providers_auth = {}
1653- if len (enabled_providers ) > 0 :
1654- for provider in enabled_providers :
1655- providers_list .append (provider [0 ])
1656- try :
1657- if provider [2 ] is not '' and provider [3 ] is not '' :
1658- provider_auth = providers_auth .append (provider [0 ])
1659- provider_auth .update ({'username' :providers [2 ], 'password' :providers [3 ]})
1660- else :
1661- providers_auth = None
1662- except :
1663- providers_auth = None
1664- else :
1665- providers_list = None
1666- providers_auth = None
1580+ providers_list = get_providers ()
1581+ providers_auth = get_providers_auth ()
16671582
16681583 data = manual_search (moviePath , language , hi , providers_list , providers_auth , sceneName , 'movie' )
16691584 return dict (data = data )
@@ -1682,19 +1597,8 @@ def manual_get_subtitle_movie():
16821597 subtitle = request .forms .get ('subtitle' )
16831598 radarrId = request .forms .get ('radarrId' )
16841599
1685- db = sqlite3 .connect (os .path .join (config_dir , 'db/bazarr.db' ), timeout = 30 )
1686- c = db .cursor ()
1687- provider = c .execute ("SELECT * FROM table_settings_providers WHERE name = ?" ,(selected_provider ,)).fetchone ()
1688- c .close ()
1689- providers_auth = {}
1690- try :
1691- if provider [2 ] is not '' and provider [3 ] is not '' :
1692- provider_auth = providers_auth .append (provider [0 ])
1693- provider_auth .update ({'username' :providers [2 ], 'password' :providers [3 ]})
1694- else :
1695- providers_auth = None
1696- except :
1697- providers_auth = None
1600+ providers_list = get_providers ()
1601+ providers_auth = get_providers_auth ()
16981602
16991603 try :
17001604 result = manual_download_subtitle (moviePath , language , hi , subtitle , selected_provider , providers_auth , sceneName , 'movie' )
@@ -1756,6 +1660,9 @@ def test_url(protocol, url):
17561660 else :
17571661 return dict (status = True , version = result )
17581662
1663+ import warnings
1664+ # Mute DeprecationWarning
1665+ warnings .simplefilter ("ignore" , DeprecationWarning )
17591666
17601667logging .info ('Bazarr is started and waiting for request on http://' + str (ip ) + ':' + str (port ) + str (base_url ))
17611668run (host = ip , port = port , server = 'waitress' , app = app )
0 commit comments