diff options
Diffstat (limited to 'travnik.py')
-rw-r--r-- | travnik.py | 34 |
1 files changed, 23 insertions, 11 deletions
@@ -75,24 +75,36 @@ class Torrent(): for z, v in paths_r(self.files): yield z, v def matches(self, r): - if search(r, self.dict.get(b'info').get(b'name'), IGNORECASE): + try: + decoded = self.dict.get(b'info').get(b'name').decode() + except UnicodeDecodeError: + decoded = self.dict.get(b'info').get(b'name').decode("iso-8859-2") + if search(r, decoded, IGNORECASE): return True - for path, size in paths(self): - if search(r, path, IGNORECASE): + for path, size in self.paths(): + try: + decd = b'/'.join(path).decode() + except UnicodeDecodeError: + decd = b'/'.join(path).decode("iso-8859-2") + if search(r, decd, IGNORECASE): return True return False - def matching_files(self, r): - def matching_files_r(dir, r): + def matching_files(self, r, decode=False): + def matching_files_r(dirc, r, decode): files = {} - for name, content in self.paths: - if search(r, name, IGNORECASE): - files[name] = content + for name, content in dirc.items(): + try: + decoded = name.decode() + except UnicodeDecodeError: + decoded = name.decode("iso-8859-2") # TODO we could try detecting the encoding + if search(r, decoded, IGNORECASE): + files[decoded if decode else name] = content if type(content) is dict: - inhalt = matching_files_r(content, r) + inhalt = matching_files_r(content, r, decode) if inhalt: - files[name] = inhalt + files[decoded if decode else name] = inhalt return files - return matching_files_r(self.paths, r) + return matching_files_r(self.files, r, decode) def __repr__(self): return str(self.__dict__) def __hash__(self): |