def check_if_matched(name, torrent_path): with open(torrent_path, 'rb') as fh: torrent_data = fh.read() torrent = my_bencode.decode(torrent_data) info = torrent[0][b'info'] file_dir = info[b'name'].decode('utf-8') if file_dir == name: return True else: return False
def check_for_file_exists(torrent_path, file_path): with open(torrent_path, 'rb') as fh: torrent_data = fh.read() torrent = my_bencode.decode(torrent_data) info = torrent[0][b'info'] if b'files' in info.keys(): files = info[b'files'] for file in files: new_path = [] for path in file[b'path']: new_path.append(path.decode('utf-8')) append_file_path = '\\'.join(new_path) new_file_path = file_path + '\\' + append_file_path # print(new_file_path) if not os.path.exists(new_file_path): return False else: if os.path.exists(file_path): return True return True
def parser_torrent(file_path): with open(file_path, 'rb') as fh: torrent_data = fh.read() torrent = my_bencode.decode(torrent_data) info = torrent[0][b'info'] file_dir = info[b'name'].decode('utf-8') if b'files' in info.keys(): biggest = 0 file_path = '' files = info[b'files'] for file in files: new_path = [] if file[b'length'] > biggest: for path in file[b'path']: new_path.append(path.decode('utf-8')) if new_path[-1].endswith( ('.mp4', '.mkv', '.avi', '.mov', '.rmvb', '.ts')): biggest = file[b'length'] file_path = '\\'.join(new_path) file_path = file_dir + '\\' + file_path return file_path else: return file_dir