on master help sign in
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.

commit754a10c1c1b66195f3ae7542806593d87158a61b authorMarkus Heiser <markus.heiser@darmarIT.de> dateMon 30 Dec 2019, 07:44 (7 years ago) parentf6d66c036e72a4
2 files changed+20−3
searx/engines/spotify.py+14 searx/settings.yml+6−3
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 ' + 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+
3448 return params
3549
3650
searx/settings.yml+6−3
@@ -598,9 +598,12 @@ engines:
598598 shortcut : se
599599 categories : science
600600
601− - name : spotify
602− engine : spotify
603− shortcut : stf
601+# Spotify needs API credentials
602+# - name : spotify
603+# engine : spotify
604+# shortcut : stf
605+# api_client_id : *******
606+# api_client_secret : *******
604607
605608 - name : startpage
606609 engine : startpage