diff options
| author | jvoisin | 2015-12-02 17:40:05 +0100 |
|---|---|---|
| committer | jvoisin | 2015-12-02 17:40:05 +0100 |
| commit | 8b181c6ca5c6fc699efbd6ff3f68e87401ae8ab5 (patch) | |
| tree | 405349a2ca79597c0e996c11376aa1da88bc1ecc /libmat/misc.py | |
| parent | 80ece3001895ea13d50915a5215fd47e313bab4c (diff) | |
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.
Diffstat (limited to 'libmat/misc.py')
| -rw-r--r-- | libmat/misc.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libmat/misc.py b/libmat/misc.py index cc480e5..e5db06d 100644 --- a/libmat/misc.py +++ b/libmat/misc.py | |||
| @@ -54,8 +54,10 @@ class TorrentStripper(parser.GenericParser): | |||
| 54 | """ Remove recursively all compromizing fields | 54 | """ Remove recursively all compromizing fields |
| 55 | """ | 55 | """ |
| 56 | d = dict() | 56 | d = dict() |
| 57 | for i, j in [i for i in list(dictionary.items()) if i in self.fields]: | 57 | for i, j in list(dictionary.items()): |
| 58 | if isinstance(j, dict): | 58 | if not i in self.fields: |
| 59 | continue | ||
| 60 | elif isinstance(j, dict): | ||
| 59 | d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items())) | 61 | d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items())) |
| 60 | else: | 62 | else: |
| 61 | d[i] = j | 63 | d[i] = j |
| @@ -67,7 +69,7 @@ class TorrentStripper(parser.GenericParser): | |||
| 67 | with open(self.filename, 'r') as f: | 69 | with open(self.filename, 'r') as f: |
| 68 | decoded = bencode.bdecode(f.read()) | 70 | decoded = bencode.bdecode(f.read()) |
| 69 | 71 | ||
| 70 | cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields} | 72 | cleaned = self.__remove_all_recursively(decoded) |
| 71 | 73 | ||
| 72 | with open(self.output, 'w') as f: # encode the decoded torrent | 74 | with open(self.output, 'w') as f: # encode the decoded torrent |
| 73 | f.write(bencode.bencode(cleaned)) # and write it in self.output | 75 | f.write(bencode.bencode(cleaned)) # and write it in self.output |
