on master help sign in
youtube_noapi uses searx.utils.list_get
dafedbfDalf
searx/engines/youtube_noapi.py+1−8
@@ -11,6 +11,7 @@
11from urllib import quote_plus
11from urllib import quote_plus
12from lxml import html
12from lxml import html
13from searx.engines.xpath import extract_text
13from searx.engines.xpath import extract_text
14+from searx.utils import list_get
14
15
15# engine dependent config
16# engine dependent config
16categories = ['videos', 'music']
17categories = ['videos', 'music']
@@ -34,14 +35,6 @@ title_xpath = './/div[@class="yt-lockup-content"]/h3/a'
34content_xpath = './/div[@class="yt-lockup-content"]/div[@class="yt-lockup-description yt-ui-ellipsis yt-ui-ellipsis-2"]'
35content_xpath = './/div[@class="yt-lockup-content"]/div[@class="yt-lockup-description yt-ui-ellipsis yt-ui-ellipsis-2"]'
35
36
36
37
37−# get element in list or default value
38−def list_get(a_list, index, default=None):
39− if len(a_list) > index:
40− return a_list[index]
41− else:
42− return default
43−
44−
45# returns extract_text on the first result selected by the xpath or None
38# returns extract_text on the first result selected by the xpath or None
46def extract_text_from_dom(result, xpath):
39def extract_text_from_dom(result, xpath):
47 r = result.xpath(xpath)
40 r = result.xpath(xpath)