45def response(resp):
46 results = []
47
48 search_results = loads(resp.text)
49
50 if 'error' in search_results and 'message' in search_results['error']:
51 raise SearxEngineAPIException(search_results['error']['message'])
52
53
54 if 'items' not in search_results:
55 return []
56
57
58 for result in search_results['items']:
59 if "videoId" not in result["id"]:
60
61 continue
62
63 videoid = result['id']['videoId']
64
65 title = result['snippet']['title']
66 content = ''
67 thumbnail = ''
68
69 pubdate = result['snippet']['publishedAt']
70 publishedDate = parser.parse(pubdate)
71
72 thumbnail = result['snippet']['thumbnails']['high']['url']
73
74 content = result['snippet']['description']
75
76 url = base_youtube_url + videoid
77
78
79 results.append(
80 {
81 'url': url,
82 'title': title,
83 'content': content,
84 'template': 'videos.html',
85 'publishedDate': publishedDate,
86 'iframe_src': "https://www.youtube-nocookie.com/embed/" + videoid,
87 'thumbnail': thumbnail,
88 }
89 )
90
91
92 return results