summaryrefslogtreecommitdiff
path: root/searx/engines/spotify.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarIT.de>2020-01-06 08:05:29 +0000
committerGitHub <noreply@github.com>2020-01-06 08:05:29 +0000
commit1d86d0054ff29344f93943896847c12f51e1a9e0 (patch)
tree83a1cd1d16a73f25160b7d260b38ab649236637d /searx/engines/spotify.py
parent70f7142824cc44afddb5704fd59e3a4194f3dc0e (diff)
parent17b6faa4c3c1cf14a327f4a3538fc70dce08b756 (diff)
Merge branch 'master' into bug/oscar-theme
Diffstat (limited to 'searx/engines/spotify.py')
-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