Providers authentication implementation

pull/26/head
morpheus65535 7 years ago
parent 248b524b92
commit a10574f805

@ -21,7 +21,7 @@ from fdsend import send_file
import urllib
from init_db import *
from update_db import *
import update_db
from get_languages import *
from get_providers import *
@ -283,6 +283,17 @@ def save_settings():
c.execute("UPDATE table_settings_providers SET enabled = 0")
for item in settings_subliminal_providers:
c.execute("UPDATE table_settings_providers SET enabled = '1' WHERE name = ?", (item,))
settings_addic7ed_username = request.forms.get('settings_addic7ed_username')
settings_addic7ed_password = request.forms.get('settings_addic7ed_password')
c.execute("UPDATE table_settings_providers SET username = ?, password = ? WHERE name = 'addic7ed'", (settings_addic7ed_username, settings_addic7ed_password))
settings_legendastv_username = request.forms.get('settings_legendastv_username')
settings_legendastv_password = request.forms.get('settings_legendastv_password')
c.execute("UPDATE table_settings_providers SET username = ?, password = ? WHERE name = 'legendastv'", (settings_legendastv_username, settings_legendastv_password))
settings_opensubtitles_username = request.forms.get('settings_opensubtitles_username')
settings_opensubtitles_password = request.forms.get('settings_opensubtitles_password')
c.execute("UPDATE table_settings_providers SET username = ?, password = ? WHERE name = 'opensubtitles'", (settings_opensubtitles_username, settings_opensubtitles_password))
settings_subliminal_languages = request.forms.getall('settings_subliminal_languages')
c.execute("UPDATE table_settings_languages SET enabled = 0")
for item in settings_subliminal_languages:
@ -451,16 +462,29 @@ def get_subtitle():
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c = db.cursor()
c.execute("SELECT name FROM table_settings_providers WHERE enabled = 1")
providers = c.fetchall()
c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1")
enabled_providers = c.fetchall()
c.close()
providers_list = []
for provider in providers:
providers_auth = {}
if len(enabled_providers) > 0:
for provider in enabled_providers:
providers_list.append(provider[0])
try:
if provider[2] is not '' and provider[3] is not '':
provider_auth = providers_auth.append(provider[0])
provider_auth.update({'username':providers[2], 'password':providers[3]})
else:
providers_auth = None
except:
providers_auth = None
else:
providers_list = None
providers_auth = None
try:
result = download_subtitle(episodePath, language, hi, providers_list)
result = download_subtitle(episodePath, language, hi, providers_list, providers_auth)
if result is not None:
history_log(1, sonarrSeriesId, sonarrEpisodeId, result)
store_subtitles(episodePath)

