summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2017-02-14 18:32:53 +0000
committerCalum Lind <calumlind+deluge@gmail.com>2017-02-14 18:37:20 +0000
commit8a3f15e5c0a3fbd14840d6e6954dc4c1e07ddc6f (patch)
treefd643bd0febecabe8f4088513af7988182a31ad8
parent8565eccb3de9f5361ad6ae099a1e58a78f9d1e37 (diff)
downloaddeluge-8a3f15e5c0a3fbd14840d6e6954dc4c1e07ddc6f.tar.gz
deluge-8a3f15e5c0a3fbd14840d6e6954dc4c1e07ddc6f.tar.bz2
deluge-8a3f15e5c0a3fbd14840d6e6954dc4c1e07ddc6f.zip
[Autoadd] Fixes for splitting magnets from file
* use splitlines to remove line endings so filter with len works as intended. * use a short form of the magnet hash so the resulting filename will be unique and prevent potential overwriting of other files. * verify magnet is valid
-rw-r--r--deluge/plugins/autoadd/autoadd/core.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/deluge/plugins/autoadd/autoadd/core.py b/deluge/plugins/autoadd/autoadd/core.py
index f372075c8..53c557598 100644
--- a/deluge/plugins/autoadd/autoadd/core.py
+++ b/deluge/plugins/autoadd/autoadd/core.py
@@ -39,6 +39,7 @@
from deluge._libtorrent import lt
import os
+from deluge.common import is_magnet
from deluge.log import LOG as log
from deluge.plugins.pluginbase import CorePluginBase
import deluge.component as component
@@ -184,20 +185,23 @@ class Core(CorePluginBase):
log.warning("Unable to open %s: %s", filename, e)
raise e
else:
- magnets = list(filter(len, _file.readlines()))
+ magnets = list(filter(len, _file.read().splitlines()))
_file.close()
if len(magnets) < 2:
return
- n = 0
path = filename.rsplit(os.sep, 1)[0]
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('&'):
if part.startswith("dn="):
mname = os.sep.join([path, part[3:] + ".magnet"])
break
else:
- mname = '.'.join([filename, str(n), "magnet"])
- n += 1
+ short_hash = magnet.split("btih:")[1][:8]
+ mname = '.'.join([filename, short_hash, "magnet"])
try:
_mfile = open(mname, "w")
except IOError, e: