forked from zaclys/searxng
update soundcloud and add comments
This commit is contained in:
parent
dae88d862b
commit
64a68a7296
|
@ -1,30 +1,55 @@
|
||||||
|
## Soundcloud (Music)
|
||||||
|
#
|
||||||
|
# @website https://soundcloud.com
|
||||||
|
# @provide-api yes (https://developers.soundcloud.com/)
|
||||||
|
#
|
||||||
|
# @using-api yes
|
||||||
|
# @results JSON
|
||||||
|
# @stable yes
|
||||||
|
# @parse url, title, content
|
||||||
|
|
||||||
from json import loads
|
from json import loads
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
|
|
||||||
|
# engine dependent config
|
||||||
categories = ['music']
|
categories = ['music']
|
||||||
|
|
||||||
guest_client_id = 'b45b1aa10f1ac2941910a7f0d10f8e28'
|
|
||||||
url = 'https://api.soundcloud.com/'
|
|
||||||
search_url = url + 'search?{query}&facet=model&limit=20&offset={offset}&linked_partitioning=1&client_id='+guest_client_id # noqa
|
|
||||||
|
|
||||||
paging = True
|
paging = True
|
||||||
|
|
||||||
|
# api-key
|
||||||
|
guest_client_id = 'b45b1aa10f1ac2941910a7f0d10f8e28'
|
||||||
|
|
||||||
|
# search-url
|
||||||
|
url = 'https://api.soundcloud.com/'
|
||||||
|
search_url = url + 'search?{query}&facet=model&limit=20&offset={offset}&linked_partitioning=1&client_id={client_id}'
|
||||||
|
|
||||||
|
|
||||||
|
# do search-request
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
offset = (params['pageno'] - 1) * 20
|
offset = (params['pageno'] - 1) * 20
|
||||||
|
|
||||||
params['url'] = search_url.format(query=urlencode({'q': query}),
|
params['url'] = search_url.format(query=urlencode({'q': query}),
|
||||||
offset=offset)
|
offset=offset,
|
||||||
|
client_id=guest_client_id)
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
# get response from search-request
|
||||||
def response(resp):
|
def response(resp):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
search_res = loads(resp.text)
|
search_res = loads(resp.text)
|
||||||
|
|
||||||
|
# parse results
|
||||||
for result in search_res.get('collection', []):
|
for result in search_res.get('collection', []):
|
||||||
if result['kind'] in ('track', 'playlist'):
|
if result['kind'] in ('track', 'playlist'):
|
||||||
title = result['title']
|
title = result['title']
|
||||||
content = result['description']
|
content = result['description']
|
||||||
|
|
||||||
|
# append result
|
||||||
results.append({'url': result['permalink_url'],
|
results.append({'url': result['permalink_url'],
|
||||||
'title': title,
|
'title': title,
|
||||||
'content': content})
|
'content': content})
|
||||||
|
|
||||||
|
# return results
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -86,7 +86,6 @@ engines:
|
||||||
|
|
||||||
- name : soundcloud
|
- name : soundcloud
|
||||||
engine : soundcloud
|
engine : soundcloud
|
||||||
categories : music
|
|
||||||
shortcut : sc
|
shortcut : sc
|
||||||
|
|
||||||
- name : stackoverflow
|
- name : stackoverflow
|
||||||
|
|
Loading…
Reference in New Issue