simplify and factorize code, remove dead code, follow conventions, use new-style classes
This commit is contained in:
parent
55a1574df5
commit
f1b3264a67
28 changed files with 202 additions and 251 deletions
|
|
@ -31,10 +31,6 @@ class KickassBackend(BaseBackend, ICapTorrent):
|
|||
VERSION = '0.5'
|
||||
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):
|
||||
|
|
|
|||
|
|
@ -30,43 +30,19 @@ class KickassBrowser(BaseBrowser):
|
|||
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
|
||||
'http://fr.kickasstorrents.com/new/.*field=seeders&sorder=desc': TorrentsPage,
|
||||
'http://fr.kickasstorrents.com/.*.html': TorrentPage,
|
||||
}
|
||||
|
||||
def home(self):
|
||||
return self.location('http://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)
|
||||
|
|
|
|||
|
|
@ -16,28 +16,18 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.torrent import Torrent
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.tools.misc import get_bytes_size
|
||||
|
||||
|
||||
__all__ = ['TorrentsPage']
|
||||
|
||||
|
||||
class TorrentsPage(BasePage):
|
||||
def unit(self, n, u):
|
||||
m = {'bytes': 1,
|
||||
'KB': 1024,
|
||||
'MB': 1024*1024,
|
||||
'GB': 1024*1024*1024,
|
||||
'TB': 1024*1024*1024*1024,
|
||||
}
|
||||
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':
|
||||
if tr.attrib.get('class', '') == 'odd' or tr.attrib.get('class', '') == ' even':
|
||||
title = tr.getchildren()[0].getchildren()[1].getchildren()[1].text
|
||||
if not title:
|
||||
title = ''
|
||||
|
|
@ -46,78 +36,67 @@ class TorrentsPage(BasePage):
|
|||
title += red.text
|
||||
if red.tail:
|
||||
title += red.tail
|
||||
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','')
|
||||
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 = tr.getchildren()[1].getchildren()[0].text
|
||||
size = size = size.replace(',','.')
|
||||
size = size = size.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
|
||||
yield Torrent(idt,
|
||||
title,
|
||||
url=url,
|
||||
size=get_bytes_size(size, u),
|
||||
seeders=int(seed),
|
||||
leechers=int(leech))
|
||||
|
||||
|
||||
class TorrentPage(BasePage):
|
||||
def unit(self, n, u):
|
||||
m = {'bytes': 1,
|
||||
'KB': 1024,
|
||||
'MB': 1024*1024,
|
||||
'GB': 1024*1024*1024,
|
||||
'TB': 1024*1024*1024*1024,
|
||||
}
|
||||
return float(n*m[u])
|
||||
|
||||
def get_torrent(self, id):
|
||||
|
||||
seed = 0
|
||||
leech = 0
|
||||
description = "No description"
|
||||
description = 'No description'
|
||||
url = 'No Url found'
|
||||
for div in self.document.getiterator('div'):
|
||||
if div.attrib.get('id','') == 'desc':
|
||||
if div.attrib.get('id', '') == 'desc':
|
||||
description = div.text.strip()
|
||||
for ch in div.getchildren():
|
||||
if ch.tail != None:
|
||||
description += ' '+ch.tail.strip()
|
||||
if div.attrib.get('class','') == 'seedBlock':
|
||||
if div.attrib.get('class', '') == 'seedBlock':
|
||||
seed = int(div.getchildren()[1].text)
|
||||
if div.attrib.get('class','') == 'leechBlock':
|
||||
if div.attrib.get('class', '') == 'leechBlock':
|
||||
leech = int(div.getchildren()[1].text)
|
||||
|
||||
for h in self.document.getiterator('h1'):
|
||||
if h.attrib.get('class','') == 'torrentName':
|
||||
if h.attrib.get('class', '') == 'torrentName':
|
||||
title = h.getchildren()[0].getchildren()[0].text
|
||||
|
||||
for a in self.document.getiterator('a'):
|
||||
if ('Download' in a.attrib.get('title','')) and ('torrent file' in a.attrib.get('title','')):
|
||||
url = a.attrib.get('href','')
|
||||
if ('Download' in a.attrib.get('title', '')) and ('torrent file' in a.attrib.get('title', '')):
|
||||
url = a.attrib.get('href', '')
|
||||
|
||||
size = 0
|
||||
for span in self.document.getiterator('span'):
|
||||
if span.attrib.get('class','') == "folder" or span.attrib.get('class','') == "folderopen":
|
||||
if span.attrib.get('class', '') == 'folder' or span.attrib.get('class', '') == 'folderopen':
|
||||
size = span.getchildren()[1].tail
|
||||
u = span.getchildren()[2].text
|
||||
size = float(size.split(': ')[1].replace(',','.'))
|
||||
size = float(size.split(': ')[1].replace(',', '.'))
|
||||
|
||||
files = []
|
||||
for td in self.document.getiterator('td'):
|
||||
if td.attrib.get('class','') == 'torFileName':
|
||||
if td.attrib.get('class', '') == 'torFileName':
|
||||
files.append(td.text)
|
||||
|
||||
|
||||
torrent = Torrent(id, title)
|
||||
torrent = Torrent(id, title)
|
||||
torrent.url = url
|
||||
torrent.size = self.unit(size,u)
|
||||
torrent.size = get_bytes_size(size, u)
|
||||
torrent.seeders = int(seed)
|
||||
torrent.leechers = int(leech)
|
||||
torrent.description = description
|
||||
torrent.files = files
|
||||
|
||||
return torrent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue