on master help sign in
Merge pull request #1661 from 0xhtml/fix-engine-spotify
754a10cMarkus Heiser
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 ' + base64.b64encode(
42+ "{}:{}".format(api_client_id, api_client_secret).encode('utf-8')
43+ ).decode('utf-8')}
44+ )
45+ j = loads(r.text)
46+ params['headers'] = {'Authorization': 'Bearer {}'.format(j.get('access_token'))}
47+
34 return params
48 return params
35
49
36
50
searx/settings.yml+6−3
@@ -598,9 +598,12 @@ engines:
598 shortcut : se
598 shortcut : se
599 categories : science
599 categories : science
600
600
601+# Spotify needs API credentials
601− - name : spotify
602+# - name : spotify
602− engine : spotify
603+# engine : spotify
603− shortcut : stf
604+# shortcut : stf
605+# api_client_id : *******
606+# api_client_secret : *******
604
607
605 - name : startpage
608 - name : startpage
606 engine : startpage
609 engine : startpage