on master help sign in
Fix spotify engine
c329ea10xhtml
searx/engines/spotify.py+14
@@ -12,10 +12,14 @@
12
12
13from json import loads
13from json import loads
14from searx.url_utils import urlencode
14from searx.url_utils import urlencode
15+import requests
16+import base64
15
17
16# engine dependent config
18# engine dependent config
17categories = ['music']
19categories = ['music']
18paging = True
20paging = True
21+api_client_id = None
22+api_client_secret = None
19
23
20# search-url
24# search-url
21url = 'https://api.spotify.com/'
25url = 'https://api.spotify.com/'
@@ -31,6 +35,16 @@ def request(query, params):
31
35
32 params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset)
36 params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset)
33
37
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+
34 return params
48 return params
35
49
36
50