Support magnet URLs in weboorents
This commit is contained in:
parent
f8843084f0
commit
ee04a92f04
2 changed files with 30 additions and 13 deletions
|
|
@ -21,9 +21,10 @@ from __future__ import with_statement
|
|||
|
||||
import sys
|
||||
|
||||
from weboob.capabilities.torrent import ICapTorrent
|
||||
from weboob.capabilities.torrent import ICapTorrent, MagnetOnly
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter
|
||||
from weboob.core import CallErrors
|
||||
|
||||
|
||||
__all__ = ['Weboorrents']
|
||||
|
|
@ -142,6 +143,7 @@ class Weboorrents(ReplApplication):
|
|||
if dest is None:
|
||||
dest = '%s.torrent' % _id
|
||||
|
||||
try:
|
||||
for backend, buf in self.do('get_torrent_file', _id, backends=backend_name):
|
||||
if buf:
|
||||
if dest == '-':
|
||||
|
|
@ -154,6 +156,15 @@ class Weboorrents(ReplApplication):
|
|||
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
|
||||
return 1
|
||||
return
|
||||
except CallErrors, errors:
|
||||
for backend, error, backtrace in errors:
|
||||
if isinstance(error, MagnetOnly):
|
||||
print >>sys.stderr, u'Error(%s): No direct URL available, ' \
|
||||
u'please provide this magnet URL ' \
|
||||
u'to your client:\n%s' % (backend, error.magnet)
|
||||
return 4
|
||||
else:
|
||||
self.bcall_error_handler(backend, error, backtrace)
|
||||
|
||||
print >>sys.stderr, 'Torrent "%s" not found' % id
|
||||
return 3
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ from .base import IBaseCap, CapBaseObject
|
|||
__all__ = ['ICapTorrent', 'Torrent']
|
||||
|
||||
|
||||
class MagnetOnly(Exception):
|
||||
def __init__(self, magnet):
|
||||
self.magnet = magnet
|
||||
Exception.__init__(self, 'Only magnet URL is available')
|
||||
|
||||
|
||||
class Torrent(CapBaseObject):
|
||||
def __init__(self, id, name):
|
||||
CapBaseObject.__init__(self, id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue