summaryrefslogtreecommitdiff
path: root/searx/engines/mixcloud.py
diff options
context:
space:
mode:
authorCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-21 18:02:29 +0100
committerCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-21 18:02:29 +0100
commit85dcfa2c7d66dbfde1c0aa349f01020b02195676 (patch)
tree2c649a35222bfc82c03312528016280bdca2c20b /searx/engines/mixcloud.py
parent549dcac588e810090e98cb753fde2828bef66325 (diff)
downloadsearxng-85dcfa2c7d66dbfde1c0aa349f01020b02195676.tar.gz
searxng-85dcfa2c7d66dbfde1c0aa349f01020b02195676.zip
BTDigg and Mixcloud engines
Diffstat (limited to 'searx/engines/mixcloud.py')
-rw-r--r--searx/engines/mixcloud.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/searx/engines/mixcloud.py b/searx/engines/mixcloud.py
new file mode 100644
index 000000000..676e6f845
--- /dev/null
+++ b/searx/engines/mixcloud.py
@@ -0,0 +1,59 @@
+## Mixcloud (Music)
+#
+# @website https://http://www.mixcloud.com/
+# @provide-api yes (http://www.mixcloud.com/developers/
+#
+# @using-api yes
+# @results JSON
+# @stable yes
+# @parse url, title, content, embedded, publishedDate
+
+from json import loads
+from urllib import urlencode
+from dateutil import parser
+
+# engine dependent config
+categories = ['music']
+paging = True
+
+# search-url
+url = 'http://api.mixcloud.com/'
+search_url = url + 'search/?{query}&type=cloudcast&limit=10&offset={offset}'
+
+embedded_url = '<iframe scrolling="no" frameborder="0" allowTransparency="true" ' +\
+ 'data-src="https://www.mixcloud.com/widget/iframe/?feed={url}" width="300" height="300"></iframe>'
+
+
+# do search-request
+def request(query, params):
+ offset = (params['pageno'] - 1) * 10
+
+ params['url'] = search_url.format(query=urlencode({'q': query}),
+ offset=offset)
+
+ return params
+
+
+# get response from search-request
+def response(resp):
+ results = []
+
+ search_res = loads(resp.text)
+
+ # parse results
+ for result in search_res.get('data', []):
+ title = result['name']
+ url = result['url']
+ content = result['user']['name']
+ embedded = embedded_url.format(url=url)
+ publishedDate = parser.parse(result['created_time'])
+
+ # append result
+ results.append({'url': url,
+ 'title': title,
+ 'embedded': embedded,
+ 'publishedDate': publishedDate,
+ 'content': content})
+
+ # return results
+ return results