diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index d88cbfdd..84f3770f 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -708,6 +708,10 @@
+
+ + +
diff --git a/headphones/config.py b/headphones/config.py index 9679981f..7f29d50e 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -306,6 +306,7 @@ _CONFIG_DEFINITIONS = { 'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1), 'WAIT_UNTIL_RELEASE_DATE': (int, 'General', 0), 'REDACTED': (int, 'Redacted', 0), + 'REDACTED_APIKEY': (str, 'Redacted', ''), 'REDACTED_USERNAME': (str, 'Redacted', ''), 'REDACTED_PASSWORD': (str, 'Redacted', ''), 'REDACTED_RATIO': (str, 'Redacted', ''), diff --git a/headphones/searcher.py b/headphones/searcher.py index 65d486e7..a2cd9eeb 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -1590,9 +1590,9 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, if not orpheusobj or not orpheusobj.logged_in(): try: logger.info("Attempting to log in to Orpheus.network...") - orpheusobj = gazelleapi.GazelleAPI(headphones.CONFIG.ORPHEUS_USERNAME, - headphones.CONFIG.ORPHEUS_PASSWORD, - headphones.CONFIG.ORPHEUS_URL) + orpheusobj = gazelleapi.GazelleAPI(username=headphones.CONFIG.ORPHEUS_USERNAME, + password=headphones.CONFIG.ORPHEUS_PASSWORD, + url=headphones.CONFIG.ORPHEUS_URL) orpheusobj._login() except Exception as e: orpheusobj = None @@ -1726,9 +1726,8 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, if not redobj or not redobj.logged_in(): try: logger.info("Attempting to log in to Redacted...") - redobj = gazelleapi.GazelleAPI(headphones.CONFIG.REDACTED_USERNAME, - headphones.CONFIG.REDACTED_PASSWORD, - providerurl) + redobj = gazelleapi.GazelleAPI(apikey=headphones.CONFIG.REDACTED_APIKEY, + url=providerurl) redobj._login() except Exception as e: redobj = None diff --git a/headphones/webserve.py b/headphones/webserve.py index 8722cc38..e85503f5 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1242,6 +1242,7 @@ class WebInterface(object): "orpheus_ratio": headphones.CONFIG.ORPHEUS_RATIO, "orpheus_url": headphones.CONFIG.ORPHEUS_URL, "use_redacted": checked(headphones.CONFIG.REDACTED), + "redacted_apikey": headphones.CONFIG.REDACTED_APIKEY, "redacted_username": headphones.CONFIG.REDACTED_USERNAME, "redacted_password": headphones.CONFIG.REDACTED_PASSWORD, "redacted_ratio": headphones.CONFIG.REDACTED_RATIO, diff --git a/lib/pygazelle/api.py b/lib/pygazelle/api.py index 866e7baf..dd864ba6 100644 --- a/lib/pygazelle/api.py +++ b/lib/pygazelle/api.py @@ -41,11 +41,12 @@ class GazelleAPI(object): 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'} - def __init__(self, username=None, password=None, url=None): + def __init__(self, apikey=None, username=None, password=None, url=None): self.session = requests.session() self.session.headers = self.default_headers self.username = username self.password = password + self.apikey = apikey self.authkey = None self.passkey = None self.userid = None @@ -94,14 +95,17 @@ class GazelleAPI(object): self.wait_for_rate_limit() - loginpage = self.site + 'login.php' - data = {'username': self.username, - 'password': self.password, - 'keeplogged': '1'} - r = self.session.post(loginpage, data=data, timeout=self.default_timeout, headers=self.default_headers) - self.past_request_timestamps.append(time.time()) - if r.status_code != 200: - raise LoginException("Login returned status code %s" % r.status_code) + if self.apikey is not None: + self.session.headers["Authorization"] = self.apikey + else: + loginpage = self.site + 'login.php' + data = {'username': self.username, + 'password': self.password, + 'keeplogged': '1'} + r = self.session.post(loginpage, data=data, timeout=self.default_timeout, headers=self.default_headers) + self.past_request_timestamps.append(time.time()) + if r.status_code != 200: + raise LoginException("Login returned status code %s" % r.status_code) try: accountinfo = self.request('index', autologin=False)