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'Size:\s*([\d.]+)(TB|GB|MB|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
77 groups = size_re.match(item).groups()
78 params['filesize'] = get_torrent_size(groups[0], groups[1])
79 except:
80 pass
81 elif item.startswith('Date:'):
82 try:
83
84 date = datetime.strptime(item, 'Date: %Y-%m-%d %H:%M UTC')
85 params['publishedDate'] = date
86 except:
87 pass
88 elif item.startswith('Comment:'):
89 params['content'] = item
90 stats = info_row.xpath('./td[@class="stats"]/span')
91
92 if len(stats) == 3:
93 params['seed'] = int_or_zero(extract_text(stats[0]))
94 params['leech'] = int_or_zero(extract_text(stats[1]))
95
96 results.append(params)
97
98 return results