diff --git a/weboob/backends/piratebay/backend.py b/weboob/backends/piratebay/backend.py index f7e6031da04789c019410e00dd275da679ccbc6a..214ca8c11cc5624aea774a2dbb2d95a2d3ddaf02 100644 --- a/weboob/backends/piratebay/backend.py +++ b/weboob/backends/piratebay/backend.py @@ -52,4 +52,4 @@ def get_torrent_file(self, id): return self.browser.openurl(torrent.url.encode('utf-8')).read() def iter_torrents(self, pattern): - return self.browser.iter_torrents(pattern) + return self.browser.iter_torrents(pattern.replace(' ','+')) diff --git a/weboob/backends/piratebay/browser.py b/weboob/backends/piratebay/browser.py index 839a287f97908fd2a537335af56d5cc6b2234e9d..ddd408f5b1649044b2dc9b28a1348a7a0a763e95 100644 --- a/weboob/backends/piratebay/browser.py +++ b/weboob/backends/piratebay/browser.py @@ -19,7 +19,7 @@ from weboob.tools.browser import BaseBrowser from .pages.index import IndexPage -from .pages.torrents import TorrentsPage +from .pages.torrents import TorrentsPage, TorrentPage __all__ = ['PiratebayBrowser'] @@ -27,10 +27,11 @@ class PiratebayBrowser(BaseBrowser): PROTOCOL = 'https' + ENCODING = 'utf-8' USER_AGENT = BaseBrowser.USER_AGENTS['wget'] PAGES = {'https://thepiratebay.org' : IndexPage, 'https://thepiratebay.org/search/.*/0/7/0' : TorrentsPage, - #'https://thepiratebay.org/torrent/.*' : TorrentPage + 'https://thepiratebay.org/torrent/.*' : TorrentPage } def __init__(self, *args, **kwargs): @@ -59,12 +60,13 @@ def home(self): def iter_torrents(self, pattern): #self.location(self.buildurl('/torrents.php', searchstr=pattern)) - self.location('https://thepiratebay.org/search/%s/0/7/0' % pattern, '') + self.location('https://thepiratebay.org/search/%s/0/7/0' % pattern) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def get_torrent(self, id): + print 'goto:'+id self.location('https://thepiratebay.org/torrent/%s/' % id) assert self.is_on_page(TorrentPage) diff --git a/weboob/backends/piratebay/pages/torrents.py b/weboob/backends/piratebay/pages/torrents.py index 99cffcc09d83b6ccf1926fb0305a5c5450e43644..f95e546dc1e54257a19be0783abef9e4416437c3 100644 --- a/weboob/backends/piratebay/pages/torrents.py +++ b/weboob/backends/piratebay/pages/torrents.py @@ -29,19 +29,14 @@ class TorrentsPage(BasePage): - #TORRENTID_REGEXP = re.compile('torrents\.php\?action=download&id=(\d+)') def unit(self, n, u): m = {'KB': 1024, 'MB': 1024*1024, 'GB': 1024*1024*1024, 'TB': 1024*1024*1024*1024, } - return float(n.replace(',', '')) * m.get(u, 1) - - #def format_url(self, url): - # return '%s://%s/%s' % (self.browser.PROTOCOL, - # self.browser.DOMAIN, - # url) + #return float(n.replace(',', '')) * m.get(u, 1) + return float(n*m[u]) def iter_torrents(self): @@ -73,11 +68,12 @@ def iter_torrents(self): torrent = Torrent(idt, title, url=url, - size=self.unit(size.replace('.',','),u), + size=self.unit(float(size),u), seeders=int(seed), leechers=int(leech)) yield torrent +class TorrentPage(BasePage): def get_torrent(self, id): table = self.document.getroot().cssselect('div.thin') if not table: