summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarIT.de>2019-12-30 07:44:31 +0100
committerGitHub <noreply@github.com>2019-12-30 07:44:31 +0100
commit754a10c1c1b66195f3ae7542806593d87158a61b (patch)
tree0c2e238ed8fd03a95a090692d0d761fe2ea13d79 /searx/engines
parentf6d66c0f6f1d8f1f583d9000ee0123450cce8130 (diff)
parent36e72a46192235615f63a02984ab88c70145b0ec (diff)
Merge pull request #1661 from 0xhtml/fix-engine-spotify
Fix engine spotify As you can read here https://developer.spotify.com/documentation/web-api/#authentication all requests to the spotify api require authentication. You can not test the api without credentials.
Diffstat (limited to 'searx/engines')
-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..00c395706 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 ' + base64.b64encode(
+ "{}:{}".format(api_client_id, api_client_secret).encode('utf-8')
+ ).decode('utf-8')}
+ )
+ j = loads(r.text)
+ params['headers'] = {'Authorization': 'Bearer {}'.format(j.get('access_token'))}
+
return params