forked from zaclys/searxng
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.
This commit is contained in:
commit
754a10c1c1
|
@ -12,10 +12,14 @@
|
||||||
|
|
||||||
from json import loads
|
from json import loads
|
||||||
from searx.url_utils import urlencode
|
from searx.url_utils import urlencode
|
||||||
|
import requests
|
||||||
|
import base64
|
||||||
|
|
||||||
# engine dependent config
|
# engine dependent config
|
||||||
categories = ['music']
|
categories = ['music']
|
||||||
paging = True
|
paging = True
|
||||||
|
api_client_id = None
|
||||||
|
api_client_secret = None
|
||||||
|
|
||||||
# search-url
|
# search-url
|
||||||
url = 'https://api.spotify.com/'
|
url = 'https://api.spotify.com/'
|
||||||
|
@ -31,6 +35,16 @@ def request(query, params):
|
||||||
|
|
||||||
params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset)
|
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
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -598,9 +598,12 @@ engines:
|
||||||
shortcut : se
|
shortcut : se
|
||||||
categories : science
|
categories : science
|
||||||
|
|
||||||
- name : spotify
|
# Spotify needs API credentials
|
||||||
engine : spotify
|
# - name : spotify
|
||||||
shortcut : stf
|
# engine : spotify
|
||||||
|
# shortcut : stf
|
||||||
|
# api_client_id : *******
|
||||||
|
# api_client_secret : *******
|
||||||
|
|
||||||
- name : startpage
|
- name : startpage
|
||||||
engine : startpage
|
engine : startpage
|
||||||
|
|
Loading…
Reference in New Issue