diff options
Diffstat (limited to 'travnik.py')
-rw-r--r-- | travnik.py | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -13,6 +13,7 @@ class Torrent(): self.sha1 = b'' self.files = {} self.type = Type.UNDEF + self.cache = None def file(self, f): self.parse(open(f, "rb").read()) def parse(self, b): @@ -25,7 +26,7 @@ class Torrent(): if b'files' in self.dict.get(b'info').keys(): self.type = Type.V1 for file in self.dict.get(b'info').get(b'files'): - if file.get(b'attr') is not None and b'p' in file.get(b'attr') or b'padding.file' in b'/'.join(file.get(b'path')) or b'.pad' in file.get(b'path'): + if file.get(b'attr') is not None and b'p' in file.get(b'attr') or b'padding.file' in b'/'.join(file.get(b'path')) or b'.pad' in file.get(b'path') or b'_____padding_file_' in b'/'.join(file.get(b'path')): continue def insert_file(d, path, length, self): name = path.pop() @@ -74,23 +75,37 @@ class Torrent(): yield z, v for z, v in paths_r(self.files): yield z, v - def matches(self, r): + def matches(self, r, cache=False): + does = False + if cache and self.cache: + return search(r, self.cache, 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") except AttributeError: decoded = str(self.dict.get(b'info').get(b'name')) + if search(r, self.dict.get(b'source').get(b'ip').decode(), IGNORECASE): + does = True + if not cache: + return True if search(r, decoded, IGNORECASE): - return True + does = True + if not cache: + return True + if cache: + self.cache = self.dict.get(b'source').get(b'ip').decode() + "|" + decoded + "|" for path, size in self.paths(): try: decd = b'/'.join(path).decode() except UnicodeDecodeError: decd = b'/'.join(path).decode("iso-8859-2") + self.cache += decd + "|" if search(r, decd, IGNORECASE): - return True - return False + does = True + if not cache: + return True + return does def matching_files(self, r, decode=False): def matching_files_r(dirc, r, decode): files = {} |