on master help sign in
Fix spotify engine
commitc329ea135ed8c7b56a16e08bf0ee8f6f82609406 author0xhtml <34682885+0xhtml@users.noreply.github.com> dateWed 31 Jul 2019, 20:44 (7 years ago) parent7f56c78
1 file changed+14
searx/engines/spotify.py+14
searx/engines/spotify.py+14
@@ -12,10 +12,14 @@
1212
1313from json import loads
1414from searx.url_utils import urlencode
15+import requests
16+import base64
1517
1618# engine dependent config
1719categories = ['music']
1820paging = True
21+api_client_id = None
22+api_client_secret = None
1923
2024# search-url
2125url = 'https://api.spotify.com/'
@@ -31,6 +35,16 @@ def request(query, params):
3135
3236 params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset)
3337
38+ r = requests.post(
39+ 'https://accounts.spotify.com/api/token',
40+ data={'grant_type': 'client_credentials'},
41+ headers={'Authorization': 'Basic ' + str(base64.b64encode(
42+ (api_client_id + ":" + api_client_secret).encode('utf-8')
43+ ), 'utf-8')}
44+ )
45+ j = loads(r.text)
46+ params['headers'] = {'Authorization': 'Bearer ' + j['access_token']}
47+
3448 return params
3549
3650