mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-17 05:47:50 +00:00
Multiple Magnet links support in autoadd plugin
This commit is contained in:
parent
6f77703e29
commit
8452b63d19
@ -182,6 +182,37 @@ class Core(CorePluginBase):
|
|||||||
|
|
||||||
return filedump
|
return filedump
|
||||||
|
|
||||||
|
def split_magnets(self, filename):
|
||||||
|
log.debug("Attempting to open %s for splitting magnets.", filename)
|
||||||
|
try:
|
||||||
|
_file = open(filename, "r")
|
||||||
|
except IOError, e:
|
||||||
|
log.warning("Unable to open %s: %s", filename, e)
|
||||||
|
raise e
|
||||||
|
else:
|
||||||
|
magnets = list(filter(len, _file.readlines()))
|
||||||
|
_file.close()
|
||||||
|
if len(magnets) < 2:
|
||||||
|
return
|
||||||
|
n = 0
|
||||||
|
path = filename.rsplit(os.sep, 1)[0]
|
||||||
|
for magnet in magnets:
|
||||||
|
for part in magnet.split('&'):
|
||||||
|
if part.startswith("dn="):
|
||||||
|
mname = os.sep.join([path, part[3:] + ".magnet"])
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
mname = '.'.join([filename, str(n), "magnet"])
|
||||||
|
n += 1
|
||||||
|
try:
|
||||||
|
_mfile = open(mname, "w")
|
||||||
|
except IOError, e:
|
||||||
|
log.warning("Unable to open %s: %s", mname, e)
|
||||||
|
else:
|
||||||
|
_mfile.write(magnet)
|
||||||
|
_mfile.close()
|
||||||
|
return magnets
|
||||||
|
|
||||||
def update_watchdir(self, watchdir_id):
|
def update_watchdir(self, watchdir_id):
|
||||||
"""Check the watch folder for new torrents to add."""
|
"""Check the watch folder for new torrents to add."""
|
||||||
log.trace("Updating watchdir id: %s", watchdir_id)
|
log.trace("Updating watchdir id: %s", watchdir_id)
|
||||||
@ -209,6 +240,23 @@ class Core(CorePluginBase):
|
|||||||
if OPTIONS_AVAILABLE.get(option):
|
if OPTIONS_AVAILABLE.get(option):
|
||||||
if watchdir.get(option+'_toggle', True):
|
if watchdir.get(option+'_toggle', True):
|
||||||
opts[option] = value
|
opts[option] = value
|
||||||
|
|
||||||
|
# Check for .magnet files containing multiple magnet links and
|
||||||
|
# create a new .magnet file for each of them.
|
||||||
|
for filename in os.listdir(watchdir["abspath"]):
|
||||||
|
try:
|
||||||
|
filepath = os.path.join(watchdir["abspath"], filename)
|
||||||
|
except UnicodeDecodeError, e:
|
||||||
|
log.error("Unable to auto add torrent due to improper "
|
||||||
|
"filename encoding: %s", e)
|
||||||
|
continue
|
||||||
|
if os.path.isdir(filepath):
|
||||||
|
# Skip directories
|
||||||
|
continue
|
||||||
|
elif os.path.splitext(filename)[1] == ".magnet" and \
|
||||||
|
self.split_magnets(filepath):
|
||||||
|
os.remove(filepath)
|
||||||
|
|
||||||
for filename in os.listdir(watchdir["abspath"]):
|
for filename in os.listdir(watchdir["abspath"]):
|
||||||
try:
|
try:
|
||||||
filepath = os.path.join(watchdir["abspath"], filename)
|
filepath = os.path.join(watchdir["abspath"], filename)
|
||||||
|
@ -43,7 +43,7 @@ from setuptools import setup, find_packages
|
|||||||
__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.02"
|
__version__ = "1.04"
|
||||||
__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…
x
Reference in New Issue
Block a user