summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/deezer.py4
-rw-r--r--searx/engines/piratebay.py14
-rw-r--r--searx/engines/spotify.py60
3 files changed, 75 insertions, 3 deletions
diff --git a/searx/engines/deezer.py b/searx/engines/deezer.py
index 8d0b46fac..7fbd3c200 100644
--- a/searx/engines/deezer.py
+++ b/searx/engines/deezer.py
@@ -45,6 +45,10 @@ def response(resp):
if result['type'] == 'track':
title = result['title']
url = result['link']
+
+ if url.startswith('http://'):
+ url = 'https' + url[4:]
+
content = result['artist']['name'] +\
" • " +\
result['album']['title'] +\
diff --git a/searx/engines/piratebay.py b/searx/engines/piratebay.py
index fa5c61128..adee6c1fd 100644
--- a/searx/engines/piratebay.py
+++ b/searx/engines/piratebay.py
@@ -1,4 +1,4 @@
-## Piratebay (Videos, Music, Files)
+# Piratebay (Videos, Music, Files)
#
# @website https://thepiratebay.se
# @provide-api no (nothing found)
@@ -42,6 +42,10 @@ def request(query, params):
search_type=search_type,
pageno=params['pageno'] - 1)
+ # FIX: SSLError: hostname 'kthepiratebay.se'
+ # doesn't match either of 'ssl2000.cloudflare.com', 'cloudflare.com', '*.cloudflare.com'
+ params['verify'] = False
+
return params
@@ -78,7 +82,11 @@ def response(resp):
leech = 0
magnetlink = result.xpath(magnet_xpath)[0]
- torrentfile = result.xpath(torrent_xpath)[0]
+ torrentfile_links = result.xpath(torrent_xpath)
+ if torrentfile_links:
+ torrentfile_link = torrentfile_links[0].attrib.get('href')
+ else:
+ torrentfile_link = None
# append result
results.append({'url': href,
@@ -87,7 +95,7 @@ def response(resp):
'seed': seed,
'leech': leech,
'magnetlink': magnetlink.attrib.get('href'),
- 'torrentfile': torrentfile.attrib.get('href'),
+ 'torrentfile': torrentfile_link,
'template': 'torrent.html'})
# return results sorted by seeder
diff --git a/searx/engines/spotify.py b/searx/engines/spotify.py
new file mode 100644
index 000000000..61f3721ec
--- /dev/null
+++ b/searx/engines/spotify.py
@@ -0,0 +1,60 @@
+## Spotify (Music)
+#
+# @website https://spotify.com
+# @provide-api yes (https://developer.spotify.com/web-api/search-item/)
+#
+# @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 = 'https://api.spotify.com/'
+search_url = url + 'v1/search?{query}&type=track&offset={offset}'
+
+embedded_url = '<iframe data-src="https://embed.spotify.com/?uri=spotify:track:{audioid}"\
+ width="300" height="80" frameborder="0" allowtransparency="true"></iframe>'
+
+
+# do search-request
+def request(query, params):
+ offset = (params['pageno'] - 1) * 20
+
+ 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('tracks', {}).get('items', {}):
+ if result['type'] == 'track':
+ title = result['name']
+ url = result['external_urls']['spotify']
+ content = result['artists'][0]['name'] +\
+ " &bull; " +\
+ result['album']['name'] +\
+ " &bull; " + result['name']
+ embedded = embedded_url.format(audioid=result['id'])
+
+ # append result
+ results.append({'url': url,
+ 'title': title,
+ 'embedded': embedded,
+ 'content': content})
+
+ # return results
+ return results