summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0xhtml <34682885+0xhtml@users.noreply.github.com>2019-07-31 20:44:41 +0200
committer0xhtml <34682885+0xhtml@users.noreply.github.com>2019-07-31 20:44:41 +0200
commitc329ea135ed8c7b56a16e08bf0ee8f6f82609406 (patch)
tree4922c852f3af81c4256635d6215743576693b957
parent7f56c78876c3f1ccd73c13a1275249a42c2c2405 (diff)
Fix spotify engine
-rw-r--r--searx/engines/spotify.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/searx/engines/spotify.py b/searx/engines/spotify.py
index aed756be3..da32b334c 100644
--- a/searx/engines/spotify.py
+++ b/searx/engines/spotify.py
@@ -12,10 +12,14 @@
from json import loads
from searx.url_utils import urlencode
+import requests
+import base64
# engine dependent config
categories = ['music']
paging = True
+api_client_id = None
+api_client_secret = None
# search-url
url = 'https://api.spotify.com/'
@@ -31,6 +35,16 @@ def request(query, params):
params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset)
+ r = requests.post(
+ 'https://accounts.spotify.com/api/token',
+ data={'grant_type': 'client_credentials'},
+ headers={'Authorization': 'Basic ' + str(base64.b64encode(
+ (api_client_id + ":" + api_client_secret).encode('utf-8')
+ ), 'utf-8')}
+ )
+ j = loads(r.text)
+ params['headers'] = {'Authorization': 'Bearer ' + j['access_token']}
+
return params