mirror of
https://github.com/morpheus65535/bazarr
synced 2025-03-13 15:38:47 +00:00
Fix for providers auth not used
This commit is contained in:
parent
d4cd75b0fb
commit
54329b0d2b
3 changed files with 79 additions and 203 deletions
129
bazarr.py
129
bazarr.py
|
@ -85,7 +85,8 @@ import hashlib
|
|||
import time
|
||||
|
||||
from get_languages import load_language_in_db, language_from_alpha3
|
||||
from get_providers import *
|
||||
from get_providers import load_providers, get_providers, get_providers_auth
|
||||
load_providers()
|
||||
|
||||
from get_series import *
|
||||
from get_episodes import *
|
||||
|
@ -1473,28 +1474,8 @@ def get_subtitle():
|
|||
sonarrEpisodeId = request.forms.get('sonarrEpisodeId')
|
||||
# tvdbid = request.forms.get('tvdbid')
|
||||
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1")
|
||||
enabled_providers = c.fetchall()
|
||||
c.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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
try:
|
||||
result = download_subtitle(episodePath, language, hi, providers_list, providers_auth, sceneName, 'series')
|
||||
|
@ -1518,28 +1499,8 @@ def manual_search_json():
|
|||
language = request.forms.get('language')
|
||||
hi = request.forms.get('hi')
|
||||
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1")
|
||||
enabled_providers = c.fetchall()
|
||||
c.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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
data = manual_search(episodePath, language, hi, providers_list, providers_auth, sceneName, 'series')
|
||||
return dict(data=data)
|
||||
|
@ -1559,19 +1520,8 @@ def manual_get_subtitle():
|
|||
sonarrSeriesId = request.forms.get('sonarrSeriesId')
|
||||
sonarrEpisodeId = request.forms.get('sonarrEpisodeId')
|
||||
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
provider = c.execute("SELECT * FROM table_settings_providers WHERE name = ?",(selected_provider,)).fetchone()
|
||||
c.close()
|
||||
providers_auth = {}
|
||||
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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
try:
|
||||
result = manual_download_subtitle(episodePath, language, hi, subtitle, selected_provider, providers_auth, sceneName, 'series')
|
||||
|
@ -1597,28 +1547,8 @@ def get_subtitle_movie():
|
|||
radarrId = request.forms.get('radarrId')
|
||||
# tmdbid = request.forms.get('tmdbid')
|
||||
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1")
|
||||
enabled_providers = c.fetchall()
|
||||
c.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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
try:
|
||||
result = download_subtitle(moviePath, language, hi, providers_list, providers_auth, sceneName, 'movie')
|
||||
|
@ -1642,28 +1572,8 @@ def manual_search_movie_json():
|
|||
language = request.forms.get('language')
|
||||
hi = request.forms.get('hi')
|
||||
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1")
|
||||
enabled_providers = c.fetchall()
|
||||
c.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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
data = manual_search(moviePath, language, hi, providers_list, providers_auth, sceneName, 'movie')
|
||||
return dict(data=data)
|
||||
|
@ -1682,19 +1592,8 @@ def manual_get_subtitle_movie():
|
|||
subtitle = request.forms.get('subtitle')
|
||||
radarrId = request.forms.get('radarrId')
|
||||
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
provider = c.execute("SELECT * FROM table_settings_providers WHERE name = ?",(selected_provider,)).fetchone()
|
||||
c.close()
|
||||
providers_auth = {}
|
||||
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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
try:
|
||||
result = manual_download_subtitle(moviePath, language, hi, subtitle, selected_provider, providers_auth, sceneName, 'movie')
|
||||
|
|
|
@ -3,29 +3,65 @@ from get_argv import config_dir
|
|||
import sqlite3
|
||||
import os
|
||||
from subliminal import provider_manager
|
||||
import collections
|
||||
|
||||
# Get providers list from subliminal
|
||||
providers_list = sorted(provider_manager.names())
|
||||
def load_providers():
|
||||
# Get providers list from subliminal
|
||||
providers_list = sorted(provider_manager.names())
|
||||
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
# Remove unsupported providers
|
||||
providers_in_db = c.execute('SELECT name FROM table_settings_providers').fetchall()
|
||||
for provider_in_db in providers_in_db:
|
||||
if provider_in_db[0] not in providers_list:
|
||||
c.execute('DELETE FROM table_settings_providers WHERE name = ?', (provider_in_db[0], ))
|
||||
# Remove unsupported providers
|
||||
providers_in_db = c.execute('SELECT name FROM table_settings_providers').fetchall()
|
||||
for provider_in_db in providers_in_db:
|
||||
if provider_in_db[0] not in providers_list:
|
||||
c.execute('DELETE FROM table_settings_providers WHERE name = ?', (provider_in_db[0], ))
|
||||
|
||||
# Commit changes to database table
|
||||
db.commit()
|
||||
# Commit changes to database table
|
||||
db.commit()
|
||||
|
||||
# Insert providers in database table
|
||||
for provider_name in providers_list:
|
||||
c.execute('''INSERT OR IGNORE INTO table_settings_providers(name) VALUES(?)''', (provider_name, ))
|
||||
# Insert providers in database table
|
||||
for provider_name in providers_list:
|
||||
c.execute('''INSERT OR IGNORE INTO table_settings_providers(name) VALUES(?)''', (provider_name, ))
|
||||
|
||||
# Commit changes to database table
|
||||
db.commit()
|
||||
# Commit changes to database table
|
||||
db.commit()
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
|
||||
def get_providers():
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
enabled_providers = c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1").fetchall()
|
||||
c.close()
|
||||
|
||||
providers_list = []
|
||||
if len(enabled_providers) > 0:
|
||||
for provider in enabled_providers:
|
||||
providers_list.append(provider[0])
|
||||
else:
|
||||
providers_list = None
|
||||
|
||||
return providers_list
|
||||
|
||||
|
||||
def get_providers_auth():
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
enabled_providers = c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1 AND username is not NULL AND password is not NULL").fetchall()
|
||||
c.close()
|
||||
|
||||
providers_auth = collections.defaultdict(dict)
|
||||
if len(enabled_providers) > 0:
|
||||
for provider in enabled_providers:
|
||||
providers_auth[provider[0]] = {}
|
||||
providers_auth[provider[0]]['username'] = provider[2]
|
||||
providers_auth[provider[0]]['password'] = provider[3]
|
||||
else:
|
||||
providers_auth = None
|
||||
|
||||
return providers_auth
|
|
@ -17,6 +17,7 @@ from utils import history_log, history_log_movie
|
|||
from notifier import send_notifications, send_notifications_movie
|
||||
import cPickle as pickle
|
||||
import codecs
|
||||
from get_providers import get_providers, get_providers_auth
|
||||
|
||||
# configure the cache
|
||||
region.configure('dogpile.cache.memory')
|
||||
|
@ -201,7 +202,7 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
|
|||
else:
|
||||
try:
|
||||
best_subtitle = subtitle
|
||||
download_subtitles([best_subtitle])
|
||||
download_subtitles([best_subtitle], providers=provider, provider_configs=providers_auth)
|
||||
except Exception as e:
|
||||
logging.exception('Error downloading subtitles for ' + path)
|
||||
return None
|
||||
|
@ -265,25 +266,10 @@ def series_download_subtitles(no):
|
|||
c_db = conn_db.cursor()
|
||||
episodes_details = c_db.execute('SELECT path, missing_subtitles, sonarrEpisodeId, scene_name FROM table_episodes WHERE sonarrSeriesId = ? AND missing_subtitles != "[]"' + monitored_only_query_string, (no,)).fetchall()
|
||||
series_details = c_db.execute("SELECT hearing_impaired FROM table_shows WHERE sonarrSeriesId = ?", (no,)).fetchone()
|
||||
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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
for episode in episodes_details:
|
||||
for language in ast.literal_eval(episode[1]):
|
||||
|
@ -300,25 +286,10 @@ def movies_download_subtitles(no):
|
|||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
movie = c_db.execute("SELECT path, missing_subtitles, radarrId, sceneName, hearing_impaired FROM table_movies WHERE radarrId = ?", (no,)).fetchone()
|
||||
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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
for language in ast.literal_eval(movie[1]):
|
||||
if language is not None:
|
||||
|
@ -334,25 +305,10 @@ def wanted_download_subtitles(path):
|
|||
conn_db = sqlite3.connect(os.path.join(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.sonarrSeriesId, table_shows.hearing_impaired, table_episodes.scene_name, table_episodes.failedAttempts 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 * 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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
for episode in episodes_details:
|
||||
attempt = episode[6]
|
||||
|
@ -390,25 +346,10 @@ def wanted_download_subtitles_movie(path):
|
|||
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c_db = conn_db.cursor()
|
||||
movies_details = c_db.execute("SELECT path, missing_subtitles, radarrId, radarrId, hearing_impaired, sceneName, failedAttempts FROM table_movies WHERE path = ? AND missing_subtitles != '[]'", (path_replace_reverse_movie(path),)).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
|
||||
providers_list = get_providers()
|
||||
providers_auth = get_providers_auth()
|
||||
|
||||
for movie in movies_details:
|
||||
attempt = movie[6]
|
||||
|
|
Loading…
Add table
Reference in a new issue