mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-04 15:38:43 +00:00
[AutoAdd] Fixes for adding magnets
* Combines three commits from 1.3-stable that fixed splitting magnets from file.b52de1549e
,8a3f15e5c0
,2d4dec669e
This commit is contained in:
parent
7e04abd1e5
commit
c8d084c563
3 changed files with 16 additions and 13 deletions
|
@ -334,7 +334,7 @@ class TorrentManager(component.Component):
|
||||||
elif magnet:
|
elif magnet:
|
||||||
magnet_info = get_magnet_info(magnet)
|
magnet_info = get_magnet_info(magnet)
|
||||||
if magnet_info:
|
if magnet_info:
|
||||||
add_torrent_params['url'] = magnet.encode('utf8')
|
add_torrent_params['url'] = magnet.strip().encode('utf8')
|
||||||
add_torrent_params['name'] = magnet_info['name']
|
add_torrent_params['name'] = magnet_info['name']
|
||||||
torrent_id = magnet_info['info_hash']
|
torrent_id = magnet_info['info_hash']
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -26,7 +26,7 @@ from twisted.internet.task import LoopingCall, deferLater
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
from deluge._libtorrent import lt
|
from deluge._libtorrent import lt
|
||||||
from deluge.common import AUTH_LEVEL_ADMIN
|
from deluge.common import AUTH_LEVEL_ADMIN, is_magnet
|
||||||
from deluge.core.rpcserver import export
|
from deluge.core.rpcserver import export
|
||||||
from deluge.event import DelugeEvent
|
from deluge.event import DelugeEvent
|
||||||
from deluge.plugins.pluginbase import CorePluginBase
|
from deluge.plugins.pluginbase import CorePluginBase
|
||||||
|
@ -172,26 +172,29 @@ class Core(CorePluginBase):
|
||||||
magnets = []
|
magnets = []
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r') as _file:
|
with open(filename, 'r') as _file:
|
||||||
for line in _file:
|
magnets = list(filter(len, _file.read().splitlines()))
|
||||||
line = line.strip()
|
|
||||||
if line:
|
|
||||||
magnets.append(line)
|
|
||||||
except IOError as ex:
|
except IOError as ex:
|
||||||
log.warning('Unable to open %s: %s', filename, ex)
|
log.warning('Unable to open %s: %s', filename, ex)
|
||||||
|
|
||||||
if len(magnets) < 2:
|
if len(magnets) < 2:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
n = 0
|
|
||||||
path = filename.rsplit(os.sep, 1)[0]
|
path = filename.rsplit(os.sep, 1)[0]
|
||||||
for magnet in magnets:
|
for magnet in magnets:
|
||||||
|
if not is_magnet(magnet):
|
||||||
|
log.warning('Found line which is not a magnet: %s', magnet)
|
||||||
|
continue
|
||||||
|
|
||||||
for part in magnet.split('&'):
|
for part in magnet.split('&'):
|
||||||
if part.startswith('dn='):
|
if part.startswith('dn='):
|
||||||
mname = os.sep.join([path, part[3:] + '.magnet'])
|
name = part[3:].strip()
|
||||||
break
|
if name:
|
||||||
|
mname = os.sep.join([path, name + '.magnet'])
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
mname = '.'.join([filename, str(n), 'magnet'])
|
short_hash = magnet.split('btih:')[1][:8]
|
||||||
n += 1
|
mname = '.'.join([os.path.splitext(filename)[0], short_hash, 'magnet'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(mname, 'w') as _mfile:
|
with open(mname, 'w') as _mfile:
|
||||||
_mfile.write(magnet)
|
_mfile.write(magnet)
|
||||||
|
@ -277,7 +280,7 @@ class Core(CorePluginBase):
|
||||||
# The torrent looks good, so lets add it to the session.
|
# The torrent looks good, so lets add it to the session.
|
||||||
if magnet:
|
if magnet:
|
||||||
torrent_id = component.get('Core').add_torrent_magnet(
|
torrent_id = component.get('Core').add_torrent_magnet(
|
||||||
filedump, options)
|
filedump.strip(), options)
|
||||||
else:
|
else:
|
||||||
torrent_id = component.get('Core').add_torrent_file(
|
torrent_id = component.get('Core').add_torrent_file(
|
||||||
filename, base64.encodestring(filedump), options)
|
filename, base64.encodestring(filedump), options)
|
||||||
|
|
|
@ -18,7 +18,7 @@ from setuptools import find_packages, setup
|
||||||
__plugin_name__ = 'AutoAdd'
|
__plugin_name__ = 'AutoAdd'
|
||||||
__author__ = 'Chase Sterling, Pedro Algarvio'
|
__author__ = 'Chase Sterling, Pedro Algarvio'
|
||||||
__author_email__ = 'chase.sterling@gmail.com, pedro@algarvio.me'
|
__author_email__ = 'chase.sterling@gmail.com, pedro@algarvio.me'
|
||||||
__version__ = '1.05'
|
__version__ = '1.06'
|
||||||
__url__ = 'http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd'
|
__url__ = 'http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd'
|
||||||
__license__ = 'GPLv3'
|
__license__ = 'GPLv3'
|
||||||
__description__ = 'Monitors folders for .torrent files.'
|
__description__ = 'Monitors folders for .torrent files.'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue