[kickass] fill_torrent

[weboorrents] temporary modification to fully load torrent on 'info short_id'
This commit is contained in:
Julien Veyssier 2013-03-09 17:37:26 +01:00
commit aab3ea5741
3 changed files with 28 additions and 10 deletions

View file

@ -21,6 +21,7 @@
from weboob.capabilities.torrent import Torrent
from weboob.tools.browser import BasePage
from weboob.tools.misc import get_bytes_size
from weboob.capabilities.base import NotAvailable
__all__ = ['TorrentsPage']
@ -65,27 +66,29 @@ class TorrentsPage(BasePage):
class TorrentPage(BasePage):
def get_torrent(self, id):
title = ''
size = NotAvailable
url = 'https://isohunt.com/download/%s/%s.torrent' % (id, id)
for a in self.document.getiterator('a'):
if 'Search more torrents of' in a.attrib.get('title', ''):
title = a.tail
seed = -1
leech = -1
seed = NotAvailable
leech = NotAvailable
tip_id = "none"
for span in self.document.getiterator('span'):
if span.attrib.get('style', '') == 'color:green;' and ('ShowTip' in span.attrib.get('onmouseover', '')):
seed = span.tail.split(' ')[1]
seed = int(span.tail.split(' ')[1])
tip_id = span.attrib.get('onmouseover', '').split("'")[1]
for div in self.document.getiterator('div'):
# find the corresponding super tip which appears on super mouse hover!
if div.attrib.get('class', '') == 'dirs ydsf' and tip_id in div.attrib.get('id', ''):
leech = div.getchildren()[0].getchildren()[1].tail.split(' ')[2]
leech = int(div.getchildren()[0].getchildren()[1].tail.split(' ')[2])
# the <b> with the size in it doesn't have a distinction
# have to get it by higher
elif div.attrib.get('id', '') == 'torrent_details':
size = div.getchildren()[6].getchildren()[0].getchildren()[0].text
u = size[-2:]
size = float(size[:-3])
size = get_bytes_size(size, u)
# files and description (uploader's comment)
description = 'No description'
@ -115,9 +118,9 @@ class TorrentPage(BasePage):
torrent = Torrent(id, title)
torrent.url = url
torrent.size = get_bytes_size(size, u)
torrent.seeders = int(seed)
torrent.leechers = int(leech)
torrent.size = size
torrent.seeders = seed
torrent.leechers = leech
torrent.description = description
torrent.files = files
return torrent

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.torrent import ICapTorrent
from weboob.capabilities.torrent import ICapTorrent, Torrent
from weboob.tools.backend import BaseBackend
from .browser import KickassBrowser
@ -61,3 +61,12 @@ class KickassBackend(BaseBackend, ICapTorrent):
def iter_torrents(self, pattern):
return self.browser.iter_torrents(quote_plus(pattern.encode('utf-8')))
def fill_torrent(self, torrent, fields):
print "plpl"
if 'description' in fields or fields == None:
return self.get_torrent(torrent.id)
OBJECTS = {
Torrent:fill_torrent
}

View file

@ -95,8 +95,14 @@ class Weboorrents(ReplApplication):
Get information about a torrent.
"""
torrent = self.get_object(id, 'get_torrent')
# Following commented line could be better
#torrent = self.get_object(id, 'get_torrent', ('description','files'))
torrent = None
_id, backend = self.parse_id(id)
for _backend, result in self.do('get_torrent', _id, backends=backend, caps=ICapTorrent):
if result:
backend = _backend
torrent = result
if not torrent:
print >>sys.stderr, 'Torrent not found: %s' % id
return 3