Clean up the Torrent object

As discussed on IRC, those huge constructors aren't ideal.
Includes misc pep8 fixes.
This commit is contained in:
Laurent Bachelier 2012-03-09 00:42:31 +01:00
commit a31a751e28
5 changed files with 44 additions and 44 deletions

View file

@ -39,6 +39,7 @@ __all__ = ['TorrentsPage']
class TorrentsPage(BasePage):
TORRENTID_REGEXP = re.compile('torrents\.php\?action=download&id=(\d+)')
def format_url(self, url):
return '%s://%s/%s' % (self.browser.PROTOCOL,
self.browser.DOMAIN,
@ -75,7 +76,7 @@ class TorrentsPage(BasePage):
if len(tds) == 7:
# Under a group
i = 0
elif len(tds) in (8,9):
elif len(tds) in (8, 9):
# An alone torrent
i = len(tds) - 1
while i >= 0 and tds[i].find('a') is None:
@ -102,16 +103,15 @@ class TorrentsPage(BasePage):
size, unit = tds[i+3].text.split()
except ValueError:
size, unit = tds[i+2].text.split()
size = get_bytes_size(float(size.replace(',','')), unit)
size = get_bytes_size(float(size.replace(',', '')), unit)
seeders = int(tds[-2].text)
leechers = int(tds[-1].text)
torrent = Torrent(id,
title,
url=self.format_url(url),
size=size,
seeders=seeders,
leechers=leechers)
torrent = Torrent(id, title)
torrent.url = self.format_url(url)
torrent.size = size
torrent.seeders = seeders
torrent.leechers = leechers
yield torrent
else:
debug('unknown attrib: %s' % tr.attrib)

View file

@ -32,7 +32,7 @@ class TorrentsPage(BasePage):
if tr.attrib.get('class', '') == 'hlRow':
# sometimes the first tr also has the attribute hlRow
# i use that to ditinct it from the others
if tr.attrib.has_key('onmouseout'):
if 'onmouseout' in tr.attrib:
atitle = tr.getchildren()[2].getchildren()[1]
title = atitle.text
if not title:
@ -42,7 +42,7 @@ class TorrentsPage(BasePage):
title += bold.text
if bold.tail:
title += bold.tail
idt = tr.getchildren()[2].getchildren()[0].attrib.get('href','')
idt = tr.getchildren()[2].getchildren()[0].attrib.get('href', '')
idt = idt.split('/')[2]
size = tr.getchildren()[3].text
u = size[-2:]
@ -50,12 +50,12 @@ class TorrentsPage(BasePage):
seed = tr.getchildren()[4].text
leech = tr.getchildren()[5].text
url = 'https://isohunt.com/download/%s/mon_joli_torrent.torrent' % idt
yield Torrent(idt,
title,
url=url,
size=get_bytes_size(size, u),
seeders=int(seed),
leechers=int(leech))
torrent = Torrent(idt, title)
torrent.url = url
torrent.size = get_bytes_size(size, u)
torrent.seeders = int(seed)
torrent.leechers = int(leech)
yield torrent
class TorrentPage(BasePage):
@ -95,7 +95,7 @@ class TorrentPage(BasePage):
description = p.getchildren()[1].tail
if count_p_found == 2:
if p.getchildren()[0].text == 'Directory:':
files.append(p.getchildren()[0].tail.strip()+'/')
files.append(p.getchildren()[0].tail.strip() + '/')
else:
files.append(p.getchildren()[0].tail.strip())

View file

@ -22,6 +22,7 @@ try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
from urlparse import urlsplit
from weboob.capabilities.torrent import Torrent
@ -59,13 +60,13 @@ class TorrentsPage(BasePage):
seed = tr.getchildren()[4].text
leech = tr.getchildren()[5].text
yield Torrent(idt,
title,
url=url,
filename=parse_qs(urlsplit(url).query).get('title', [None])[0],
size=get_bytes_size(size, u),
seeders=int(seed),
leechers=int(leech))
torrent = Torrent(idt, title)
torrent.url = url
torrent.filename = parse_qs(urlsplit(url).query).get('title', [None])[0]
torrent.size = get_bytes_size(size, u)
torrent.seeders = int(seed)
torrent.leechers = int(leech)
yield torrent
class TorrentPage(BasePage):
@ -105,7 +106,7 @@ class TorrentPage(BasePage):
for span in self.document.getiterator('span'):
# sometimes there are others span, this is not so sure but the size of the children list
# is enough to know if this is the right span
if (span.attrib.get('class', '') == 'folder' or span.attrib.get('class', '') == 'folderopen') and len(span.getchildren())>2:
if (span.attrib.get('class', '') == 'folder' or span.attrib.get('class', '') == 'folderopen') and len(span.getchildren()) > 2:
size = span.getchildren()[1].tail
u = span.getchildren()[2].text
size = float(size.split(': ')[1].replace(',', '.'))

View file

@ -55,12 +55,11 @@ class TorrentsPage(BasePage):
seed = tr.getchildren()[2].text
leech = tr.getchildren()[3].text
torrent = Torrent(idt,
title,
url=url,
size=self.unit(float(size), u),
seeders=int(seed),
leechers=int(leech))
torrent = Torrent(idt, title)
torrent.url = url
torrent.size = self.unit(float(size), u)
torrent.seeders = int(seed)
torrent.leechers = int(leech)
yield torrent