|
@@ -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
|
+
|
1
|
11
|
from json import loads
|
2
|
12
|
from urllib import urlencode
|
3
|
13
|
|
|
14
|
+# engine dependent config
|
4
|
15
|
categories = ['music']
|
|
16
|
+paging = True
|
5
|
17
|
|
|
18
|
+# api-key
|
6
|
19
|
guest_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
|
9
|
20
|
|
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}'
|
11
|
24
|
|
12
|
25
|
|
|
26
|
+# do search-request
|
13
|
27
|
def request(query, params):
|
14
|
28
|
offset = (params['pageno'] - 1) * 20
|
|
29
|
+
|
15
|
30
|
params['url'] = search_url.format(query=urlencode({'q': query}),
|
16
|
|
- offset=offset)
|
|
31
|
+ offset=offset,
|
|
32
|
+ client_id=guest_client_id)
|
|
33
|
+
|
17
|
34
|
return params
|
18
|
35
|
|
19
|
36
|
|
|
37
|
+# get response from search-request
|
20
|
38
|
def response(resp):
|
21
|
39
|
results = []
|
|
40
|
+
|
22
|
41
|
search_res = loads(resp.text)
|
|
42
|
+
|
|
43
|
+ # parse results
|
23
|
44
|
for result in search_res.get('collection', []):
|
24
|
45
|
if result['kind'] in ('track', 'playlist'):
|
25
|
46
|
title = result['title']
|
26
|
47
|
content = result['description']
|
|
48
|
+
|
|
49
|
+ # append result
|
27
|
50
|
results.append({'url': result['permalink_url'],
|
28
|
51
|
'title': title,
|
29
|
52
|
'content': content})
|
|
53
|
+
|
|
54
|
+ # return results
|
30
|
55
|
return results
|