Commit 8b181c6c authored by jvoisin's avatar jvoisin

Improves the way torrents are handled

This commit makes metadata removal of torrents recursive.
It's close to useless, because I haven't seen any torrent with a
recursive structure, but the documentation says that it can happen, and
the method was already implemented, so better safe than sorry.
parent 80ece300
......@@ -54,8 +54,10 @@ class TorrentStripper(parser.GenericParser):
""" Remove recursively all compromizing fields
d = dict()
for i, j in [i for i in list(dictionary.items()) if i in self.fields]:
if isinstance(j, dict):
for i, j in list(dictionary.items()):
if not i in self.fields:
elif isinstance(j, dict):
d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items()))
d[i] = j
......@@ -67,7 +69,7 @@ class TorrentStripper(parser.GenericParser):
with open(self.filename, 'r') as f:
decoded = bencode.bdecode(
cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields}
cleaned = self.__remove_all_recursively(decoded)
with open(self.output, 'w') as f: # encode the decoded torrent
f.write(bencode.bencode(cleaned)) # and write it in self.output
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment