From e908d862c89cbd46e9c973ba782d1bf99022711c Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Wed, 30 Jun 2010 23:42:17 +0200 Subject: [PATCH] rewritten weboorrents --- weboob/frontends/weboorrents/weboorrents.py | 57 ++++++++------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/weboob/frontends/weboorrents/weboorrents.py b/weboob/frontends/weboorrents/weboorrents.py index 0f27d053..64f09d2f 100644 --- a/weboob/frontends/weboorrents/weboorrents.py +++ b/weboob/frontends/weboorrents/weboorrents.py @@ -17,7 +17,7 @@ from __future__ import with_statement -import logging +import sys from weboob.capabilities.torrent import ICapTorrent from weboob.tools.application import ConsoleApplication @@ -36,48 +36,33 @@ class Weboorrents(ConsoleApplication): self.load_backends(ICapTorrent) return self.process_command(*argv[1:]) - def split_id(self, id): - if not '.' in id: - logging.error('ID must be in form .') - return None, None - - backend_name, id = id.split('.', 1) - backend = self.weboob.backends.get(backend_name, None) - if not backend: - logging.error('Backends "%s" not found' % backend_name) - return None, None - - return backend, id - @ConsoleApplication.command('Get information about a torrent') def command_info(self, id): - backend, id = self.split_id(id) - if not backend: - return 1 - with backend: - torrent = backend.get_torrent(id) - if not torrent: - logging.error('Torrent "%s" not found' % id) - return 1 - self.format(torrent, backend.name) + _id, backend_name = self.parse_id(id) + + found = 0 + for backend, torrent in self.weboob.do_backends(backend_name, 'get_torrent', _id): + if torrent: + self.format(torrent, backend.name) + found = 1 + + if not found: + print >>sys.stderr, 'Torrent "%s" not found' % id @ConsoleApplication.command('Get the torrent file') def command_getfile(self, id, dest): - backend, id = self.split_id(id) - if not backend: - return 1 + _id, backend_name = self.parse_id(id) - with backend: - s = backend.get_torrent_file(id) - if not s: - logging.error('Torrent "%s" not found' % id) - return 1 + for backend, buf in self.weboob.do_backends(backend_name, 'get_torrent_file', _id): + if buf: + if dest == '-': + print buf + else: + with open(dest, 'w') as f: + f.write(buf) + return - if dest == '-': - print s - else: - with open(dest, 'w') as f: - f.write(s) + print >>sys.stderr, 'Torrent "%s" not found' % id @ConsoleApplication.command('Search torrents') def command_search(self, pattern=None):