summaryrefslogtreecommitdiff
path: root/searx/engines/deezer.py
diff options
context:
space:
mode:
authorCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-05 02:04:23 +0100
committerCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-05 02:04:23 +0100
commit4a195e0b28fdd940e046c442032c816095416fec (patch)
tree88a4d4b151bbd9771cb1a58cf37f7691737af9e4 /searx/engines/deezer.py
parent7b531c6fcefe1c0c5cc19967454cdddb6e1c8fbd (diff)
downloadsearxng-4a195e0b28fdd940e046c442032c816095416fec.tar.gz
searxng-4a195e0b28fdd940e046c442032c816095416fec.zip
Integrated media in results + Deezer Engine
New "embedded" item for the results, allow to give an iframe to display the media directly in the results. Note that the attributes src of the iframes are not set, but instead data-src is set, allowing to only load the iframe when clicked. Deezer engine based on public API (no key).
Diffstat (limited to 'searx/engines/deezer.py')
-rw-r--r--searx/engines/deezer.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/searx/engines/deezer.py b/searx/engines/deezer.py
new file mode 100644
index 000000000..6c26b6aeb
--- /dev/null
+++ b/searx/engines/deezer.py
@@ -0,0 +1,62 @@
+## Deezer (Music)
+#
+# @website https://deezer.com
+# @provide-api yes (http://developers.deezer.com/api/)
+#
+# @using-api yes
+# @results JSON
+# @stable yes
+# @parse url, title, content, embedded
+
+from json import loads
+from urllib import urlencode
+
+# engine dependent config
+categories = ['music']
+paging = True
+
+# search-url
+url = 'http://api.deezer.com/'
+search_url = url + 'search?{query}&index={offset}'
+
+embedded_url = '<iframe scrolling="no" frameborder="0" allowTransparency="true" ' +\
+ 'data-src="http://www.deezer.com/plugins/player?type=tracks&id={audioid}" ' +\
+ 'width="540" height="80"></iframe>'
+
+
+# do search-request
+def request(query, params):
+ offset = (params['pageno'] - 1) * 25
+
+ 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', []):
+ if result['type'] == 'track':
+ print result
+ title = result['title']
+ url = result['link']
+ content = result['artist']['name'] +\
+ " &bull; " +\
+ result['album']['title'] +\
+ " &bull; " + result['title']
+ embedded = embedded_url.format(audioid=result['id'])
+
+ # append result
+ results.append({'url': url,
+ 'title': title,
+ 'embedded': embedded,
+ 'content': content})
+
+ # return results
+ return results