[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()
|
return self.browser.openurl(torrent.url.encode('utf-8')).read()
|
||||||
|
|
||||||
def iter_torrents(self, pattern):
|
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 weboob.tools.browser import BaseBrowser
|
||||||
|
|
||||||
from .pages.index import IndexPage
|
from .pages.index import IndexPage
|
||||||
from .pages.torrents import TorrentsPage
|
from .pages.torrents import TorrentsPage, TorrentPage
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['PiratebayBrowser']
|
__all__ = ['PiratebayBrowser']
|
||||||
|
|
@ -27,10 +27,11 @@ __all__ = ['PiratebayBrowser']
|
||||||
|
|
||||||
class PiratebayBrowser(BaseBrowser):
|
class PiratebayBrowser(BaseBrowser):
|
||||||
PROTOCOL = 'https'
|
PROTOCOL = 'https'
|
||||||
|
ENCODING = 'utf-8'
|
||||||
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
|
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
|
||||||
PAGES = {'https://thepiratebay.org' : IndexPage,
|
PAGES = {'https://thepiratebay.org' : IndexPage,
|
||||||
'https://thepiratebay.org/search/.*/0/7/0' : TorrentsPage,
|
'https://thepiratebay.org/search/.*/0/7/0' : TorrentsPage,
|
||||||
#'https://thepiratebay.org/torrent/.*' : TorrentPage
|
'https://thepiratebay.org/torrent/.*' : TorrentPage
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
@ -59,12 +60,13 @@ class PiratebayBrowser(BaseBrowser):
|
||||||
|
|
||||||
def iter_torrents(self, pattern):
|
def iter_torrents(self, pattern):
|
||||||
#self.location(self.buildurl('/torrents.php', searchstr=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)
|
assert self.is_on_page(TorrentsPage)
|
||||||
return self.page.iter_torrents()
|
return self.page.iter_torrents()
|
||||||
|
|
||||||
def get_torrent(self, id):
|
def get_torrent(self, id):
|
||||||
|
print 'goto:'+id
|
||||||
self.location('https://thepiratebay.org/torrent/%s/' % id)
|
self.location('https://thepiratebay.org/torrent/%s/' % id)
|
||||||
|
|
||||||
assert self.is_on_page(TorrentPage)
|
assert self.is_on_page(TorrentPage)
|
||||||
|
|
|
||||||
|
|
@ -29,19 +29,14 @@ __all__ = ['TorrentsPage']
|
||||||
|
|
||||||
|
|
||||||
class TorrentsPage(BasePage):
|
class TorrentsPage(BasePage):
|
||||||
#TORRENTID_REGEXP = re.compile('torrents\.php\?action=download&id=(\d+)')
|
|
||||||
def unit(self, n, u):
|
def unit(self, n, u):
|
||||||
m = {'KB': 1024,
|
m = {'KB': 1024,
|
||||||
'MB': 1024*1024,
|
'MB': 1024*1024,
|
||||||
'GB': 1024*1024*1024,
|
'GB': 1024*1024*1024,
|
||||||
'TB': 1024*1024*1024*1024,
|
'TB': 1024*1024*1024*1024,
|
||||||
}
|
}
|
||||||
return float(n.replace(',', '')) * m.get(u, 1)
|
#return float(n.replace(',', '')) * m.get(u, 1)
|
||||||
|
return float(n*m[u])
|
||||||
#def format_url(self, url):
|
|
||||||
# return '%s://%s/%s' % (self.browser.PROTOCOL,
|
|
||||||
# self.browser.DOMAIN,
|
|
||||||
# url)
|
|
||||||
|
|
||||||
def iter_torrents(self):
|
def iter_torrents(self):
|
||||||
|
|
||||||
|
|
@ -73,11 +68,12 @@ class TorrentsPage(BasePage):
|
||||||
torrent = Torrent(idt,
|
torrent = Torrent(idt,
|
||||||
title,
|
title,
|
||||||
url=url,
|
url=url,
|
||||||
size=self.unit(size.replace('.',','),u),
|
size=self.unit(float(size),u),
|
||||||
seeders=int(seed),
|
seeders=int(seed),
|
||||||
leechers=int(leech))
|
leechers=int(leech))
|
||||||
yield torrent
|
yield torrent
|
||||||
|
|
||||||
|
class TorrentPage(BasePage):
|
||||||
def get_torrent(self, id):
|
def get_torrent(self, id):
|
||||||
table = self.document.getroot().cssselect('div.thin')
|
table = self.document.getroot().cssselect('div.thin')
|
||||||
if not table:
|
if not table:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue