[kickass] Fix download URL and magnet support in all iter_torrents

This commit is contained in:
Julien Veyssier 2013-02-28 00:46:40 +01:00
commit d05b8f959a

View file

@ -38,6 +38,8 @@ class TorrentsPage(BasePage):
def iter_torrents(self): def iter_torrents(self):
for tr in self.document.getiterator('tr'): for tr in self.document.getiterator('tr'):
if tr.attrib.get('class', '') == 'odd' or tr.attrib.get('class', '') == ' even': if tr.attrib.get('class', '') == 'odd' or tr.attrib.get('class', '') == ' even':
magnet = NotAvailable
url = NotAvailable
if not 'id' in tr.attrib: if not 'id' in tr.attrib:
continue continue
title = tr.getchildren()[0].getchildren()[1].getchildren()[1].text title = tr.getchildren()[0].getchildren()[1].getchildren()[1].text
@ -49,11 +51,14 @@ class TorrentsPage(BasePage):
.replace('.html', '') .replace('.html', '')
# look for url # look for url
for a in tr.getchildren()[0].getiterator('a'): for a in self.parser.select(tr,'div.iaconbox a'):
if '.torrent' in a.attrib.get('href', ''): href = a.attrib.get('href', '')
url = a.attrib['href'] if href.startswith('magnet'):
if url.startswith('//'): magnet = href
url = 'http:%s'%url elif href.startswith('http'):
url = href
elif href.startswith('//'):
url = 'http:%s'%href
size = tr.getchildren()[1].text size = tr.getchildren()[1].text
u = tr.getchildren()[1].getchildren()[0].text u = tr.getchildren()[1].getchildren()[0].text
@ -64,6 +69,7 @@ class TorrentsPage(BasePage):
torrent = Torrent(idt, title) torrent = Torrent(idt, title)
torrent.url = url torrent.url = url
torrent.magnet = magnet
torrent.description = NotAvailable.__unicode__() torrent.description = NotAvailable.__unicode__()
torrent.filename = parse_qs(urlsplit(url).query).get('title', [None])[0] torrent.filename = parse_qs(urlsplit(url).query).get('title', [None])[0]
torrent.size = get_bytes_size(size, u) torrent.size = get_bytes_size(size, u)