[piratebay] search
This commit is contained in:
parent
0cc2458513
commit
856e55d214
3 changed files with 10 additions and 12 deletions
|
|
@ -52,4 +52,4 @@ class PiratebayBackend(BaseBackend, ICapTorrent):
|
|||
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(' ','+'))
|
||||
|
|
|
|||
|
|
@ -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 @@ __all__ = ['PiratebayBrowser']
|
|||
|
||||
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 @@ class PiratebayBrowser(BaseBrowser):
|
|||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -29,19 +29,14 @@ __all__ = ['TorrentsPage']
|
|||
|
||||
|
||||
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 @@ class TorrentsPage(BasePage):
|
|||
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue