command 'getfile' to store torrent in a file (or to stdout with '-')
This commit is contained in:
parent
bcc3079d41
commit
550fee93ba
3 changed files with 38 additions and 3 deletions
|
|
@ -53,5 +53,12 @@ class GazelleBackend(BaseBackend, ICapTorrent):
|
||||||
def get_torrent(self, id):
|
def get_torrent(self, id):
|
||||||
return self.browser.get_torrent(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).read()
|
||||||
|
|
||||||
def iter_torrents(self, pattern):
|
def iter_torrents(self, pattern):
|
||||||
return self.browser.iter_torrents(pattern)
|
return self.browser.iter_torrents(pattern)
|
||||||
|
|
|
||||||
|
|
@ -41,3 +41,6 @@ class ICapTorrent(ICap):
|
||||||
|
|
||||||
def get_torrent(self, _id):
|
def get_torrent(self, _id):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def get_torrent_file(self, _id):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
|
||||||
|
|
@ -35,16 +35,23 @@ class Weboorrents(ConsoleApplication):
|
||||||
self.load_backends(ICapTorrent)
|
self.load_backends(ICapTorrent)
|
||||||
return self.process_command(*argv[1:])
|
return self.process_command(*argv[1:])
|
||||||
|
|
||||||
@ConsoleApplication.command('Get information about a torrent')
|
def split_id(self, id):
|
||||||
def command_info(self, id):
|
|
||||||
if not '.' in id:
|
if not '.' in id:
|
||||||
print >>sys.stderr, 'ID must be in form <backend>.<ID>'
|
print >>sys.stderr, 'ID must be in form <backend>.<ID>'
|
||||||
return 1
|
return None, None
|
||||||
|
|
||||||
backend_name, id = id.split('.', 1)
|
backend_name, id = id.split('.', 1)
|
||||||
backend = self.weboob.backends.get(backend_name, None)
|
backend = self.weboob.backends.get(backend_name, None)
|
||||||
if not backend:
|
if not backend:
|
||||||
print >>sys.stderr, 'Backends "%s" not found' % backend_name
|
print >>sys.stderr, '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
|
return 1
|
||||||
|
|
||||||
with backend:
|
with backend:
|
||||||
|
|
@ -66,6 +73,24 @@ class Weboorrents(ConsoleApplication):
|
||||||
rows.append(('Files', '\n'.join(torrent.files)))
|
rows.append(('Files', '\n'.join(torrent.files)))
|
||||||
return {backend.name: rows}
|
return {backend.name: rows}
|
||||||
|
|
||||||
|
@ConsoleApplication.command('Get the torrent file')
|
||||||
|
def command_getfile(self, id, dest):
|
||||||
|
backend, id = self.split_id(id)
|
||||||
|
if not backend:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
with backend:
|
||||||
|
s = backend.get_torrent_file(id)
|
||||||
|
if not s:
|
||||||
|
print >>sys.stderr, 'Torrent "%s" not found' % id
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if dest == '-':
|
||||||
|
print s
|
||||||
|
else:
|
||||||
|
with open(dest, 'w') as f:
|
||||||
|
f.write(s)
|
||||||
|
|
||||||
@ConsoleApplication.command('Search torrents')
|
@ConsoleApplication.command('Search torrents')
|
||||||
def command_search(self, pattern=None):
|
def command_search(self, pattern=None):
|
||||||
results = {}
|
results = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue