import os

def calculate_ed2k(): directory = input("请输入目录路径:") if not os.path.isdir(directory): print("目录不存在!") return for filename in os.listdir(directory): if not os.path.isfile(os.path.join(directory, filename)): continue filesize = os.path.getsize(os.path.join(directory, filename)) ed2k_hash = calculate_hash(os.path.join(directory, filename)) ed2k_link = "ed2k://|file|{}|{}|{}|h={}|/".format(filename, filesize, ed2k_hash, calculate_aich(ed2k_hash)) print(ed2k_link)

def calculate_hash(filepath): BLOCKSIZE = 9728000 hasher = hashlib.md5() with open(filepath, 'rb') as file: buf = file.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = file.read(BLOCKSIZE) return hasher.hexdigest()

def calculate_aich(ed2k_hash): BLOCKSIZE = 9728000 hasher = hashlib.sha1() hasher.update(ed2k_hash.encode('utf-8')) buf = hasher.digest() while len(buf) > 16: hasher = hashlib.sha1() hasher.update(buf) buf = hasher.digest() return buf.hex()

if name == 'main': calculate_ed2k()

用python3编写一个批量计算目录下文件ed2k的脚本格式为ed2kfile文件名文件大小ed2k_hashh=ed2k_aich

原文地址: https://www.cveoy.top/t/topic/bbMv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录