diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2023-02-21 16:48:59 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2023-02-21 16:48:59 +0100 |
commit | e791103cbbecbec2a87e9d1ab643ccb4fa36e311 (patch) | |
tree | f888ac0391bbccecf6b2ae621202a04908dc100a /travnik.py | |
parent | nekončano, začenjam webapp (diff) | |
download | travnik-e791103cbbecbec2a87e9d1ab643ccb4fa36e311.tar travnik-e791103cbbecbec2a87e9d1ab643ccb4fa36e311.tar.gz travnik-e791103cbbecbec2a87e9d1ab643ccb4fa36e311.tar.bz2 travnik-e791103cbbecbec2a87e9d1ab643ccb4fa36e311.tar.lz travnik-e791103cbbecbec2a87e9d1ab643ccb4fa36e311.tar.xz travnik-e791103cbbecbec2a87e9d1ab643ccb4fa36e311.tar.zst travnik-e791103cbbecbec2a87e9d1ab643ccb4fa36e311.zip |
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): |