[kickass] problem with colors into usefull text
This commit is contained in:
parent
de75347035
commit
c1f64768ee
7 changed files with 268 additions and 0 deletions
3
weboob/backends/kickass/__init__.py
Normal file
3
weboob/backends/kickass/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from .backend import KickassBackend
|
||||||
|
|
||||||
|
__all__ = ['KickassBackend']
|
||||||
54
weboob/backends/kickass/backend.py
Normal file
54
weboob/backends/kickass/backend.py
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2010 Julien Veyssier
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, version 3 of the License.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
from weboob.capabilities.torrent import ICapTorrent
|
||||||
|
from weboob.tools.backend import BaseBackend
|
||||||
|
|
||||||
|
from .browser import KickassBrowser
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['KickassBackend']
|
||||||
|
|
||||||
|
|
||||||
|
class KickassBackend(BaseBackend, ICapTorrent):
|
||||||
|
NAME = 'kickass'
|
||||||
|
MAINTAINER = 'Julien Veyssier'
|
||||||
|
EMAIL = 'julien.veyssier@aiur.fr'
|
||||||
|
VERSION = '0.4'
|
||||||
|
DESCRIPTION = 'kickasstorrent.com bittorrent tracker'
|
||||||
|
LICENSE = 'GPLv3'
|
||||||
|
#CONFIG = ValuesDict(Value('domain', label='Domain (example "ssl.what.cd")'),
|
||||||
|
# Value('protocol', label='Protocol to use', choices=('http', 'https')),
|
||||||
|
# Value('username', label='Username'),
|
||||||
|
# Value('password', label='Password', masked=True))
|
||||||
|
BROWSER = KickassBrowser
|
||||||
|
|
||||||
|
def create_default_browser(self):
|
||||||
|
return self.create_browser()
|
||||||
|
|
||||||
|
def get_torrent(self, id):
|
||||||
|
return self.browser.get_torrent(id)
|
||||||
|
|
||||||
|
def get_torrent_file(self, id):
|
||||||
|
torrent = self.browser.get_torrent(id)
|
||||||
|
if not torrent:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.browser.openurl(torrent.url.encode('utf-8')).read()
|
||||||
|
|
||||||
|
def iter_torrents(self, pattern):
|
||||||
|
return self.browser.iter_torrents(pattern.replace(' ','+'))
|
||||||
72
weboob/backends/kickass/browser.py
Normal file
72
weboob/backends/kickass/browser.py
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2010 Julien Veyssier
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, version 3 of the License.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.tools.browser import BaseBrowser
|
||||||
|
|
||||||
|
from .pages.index import IndexPage
|
||||||
|
from .pages.torrents import TorrentsPage, TorrentPage
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['KickassBrowser']
|
||||||
|
|
||||||
|
|
||||||
|
class KickassBrowser(BaseBrowser):
|
||||||
|
PROTOCOL = 'http'
|
||||||
|
ENCODING = 'utf-8'
|
||||||
|
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
|
||||||
|
PAGES = {
|
||||||
|
'http://fr.kickasstorrents.com/new/.*field=seeders&sorder=desc' : TorrentsPage,
|
||||||
|
'http://fr.kickasstorrents.com/.*.html' : TorrentPage
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
#self.DOMAIN = domain
|
||||||
|
#self.PROTOCOL = protocol
|
||||||
|
#self.PAGES = {}
|
||||||
|
#for key, value in PiratebayBrowser.PAGES.iteritems():
|
||||||
|
# self.PAGES[key % domain] = value
|
||||||
|
|
||||||
|
BaseBrowser.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
#def login(self):
|
||||||
|
# if not self.is_on_page(LoginPage):
|
||||||
|
# self.home()
|
||||||
|
# self.page.login(self.username, self.password)
|
||||||
|
|
||||||
|
#def is_logged(self):
|
||||||
|
# if not self.page or self.is_on_page(LoginPage):
|
||||||
|
# return False
|
||||||
|
# if self.is_on_page(IndexPage):
|
||||||
|
# return self.page.is_logged()
|
||||||
|
# return True
|
||||||
|
|
||||||
|
def home(self):
|
||||||
|
return self.location('http://fr.kickasstorrents.com/')
|
||||||
|
|
||||||
|
def iter_torrents(self, pattern):
|
||||||
|
#self.location(self.buildurl('/torrents.php', searchstr=pattern))
|
||||||
|
self.location('http://fr.kickasstorrents.com/new/?q=%s&field=seeders&sorder=desc' % pattern)
|
||||||
|
|
||||||
|
assert self.is_on_page(TorrentsPage)
|
||||||
|
return self.page.iter_torrents()
|
||||||
|
|
||||||
|
def get_torrent(self, id):
|
||||||
|
self.location('http://fr.kickasstorrents.com/%s.html' % id)
|
||||||
|
|
||||||
|
assert self.is_on_page(TorrentPage)
|
||||||
|
return self.page.get_torrent(id)
|
||||||
0
weboob/backends/kickass/pages/__init__.py
Normal file
0
weboob/backends/kickass/pages/__init__.py
Normal file
28
weboob/backends/kickass/pages/index.py
Normal file
28
weboob/backends/kickass/pages/index.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2010 Julien Veyssier
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, version 3 of the License.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.tools.browser import BasePage
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['IndexPage']
|
||||||
|
|
||||||
|
|
||||||
|
class IndexPage(BasePage):
|
||||||
|
def is_logged(self):
|
||||||
|
return 'id' in self.document.find('body').attrib
|
||||||
|
|
||||||
85
weboob/backends/kickass/pages/torrents.py
Normal file
85
weboob/backends/kickass/pages/torrents.py
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2010 Julien Veyssier
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, version 3 of the License.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.tools.browser import BasePage
|
||||||
|
from weboob.capabilities.torrent import Torrent
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['TorrentsPage']
|
||||||
|
|
||||||
|
|
||||||
|
class TorrentsPage(BasePage):
|
||||||
|
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)
|
||||||
|
return float(n*m[u])
|
||||||
|
|
||||||
|
def iter_torrents(self):
|
||||||
|
|
||||||
|
for tr in self.document.getiterator('tr'):
|
||||||
|
if tr.attrib.get('class','') == 'odd' or tr.attrib.get('class','') == ' even':
|
||||||
|
title = tr.getchildren()[0].getchildren()[1].getchildren()[1].text
|
||||||
|
idt = tr.getchildren()[0].getchildren()[1].getchildren()[1].attrib.get('href','').replace('/','').replace('.html','')
|
||||||
|
url = tr.getchildren()[0].getchildren()[0].getchildren()[0].getchildren()[0].attrib.get('href','')
|
||||||
|
size = tr.getchildren()[1].text
|
||||||
|
u = size[-2:]
|
||||||
|
size = size = size[:-3].replace(',','.')
|
||||||
|
size = float(size)
|
||||||
|
seed = tr.getchildren()[4].text
|
||||||
|
leech = tr.getchildren()[5].text
|
||||||
|
|
||||||
|
torrent = Torrent(idt,
|
||||||
|
title,
|
||||||
|
url=url,
|
||||||
|
size=self.unit(size,u),
|
||||||
|
seeders=int(seed),
|
||||||
|
leechers=int(leech))
|
||||||
|
yield torrent
|
||||||
|
|
||||||
|
class TorrentPage(BasePage):
|
||||||
|
def get_torrent(self, id):
|
||||||
|
for div in self.document.getiterator('div'):
|
||||||
|
if div.attrib.get('id','') == 'title':
|
||||||
|
title = div.text.strip()
|
||||||
|
elif div.attrib.get('class','') == 'download':
|
||||||
|
url = div.getchildren()[0].attrib.get('href','')
|
||||||
|
elif div.attrib.get('id','') == 'details':
|
||||||
|
size = float(div.getchildren()[0].getchildren()[5].text.split('(')[1].split('Bytes')[0])
|
||||||
|
if len(div.getchildren()) > 1 \
|
||||||
|
and div.getchildren()[1].attrib.get('class','') == 'col2' :
|
||||||
|
seed = div.getchildren()[1].getchildren()[7].text
|
||||||
|
leech = div.getchildren()[1].getchildren()[9].text
|
||||||
|
else:
|
||||||
|
seed = div.getchildren()[0].getchildren()[24].text
|
||||||
|
leech = div.getchildren()[0].getchildren()[26].text
|
||||||
|
elif div.attrib.get('class','') == 'nfo':
|
||||||
|
description = div.getchildren()[0].text
|
||||||
|
torrent = Torrent(id, title)
|
||||||
|
torrent.url = url
|
||||||
|
torrent.size = size
|
||||||
|
torrent.seeders = int(seed)
|
||||||
|
torrent.leechers = int(leech)
|
||||||
|
torrent.description = description
|
||||||
|
torrent.files = ['NYI']
|
||||||
|
|
||||||
|
return torrent
|
||||||
26
weboob/backends/kickass/test.py
Normal file
26
weboob/backends/kickass/test.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright(C) 2010 Julien Veyssier
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, version 3 of the License.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
from weboob.tools.test import BackendTest
|
||||||
|
|
||||||
|
class KickassTest(BackendTest):
|
||||||
|
BACKEND = 'kickass'
|
||||||
|
|
||||||
|
def test_torrent(self):
|
||||||
|
l = list(self.backend.iter_torrents('debian'))
|
||||||
|
if len(l) > 0:
|
||||||
|
self.backend.get_torrent_file(l[0].id)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue