diff options
| author | Adam Tauber <adam.tauber@balabit.com> | 2015-01-07 11:49:11 +0100 |
|---|---|---|
| committer | Adam Tauber <adam.tauber@balabit.com> | 2015-01-07 11:49:11 +0100 |
| commit | e4681da20f4dc2024609454771aa005bc05ba3f3 (patch) | |
| tree | f1ce53d468a72bc751138a949355b8c0696e803d /searx/engines | |
| parent | 3b672039aab207d0002eac9d7406f0c5b3239df0 (diff) | |
| parent | 05be069f424f478174b65e42fc2865148850060c (diff) | |
Merge branch 'Cqoicebordel-integrated-videos'
Diffstat (limited to 'searx/engines')
| -rw-r--r-- | searx/engines/dailymotion.py | 15 | ||||
| -rw-r--r-- | searx/engines/deezer.py | 61 | ||||
| -rw-r--r-- | searx/engines/soundcloud.py | 14 | ||||
| -rw-r--r-- | searx/engines/vimeo.py | 24 | ||||
| -rw-r--r-- | searx/engines/youtube.py | 13 |
5 files changed, 112 insertions, 15 deletions
diff --git a/searx/engines/dailymotion.py b/searx/engines/dailymotion.py index a5bffa866..03b1dbb8b 100644 --- a/searx/engines/dailymotion.py +++ b/searx/engines/dailymotion.py @@ -6,12 +6,14 @@ # @using-api yes # @results JSON # @stable yes -# @parse url, title, thumbnail +# @parse url, title, thumbnail, publishedDate, embedded # # @todo set content-parameter with correct data from urllib import urlencode from json import loads +from cgi import escape +from datetime import datetime # engine dependent config categories = ['videos'] @@ -20,7 +22,9 @@ language_support = True # search-url # see http://www.dailymotion.com/doc/api/obj-video.html -search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=5&page={pageno}&{query}' # noqa +search_url = 'https://api.dailymotion.com/videos?fields=created_time,title,description,duration,url,thumbnail_360_url,id&sort=relevance&limit=5&page={pageno}&{query}' # noqa +embedded_url = '<iframe frameborder="0" width="540" height="304" ' +\ + 'data-src="//www.dailymotion.com/embed/video/{videoid}" allowfullscreen></iframe>' # do search-request @@ -51,14 +55,17 @@ def response(resp): for res in search_res['list']: title = res['title'] url = res['url'] - #content = res['description'] - content = '' + content = escape(res['description']) thumbnail = res['thumbnail_360_url'] + publishedDate = datetime.fromtimestamp(res['created_time'], None) + embedded = embedded_url.format(videoid=res['id']) results.append({'template': 'videos.html', 'url': url, 'title': title, 'content': content, + 'publishedDate': publishedDate, + 'embedded': embedded, 'thumbnail': thumbnail}) # return results diff --git a/searx/engines/deezer.py b/searx/engines/deezer.py new file mode 100644 index 000000000..433ceffa1 --- /dev/null +++ b/searx/engines/deezer.py @@ -0,0 +1,61 @@ +## 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': + title = result['title'] + url = result['link'] + content = result['artist']['name'] +\ + " • " +\ + result['album']['title'] +\ + " • " + 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 diff --git a/searx/engines/soundcloud.py b/searx/engines/soundcloud.py index 164a569a3..44374af6f 100644 --- a/searx/engines/soundcloud.py +++ b/searx/engines/soundcloud.py @@ -6,10 +6,11 @@ # @using-api yes # @results JSON # @stable yes -# @parse url, title, content +# @parse url, title, content, publishedDate, embedded from json import loads -from urllib import urlencode +from urllib import urlencode, quote_plus +from dateutil import parser # engine dependent config categories = ['music'] @@ -27,6 +28,10 @@ search_url = url + 'search?{query}'\ '&linked_partitioning=1'\ '&client_id={client_id}' # noqa +embedded_url = '<iframe width="100%" height="166" ' +\ + 'scrolling="no" frameborder="no" ' +\ + 'data-src="https://w.soundcloud.com/player/?url={uri}"></iframe>' + # do search-request def request(query, params): @@ -50,10 +55,15 @@ def response(resp): if result['kind'] in ('track', 'playlist'): title = result['title'] content = result['description'] + publishedDate = parser.parse(result['last_modified']) + uri = quote_plus(result['uri']) + embedded = embedded_url.format(uri=uri) # append result results.append({'url': result['permalink_url'], 'title': title, + 'publishedDate': publishedDate, + 'embedded': embedded, 'content': content}) # return results diff --git a/searx/engines/vimeo.py b/searx/engines/vimeo.py index 3949a7299..39033c591 100644 --- a/searx/engines/vimeo.py +++ b/searx/engines/vimeo.py @@ -1,4 +1,4 @@ -## Vimeo (Videos) +# Vimeo (Videos) # # @website https://vimeo.com/ # @provide-api yes (http://developer.vimeo.com/api), @@ -7,15 +7,16 @@ # @using-api no (TODO, rewrite to api) # @results HTML (using search portal) # @stable no (HTML can change) -# @parse url, title, publishedDate, thumbnail +# @parse url, title, publishedDate, thumbnail, embedded # # @todo rewrite to api # @todo set content-parameter with correct data from urllib import urlencode from lxml import html +from HTMLParser import HTMLParser +from searx.engines.xpath import extract_text from dateutil import parser -from cgi import escape # engine dependent config categories = ['videos'] @@ -32,6 +33,10 @@ title_xpath = './a/div[@class="data"]/p[@class="title"]' content_xpath = './a/img/@src' publishedDate_xpath = './/p[@class="meta"]//attribute::datetime' +embedded_url = '<iframe data-src="//player.vimeo.com/video{videoid}" ' +\ + 'width="540" height="304" frameborder="0" ' +\ + 'webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>' + # do search-request def request(query, params): @@ -46,13 +51,17 @@ def response(resp): results = [] dom = html.fromstring(resp.text) + p = HTMLParser() # parse results for result in dom.xpath(results_xpath): - url = base_url + result.xpath(url_xpath)[0] - title = escape(html.tostring(result.xpath(title_xpath)[0], method='text', encoding='UTF-8').decode("utf-8")) - thumbnail = result.xpath(content_xpath)[0] - publishedDate = parser.parse(result.xpath(publishedDate_xpath)[0]) + videoid = result.xpath(url_xpath)[0] + url = base_url + videoid + title = p.unescape(extract_text(result.xpath(title_xpath))) + thumbnail = extract_text(result.xpath(content_xpath)[0]) + publishedDate = parser.parse(extract_text( + result.xpath(publishedDate_xpath)[0])) + embedded = embedded_url.format(videoid=videoid) # append result results.append({'url': url, @@ -60,6 +69,7 @@ def response(resp): 'content': '', 'template': 'videos.html', 'publishedDate': publishedDate, + 'embedded': embedded, 'thumbnail': thumbnail}) # return results diff --git a/searx/engines/youtube.py b/searx/engines/youtube.py index 973e799f8..59f07c574 100644 --- a/searx/engines/youtube.py +++ b/searx/engines/youtube.py @@ -6,7 +6,7 @@ # @using-api yes # @results JSON # @stable yes -# @parse url, title, content, publishedDate, thumbnail +# @parse url, title, content, publishedDate, thumbnail, embedded from json import loads from urllib import urlencode @@ -19,7 +19,11 @@ language_support = True # search-url base_url = 'https://gdata.youtube.com/feeds/api/videos' -search_url = base_url + '?alt=json&{query}&start-index={index}&max-results=5' # noqa +search_url = base_url + '?alt=json&{query}&start-index={index}&max-results=5' + +embedded_url = '<iframe width="540" height="304" ' +\ + 'data-src="//www.youtube-nocookie.com/embed/{videoid}" ' +\ + 'frameborder="0" allowfullscreen></iframe>' # do search-request @@ -60,6 +64,8 @@ def response(resp): if url.endswith('&'): url = url[:-1] + videoid = url[32:] + title = result['title']['$t'] content = '' thumbnail = '' @@ -72,12 +78,15 @@ def response(resp): content = result['content']['$t'] + embedded = embedded_url.format(videoid=videoid) + # append result results.append({'url': url, 'title': title, 'content': content, 'template': 'videos.html', 'publishedDate': publishedDate, + 'embedded': embedded, 'thumbnail': thumbnail}) # return results |