piratebay: Support proxies, change to new default URL

This commit is contained in:
Laurent Bachelier 2013-05-06 00:20:28 +02:00
commit ea1ff80f57
2 changed files with 26 additions and 16 deletions

View file

@ -18,7 +18,8 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.torrent import ICapTorrent, MagnetOnly, Torrent from weboob.capabilities.torrent import ICapTorrent, MagnetOnly, Torrent
from weboob.tools.backend import BaseBackend from weboob.tools.backend import BaseBackend, BackendConfig
from weboob.tools.value import Value
from weboob.capabilities.base import NotAvailable from weboob.capabilities.base import NotAvailable
from .browser import PiratebayBrowser from .browser import PiratebayBrowser
@ -35,9 +36,10 @@ class PiratebayBackend(BaseBackend, ICapTorrent):
DESCRIPTION = 'The Pirate Bay BitTorrent tracker' DESCRIPTION = 'The Pirate Bay BitTorrent tracker'
LICENSE = 'AGPLv3+' LICENSE = 'AGPLv3+'
BROWSER = PiratebayBrowser BROWSER = PiratebayBrowser
CONFIG = BackendConfig(Value('proxybay', label='Use a Proxy Bay', regexp=r'https?://.*', default='', required=False))
def create_default_browser(self): def create_default_browser(self):
return self.create_browser() return self.create_browser(self.config['proxybay'].get())
def get_torrent(self, id): def get_torrent(self, id):
return self.browser.get_torrent(id) return self.browser.get_torrent(id)
@ -63,6 +65,4 @@ class PiratebayBackend(BaseBackend, ICapTorrent):
torrent.url = tor.url torrent.url = tor.url
return torrent return torrent
OBJECTS = { OBJECTS = {Torrent: fill_torrent}
Torrent:fill_torrent
}

View file

@ -18,6 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from urlparse import urlsplit
import urllib import urllib
from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
@ -30,25 +31,34 @@ __all__ = ['PiratebayBrowser']
class PiratebayBrowser(BaseBrowser): class PiratebayBrowser(BaseBrowser):
DOMAIN = 'thepiratebay.se'
PROTOCOL = 'https'
ENCODING = 'utf-8' ENCODING = 'utf-8'
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
PAGES = {'https://thepiratebay.se/': IndexPage, def __init__(self, url, *args, **kwargs):
'https://thepiratebay.se/search/.*/0/7/0': TorrentsPage, url = url or 'https://thepiratebay.sx/'
'https://thepiratebay.se/torrent/.*': TorrentPage url_parsed = urlsplit(url)
} self.PROTOCOL = url_parsed.scheme
self.DOMAIN = url_parsed.netloc
self.PAGES = {
'%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage,
'%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage,
'%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage
}
BaseBrowser.__init__(self, *args, **kwargs)
def iter_torrents(self, pattern): def iter_torrents(self, pattern):
self.location('https://thepiratebay.se/search/%s/0/7/0' % urllib.quote_plus(pattern.encode('utf-8'))) self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL,
self.DOMAIN,
urllib.quote_plus(pattern.encode('utf-8'))))
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):
try: try:
self.location('https://thepiratebay.se/torrent/%s/' % id) self.location('%s://%s/torrent/%s/' % (self.PROTOCOL,
self.DOMAIN,
_id))
except BrowserHTTPNotFound: except BrowserHTTPNotFound:
return return
if self.is_on_page(TorrentPage): if self.is_on_page(TorrentPage):
return self.page.get_torrent(id) return self.page.get_torrent(_id)