Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
[fix] youtube_noapi engine: fix the title
Browse files Browse the repository at this point in the history
  • Loading branch information
dalf committed Jul 31, 2019
1 parent 8b7ac56 commit 0c032c8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions searx/engines/youtube_noapi.py
Expand Up @@ -67,12 +67,8 @@ def response(resp):
if videoid is not None:
url = base_youtube_url + videoid
thumbnail = 'https://i.ytimg.com/vi/' + videoid + '/hqdefault.jpg'
title = video.get('title', {}).get('simpleText', videoid)
description_snippet = 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', '')
title = get_text_from_json(video.get('title', {}))
content = get_text_from_json(video.get('descriptionSnippet', {}))
embedded = embedded_url.format(videoid=videoid)

# append result
Expand All @@ -85,3 +81,10 @@ def response(resp):

# 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', '')

0 comments on commit 0c032c8

Please sign in to comment.