@@ -1,30 +1,55 @@
1+## Soundcloud (Music)
2+#
3+# @website https://soundcloud.com
4+# @provide-api yes (https://developers.soundcloud.com/)
5+#
6+# @using-api yes
7+# @results JSON
8+# @stable yes
9+# @parse url, title, content
10+
111from json import loads
212from urllib import urlencode
313
14+# engine dependent config
415categories = ['music']
16+paging = True
517
18+# api-key
619guest_client_id = 'b45b1aa10f1ac2941910a7f0d10f8e28'
7−url = 'https://api.soundcloud.com/'
8−search_url = url + 'search?{query}&facet=model&limit=20&offset={offset}&linked_partitioning=1&client_id='+guest_client_id # noqa
920
10−paging = True
21+# search-url
22+url = 'https://api.soundcloud.com/'
23+search_url = url + 'search?{query}&facet=model&limit=20&offset={offset}&linked_partitioning=1&client_id={client_id}'
1124
1225
26+# do search-request
1327def request(query, params):
1428 offset = (params['pageno'] - 1) * 20
29+
1530 params['url'] = search_url.format(query=urlencode({'q': query}),
16− offset=offset)
31+ offset=offset,
32+ client_id=guest_client_id)
33+
1734 return params
1835
1936
37+# get response from search-request
2038def response(resp):
2139 results = []
40+
2241 search_res = loads(resp.text)
42+
43+ # parse results
2344 for result in search_res.get('collection', []):
2445 if result['kind'] in ('track', 'playlist'):
2546 title = result['title']
2647 content = result['description']
48+
49+ # append result
2750 results.append({'url': result['permalink_url'],
2851 'title': title,
2952 'content': content})
53+
54+ # return results
3055 return results