2014-12-01 12:26:38 +01:00
|
|
|
## Soundcloud (Music)
|
2014-12-13 13:56:02 +01:00
|
|
|
#
|
2014-12-01 12:26:38 +01:00
|
|
|
# @website https://soundcloud.com
|
|
|
|
# @provide-api yes (https://developers.soundcloud.com/)
|
2014-12-13 13:56:02 +01:00
|
|
|
#
|
2014-12-01 12:26:38 +01:00
|
|
|
# @using-api yes
|
|
|
|
# @results JSON
|
|
|
|
# @stable yes
|
|
|
|
# @parse url, title, content
|
|
|
|
|
2014-05-10 11:56:19 +02:00
|
|
|
from json import loads
|
|
|
|
from urllib import urlencode
|
|
|
|
|
2014-12-01 12:26:38 +01:00
|
|
|
# engine dependent config
|
2014-05-10 11:56:19 +02:00
|
|
|
categories = ['music']
|
2014-12-01 12:26:38 +01:00
|
|
|
paging = True
|
2014-05-10 11:56:19 +02:00
|
|
|
|
2014-12-01 12:26:38 +01:00
|
|
|
# api-key
|
2014-05-10 11:56:19 +02:00
|
|
|
guest_client_id = 'b45b1aa10f1ac2941910a7f0d10f8e28'
|
|
|
|
|
2014-12-01 12:26:38 +01:00
|
|
|
# search-url
|
|
|
|
url = 'https://api.soundcloud.com/'
|
2015-01-13 16:40:30 +01:00
|
|
|
search_url = url + 'search?{query}'\
|
|
|
|
'&facet=model'\
|
|
|
|
'&limit=20'\
|
|
|
|
'&offset={offset}'\
|
|
|
|
'&linked_partitioning=1'\
|
|
|
|
'&client_id={client_id}' # noqa
|
2014-05-10 11:56:19 +02:00
|
|
|
|
|
|
|
|
2014-12-01 12:26:38 +01:00
|
|
|
# do search-request
|
2014-05-10 11:56:19 +02:00
|
|
|
def request(query, params):
|
|
|
|
offset = (params['pageno'] - 1) * 20
|
2014-12-01 12:26:38 +01:00
|
|
|
|
2014-05-10 11:56:19 +02:00
|
|
|
params['url'] = search_url.format(query=urlencode({'q': query}),
|
2014-12-01 12:26:38 +01:00
|
|
|
offset=offset,
|
|
|
|
client_id=guest_client_id)
|
|
|
|
|
2014-05-10 11:56:19 +02:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
2014-12-01 12:26:38 +01:00
|
|
|
# get response from search-request
|
2014-05-10 11:56:19 +02:00
|
|
|
def response(resp):
|
|
|
|
results = []
|
2014-12-01 12:26:38 +01:00
|
|
|
|
2014-05-10 11:56:19 +02:00
|
|
|
search_res = loads(resp.text)
|
2014-12-01 12:26:38 +01:00
|
|
|
|
|
|
|
# parse results
|
2014-05-10 11:56:19 +02:00
|
|
|
for result in search_res.get('collection', []):
|
|
|
|
if result['kind'] in ('track', 'playlist'):
|
|
|
|
title = result['title']
|
|
|
|
content = result['description']
|
2014-12-01 12:26:38 +01:00
|
|
|
|
|
|
|
# append result
|
2014-05-10 11:56:19 +02:00
|
|
|
results.append({'url': result['permalink_url'],
|
|
|
|
'title': title,
|
|
|
|
'content': content})
|
2014-12-01 12:26:38 +01:00
|
|
|
|
|
|
|
# return results
|
2014-05-10 11:56:19 +02:00
|
|
|
return results
|