move obj_to_filename() into ReplApplication and use it in weboorrents

This commit is contained in:
Romain Bignon 2014-01-16 23:56:42 +01:00
commit d2b9a0a2d2
3 changed files with 38 additions and 22 deletions

View file

@ -140,13 +140,15 @@ class Weboorrents(ReplApplication):
"""
id, dest = self.parse_command_args(line, 2, 1)
_id, backend_name = self.parse_id(id)
torrent = self.get_object(id, 'get_torrent', ('description', 'files'))
if not torrent:
print >>sys.stderr, 'Torrent not found: %s' % id
return 3
if dest is None:
dest = '%s.torrent' % _id
dest = self.obj_to_filename(torrent, dest, '{id}-{name}.torrent')
try:
for backend, buf in self.do('get_torrent_file', _id, backends=backend_name):
for backend, buf in self.do('get_torrent_file', torrent.id, backends=torrent.backend):
if buf:
if dest == '-':
print buf