diff options
Diffstat (limited to 'searx/engines')
| -rw-r--r-- | searx/engines/deezer.py | 8 | ||||
| -rw-r--r-- | searx/engines/kickass.py | 4 | ||||
| -rw-r--r-- | searx/engines/photon.py | 3 | ||||
| -rw-r--r-- | searx/engines/piratebay.py | 14 | ||||
| -rw-r--r-- | searx/engines/spotify.py | 60 | ||||
| -rw-r--r-- | searx/engines/yahoo.py | 11 |
6 files changed, 83 insertions, 17 deletions
diff --git a/searx/engines/deezer.py b/searx/engines/deezer.py index 433ceffa1..7fbd3c200 100644 --- a/searx/engines/deezer.py +++ b/searx/engines/deezer.py @@ -16,11 +16,11 @@ categories = ['music'] paging = True # search-url -url = 'http://api.deezer.com/' +url = 'https://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}" ' +\ + 'data-src="https://www.deezer.com/plugins/player?type=tracks&id={audioid}" ' +\ 'width="540" height="80"></iframe>' @@ -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/kickass.py b/searx/engines/kickass.py index ea7f17c23..9c4639c32 100644 --- a/searx/engines/kickass.py +++ b/searx/engines/kickass.py @@ -34,10 +34,6 @@ def request(query, params): params['url'] = search_url.format(search_term=quote(query), pageno=params['pageno']) - # FIX: SSLError: hostname 'kickass.so' - # doesn't match either of '*.kickass.to', 'kickass.to' - params['verify'] = False - return params diff --git a/searx/engines/photon.py b/searx/engines/photon.py index a9c558c4b..869916cd4 100644 --- a/searx/engines/photon.py +++ b/searx/engines/photon.py @@ -41,9 +41,6 @@ def request(query, params): # using searx User-Agent params['headers']['User-Agent'] = searx_useragent() - # FIX: SSLError: SSL3_GET_SERVER_CERTIFICATE:certificate verify failed - params['verify'] = False - return params 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'] +\ + " • " +\ + result['album']['name'] +\ + " • " + 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 diff --git a/searx/engines/yahoo.py b/searx/engines/yahoo.py index 161f7513b..11663a415 100644 --- a/searx/engines/yahoo.py +++ b/searx/engines/yahoo.py @@ -24,11 +24,11 @@ base_url = 'https://search.yahoo.com/' search_url = 'search?{query}&b={offset}&fl=1&vl=lang_{lang}' # specific xpath variables -results_xpath = '//div[@class="res"]' +results_xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' Sr ')]" url_xpath = './/h3/a/@href' title_xpath = './/h3/a' -content_xpath = './/div[@class="abstr"]' -suggestion_xpath = '//div[@id="satat"]//a' +content_xpath = './/div[@class="compText aAbs"]' +suggestion_xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' AlsoTry ')]//a" # remove yahoo-specific tracking-url @@ -91,11 +91,12 @@ def response(resp): 'content': content}) # if no suggestion found, return results - if not dom.xpath(suggestion_xpath): + suggestions = dom.xpath(suggestion_xpath) + if not suggestions: return results # parse suggestion - for suggestion in dom.xpath(suggestion_xpath): + for suggestion in suggestions: # append suggestion results.append({'suggestion': extract_text(suggestion)}) |