46def response(resp):
47 results = []
48 dom = html.fromstring(resp.text)
49
50 for result in eval_xpath(dom, '//li[contains(@class, "search-result")]'):
51 torrentfile = eval_xpath_getindex(result, './/a[contains(@class, "dl-torrent")]/@href', 0, None)
52 magnet = eval_xpath_getindex(result, './/a[contains(@class, "dl-magnet")]/@href', 0, None)
53 if torrentfile is None or magnet is None:
54 continue
55 title = eval_xpath_getindex(result, './/h5[contains(@class, "title")]', 0, None)
56 url = eval_xpath_getindex(result, './/h5[contains(@class, "title")]/a/@href', 0, None)
57 categ = eval_xpath(result, './/a[contains(@class, "category")]')
58 stats = eval_xpath_list(result, './/div[contains(@class, "stats")]/div', min_len=5)
59
60 params = {
61 'seed': extract_text(stats[3]),
62 'leech': extract_text(stats[2]),
63 'title': extract_text(title),
64 'url': resp.search_params['base_url'] + url,
65 'filesize': extract_text(stats[1]),
66 'magnetlink': magnet,
67 'torrentfile': torrentfile,
68 'metadata': extract_text(categ),
69 'template': "torrent.html",
70 }
71
72 try:
73 params['publishedDate'] = datetime.strptime(extract_text(stats[4]), '%b %d, %Y')
74 except ValueError:
75 pass
76
77 results.append(params)
78
79 return results