40def response(resp):
41 results = []
42
43 dom = html.fromstring(resp.text)
44 rows = dom.xpath('//table[@class="listing"]//tr[contains(@class, "category_0")]')
45
46
47
48 if len(rows) == 0 or len(rows) % 2 != 0:
49 return []
50
51
52 size_re = re.compile(r'[\d.]+(T|G|M)?B', re.IGNORECASE)
53
54
55 for i in range(0, len(rows), 2):
56
57 name_row = rows[i]
58
59 links = name_row.xpath('./td[@class="desc-top"]/a')
60 params = {'template': 'torrent.html', 'url': links[-1].attrib.get('href'), 'title': extract_text(links[-1])}
61
62
63 if len(links) == 2:
64 magnet = links[0].attrib.get('href')
65 if magnet.startswith('magnet'):
66
67 params['magnetlink'] = magnet
68
69
70 info_row = rows[i + 1]
71 desc = extract_text(info_row.xpath('./td[@class="desc-bot"]')[0])
72 for item in desc.split('|'):
73 item = item.strip()
74 if item.startswith('Size:'):
75 try:
76 params['filesize'] = size_re.search(item).group()
77 except:
78 pass
79 elif item.startswith('Date:'):
80 try:
81
82 date = datetime.strptime(item, 'Date: %Y-%m-%d %H:%M UTC')
83 params['publishedDate'] = date
84 except:
85 pass
86 elif item.startswith('Comment:'):
87 params['content'] = item
88 stats = info_row.xpath('./td[@class="stats"]/span')
89
90 if len(stats) == 3:
91 params['seed'] = int_or_zero(extract_text(stats[0]))
92 params['leech'] = int_or_zero(extract_text(stats[1]))
93
94 results.append(params)
95
96 return results