@ -15,9 +15,9 @@ if os.name == 'nt':
else:
region.configure('dogpile.cache.dbm', arguments={'filename': os.path.join(os.path.dirname(__file__), 'data/cache/cachefile.dbm')})
def download_subtitle(path, language, hi, providers):
def download_subtitle(path, language, hi, providers, providers_auth):
video = scan_video(path)
best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, hearing_impaired=hi)
best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, hearing_impaired=hi, provider_configs=providers_auth)
try:
best_subtitle = best_subtitles[video][0]
@ -31,20 +31,33 @@ def download_subtitle(path, language, hi, providers):
return None
def series_download_subtitles(no):
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), tmieout=30)
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c_db = conn_db.cursor()
episodes_details = c_db.execute("SELECT path, missing_subtitles, sonarrEpisodeId FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall()
series_details = c_db.execute("SELECT hearing_impaired FROM table_shows WHERE sonarrSeriesId = ?", (no,)).fetchone()
enabled_providers = c_db.execute("SELECT name FROM table_settings_providers WHERE enabled = 1").fetchall()
enabled_providers = c_db.execute("SELECT * FROM table_settings_providers WHERE enabled = 1").fetchall()
c_db.close()
providers_list = []
providers_auth = {}
if len(enabled_providers) > 0:
for provider in enabled_providers:
providers_list.append(provider[0])
try:
if provider[2] is not '' and provider[3] is not '':
provider_auth = providers_auth.append(provider[0])
provider_auth.update({'username':providers[2], 'password':providers[3]})
else:
providers_auth = None
except:
providers_auth = None
else:
providers_list = None
providers_auth = None
for episode in episodes_details:
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)
message = download_subtitle(path_replace(episode[0]), str(pycountry.languages.lookup(language).alpha_3), series_details[0], providers_list, providers_auth)
if message is not None:
store_subtitles(path_replace(episode[0]))
history_log(1, no, episode[2], message)
@ -54,16 +67,29 @@ def wanted_download_subtitles(path):
conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/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.sonarrSeriesId, table_shows.hearing_impaired FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? AND missing_subtitles != '[]'", (path_replace_reverse(path),)).fetchall()
enabled_providers = c_db.execute("SELECT name FROM table_settings_providers WHERE enabled = 1").fetchall()
enabled_providers = c_db.execute("SELECT * FROM table_settings_providers WHERE enabled = 1").fetchall()
c_db.close()
providers_list = []
providers_auth = {}
if len(enabled_providers) > 0:
for provider in enabled_providers:
providers_list.append(provider[0])
try:
if provider[2] is not '' and provider[3] is not '':
provider_auth = providers_auth.append(provider[0])
provider_auth.update({'username':providers[2], 'password':providers[3]})
else:
providers_auth = None
except:
providers_auth = None
else:
providers_list = None
providers_auth = None
for episode in episodes_details:
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)
message = download_subtitle(path_replace(episode[0]), str(pycountry.languages.lookup(language).alpha_3), episode[4], providers_list, providers_auth)
if message is not None:
store_subtitles(path_replace(episode[0]))
list_missing_subtitles(episode[3])

@ -230,15 +230,6 @@
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Manual update</label>
</div>
<div class="eleven wide column">
<a id="settings_general_check_update" class="ui blue button">Check now and update</a>
</div>
</div>
</div>
</div>
</div>
@ -337,6 +328,90 @@
</div>
</div>
</div>
<div class="ui dividing header">Providers authentication (optionnal)</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
</div>
<div class="five wide column">
<div class="ui fluid input">
<h4 class="ui header">Username</h4>
</div>
</div>
<div class="five wide column">
<div class="ui fluid input">
<h4 class="ui header">Password (stored in clear text)</h4>
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>addic7ed</label>
</div>
%for provider in settings_providers:
% if provider[0] == 'addic7ed':
% addic7ed_username = provider[2]
% addic7ed_password = provider[3]
% end
%end
<div class="five wide column">
<div class="ui fluid input">
<input name="settings_addic7ed_username" type="text" value="{{addic7ed_username}}">
</div>
</div>
<div class="five wide column">
<div class="ui fluid input">
<input name="settings_addic7ed_password" type="password" value="{{addic7ed_password}}">
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>legendastv</label>
</div>
%for provider in settings_providers:
% if provider[0] == 'legendastv':
% legendastv_username = provider[2]
% legendastv_password = provider[3]
% end
%end
<div class="five wide column">
<div class="ui fluid input">
<input name="settings_legendastv_username" type="text" value="{{legendastv_username}}">
</div>
</div>
<div class="five wide column">
<div class="ui fluid input">
<input name="settings_legendastv_password" type="password" value="{{legendastv_password}}">
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>opensubtitles</label>
</div>
%for provider in settings_providers:
% if provider[0] == 'opensubtitles':
% opensubtitles_username = provider[2]
% opensubtitles_password = provider[3]
% end
%end
<div class="five wide column">
<div class="ui fluid input">
<input name="settings_opensubtitles_username" type="text" value="{{opensubtitles_username}}">
</div>
</div>
<div class="five wide column">
<div class="ui fluid input">
<input name="settings_opensubtitles_password" type="password" value="{{opensubtitles_password}}">
</div>
</div>
</div>
</div>
</div>
<div class="ui dividing header">Subtitles languages</div>
<div class="twelve wide column">
<div class="ui grid">

Loading…
Cancel
Save