rewritten weboorrents
This commit is contained in:
parent
a6c0636eb4
commit
e908d862c8
1 changed files with 23 additions and 38 deletions
|
|
@ -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 <backend>.<ID>')
|
||||
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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue