67def response(resp):
68 results = []
69 json = resp.json()
70
71 if not json.get("query", {}).get("pages"):
72 return results
73 for item in json["query"]["pages"].values():
74 imageinfo = item["imageinfo"][0]
75 title = item["title"].replace("File:", "").rsplit('.', 1)[0]
76 result = {
77 'url': imageinfo["descriptionurl"],
78 'title': title,
79 'content': html_to_text(item["snippet"]),
80 }
81
82 if search_type == "images":
83 result['template'] = 'images.html'
84 result['img_src'] = imageinfo["url"]
85 result['thumbnail_src'] = imageinfo["thumburl"]
86 result['resolution'] = f'{imageinfo["width"]} x {imageinfo["height"]}'
87 else:
88 result['thumbnail'] = imageinfo["thumburl"]
89
90 if search_type == "videos":
91 result['template'] = 'videos.html'
92 if imageinfo.get('duration'):
93 result['length'] = datetime.timedelta(seconds=int(imageinfo['duration']))
94 result['iframe_src'] = imageinfo['url']
95 elif search_type == "files":
96 result['template'] = 'files.html'
97 result['metadata'] = imageinfo['mime']
98 result['size'] = humanize_bytes(imageinfo['size'])
99 elif search_type == "audio":
100 result['iframe_src'] = imageinfo['url']
101
102 results.append(result)
103
104 return results