mirror of
https://github.com/searxng/searxng.git
synced 2024-11-26 12:51:02 +00:00
Merge pull request #1658 from dalf/video-fixes
Fix dailymotion, google_videos and youtube_noapi engines
This commit is contained in:
commit
1bed39e6cb
3 changed files with 22 additions and 17 deletions
|
@ -15,7 +15,7 @@
|
||||||
from json import loads
|
from json import loads
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from searx.url_utils import urlencode
|
from searx.url_utils import urlencode
|
||||||
from searx.utils import match_language
|
from searx.utils import match_language, html_to_text
|
||||||
|
|
||||||
# engine dependent config
|
# engine dependent config
|
||||||
categories = ['videos']
|
categories = ['videos']
|
||||||
|
@ -59,7 +59,7 @@ def response(resp):
|
||||||
for res in search_res['list']:
|
for res in search_res['list']:
|
||||||
title = res['title']
|
title = res['title']
|
||||||
url = res['url']
|
url = res['url']
|
||||||
content = res['description']
|
content = html_to_text(res['description'])
|
||||||
thumbnail = res['thumbnail_360_url']
|
thumbnail = res['thumbnail_360_url']
|
||||||
publishedDate = datetime.fromtimestamp(res['created_time'], None)
|
publishedDate = datetime.fromtimestamp(res['created_time'], None)
|
||||||
embedded = embedded_url.format(videoid=res['id'])
|
embedded = embedded_url.format(videoid=res['id'])
|
||||||
|
|
|
@ -75,8 +75,10 @@ def response(resp):
|
||||||
|
|
||||||
# get thumbnails
|
# get thumbnails
|
||||||
script = str(dom.xpath('//script[contains(., "_setImagesSrc")]')[0].text)
|
script = str(dom.xpath('//script[contains(., "_setImagesSrc")]')[0].text)
|
||||||
id = result.xpath('.//div[@class="s"]//img/@id')[0]
|
ids = result.xpath('.//div[@class="s"]//img/@id')
|
||||||
thumbnails_data = re.findall('s=\'(.*?)(?:\\\\[a-z,1-9,\\\\]+\'|\')\;var ii=\[(?:|[\'vidthumb\d+\',]+)\'' + id,
|
if len(ids) > 0:
|
||||||
|
thumbnails_data = \
|
||||||
|
re.findall('s=\'(.*?)(?:\\\\[a-z,1-9,\\\\]+\'|\')\;var ii=\[(?:|[\'vidthumb\d+\',]+)\'' + ids[0],
|
||||||
script)
|
script)
|
||||||
tmp = []
|
tmp = []
|
||||||
if len(thumbnails_data) != 0:
|
if len(thumbnails_data) != 0:
|
||||||
|
|
|
@ -67,12 +67,8 @@ def response(resp):
|
||||||
if videoid is not None:
|
if videoid is not None:
|
||||||
url = base_youtube_url + videoid
|
url = base_youtube_url + videoid
|
||||||
thumbnail = 'https://i.ytimg.com/vi/' + videoid + '/hqdefault.jpg'
|
thumbnail = 'https://i.ytimg.com/vi/' + videoid + '/hqdefault.jpg'
|
||||||
title = video.get('title', {}).get('simpleText', videoid)
|
title = get_text_from_json(video.get('title', {}))
|
||||||
description_snippet = video.get('descriptionSnippet', {})
|
content = get_text_from_json(video.get('descriptionSnippet', {}))
|
||||||
if 'runs' in description_snippet:
|
|
||||||
content = reduce(lambda a, b: a + b.get('text', ''), description_snippet.get('runs'), '')
|
|
||||||
else:
|
|
||||||
content = description_snippet.get('simpleText', '')
|
|
||||||
embedded = embedded_url.format(videoid=videoid)
|
embedded = embedded_url.format(videoid=videoid)
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
|
@ -85,3 +81,10 @@ def response(resp):
|
||||||
|
|
||||||
# return results
|
# return results
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def get_text_from_json(element):
|
||||||
|
if 'runs' in element:
|
||||||
|
return reduce(lambda a, b: a + b.get('text', ''), element.get('runs'), '')
|
||||||
|
else:
|
||||||
|
return element.get('simpleText', '')
|
||||||
|
|
Loading…
Reference in a new issue