46def response(resp):
47
48 results = []
49 dom = html.fromstring(resp.text)
50
51 for result in eval_xpath_list(dom, '//li[contains(@class, "searchresult")]'):
52
53 link = eval_xpath_getindex(result, './/div[@class="itemurl"]/a', 0, default=None)
54 if link is None:
55 continue
56
57 title = result.xpath('.//div[@class="heading"]/a/text()')
58 content = result.xpath('.//div[@class="subhead"]/text()')
59 new_result = {
60 "url": extract_text(link),
61 "title": extract_text(title),
62 "content": extract_text(content),
63 }
64
65 date = eval_xpath_getindex(result, '//div[@class="released"]/text()', 0, default=None)
66 if date:
67 new_result["publishedDate"] = dateparse(date.replace("released ", ""))
68
69 thumbnail = result.xpath('.//div[@class="art"]/img/@src')
70 if thumbnail:
71 new_result['thumbnail'] = thumbnail[0]
72
73 result_id = parse_qs(urlparse(link.get('href')).query)["search_item_id"][0]
74 itemtype = extract_text(result.xpath('.//div[@class="itemtype"]')).lower()
75 if "album" == itemtype:
76 new_result["iframe_src"] = iframe_src.format(type='album', result_id=result_id)
77 elif "track" == itemtype:
78 new_result["iframe_src"] = iframe_src.format(type='track', result_id=result_id)
79
80 results.append(new_result)
81 return results