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