summaryrefslogtreecommitdiff
path: root/searx/engines/youtube_noapi.py
diff options
context:
space:
mode:
authorDalf <alex@al-f.net>2019-07-31 08:39:40 +0200
committerDalf <alex@al-f.net>2019-07-31 08:39:40 +0200
commit0c032c84291954da206e8084553d91add240afd2 (patch)
tree60321d6d247c752ab5ac2f3c242daffd6795aaf2 /searx/engines/youtube_noapi.py
parent8b7ac56669ab355eb1bca92a44372ab9f343f6aa (diff)
downloadsearxng-0c032c84291954da206e8084553d91add240afd2.tar.gz
searxng-0c032c84291954da206e8084553d91add240afd2.zip
[fix] youtube_noapi engine: fix the title
Diffstat (limited to 'searx/engines/youtube_noapi.py')
-rw-r--r--searx/engines/youtube_noapi.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/searx/engines/youtube_noapi.py b/searx/engines/youtube_noapi.py
index 53a10bf35..49d0ae604 100644
--- a/searx/engines/youtube_noapi.py
+++ b/searx/engines/youtube_noapi.py
@@ -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
@@ -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', '')