def replace_invalid_chars(name):
invalid_chars = ['/', '\', ':', '*', '?', '"', '<', '>', '|']
for char in invalid_chars:
if char in name:
name = name.replace(char, " ")
return name
for xm_file in xm_files:
print(f"正在解密文件: {xm_file}")
aac_file = decrypt_xm_file_to_aac(xm_file, output_path)
aac_files.append(aac_file)
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
futures = []
for aac_file in aac_files:
mp3_file = aac_file.replace(".aac", ".mp3")
futures.append(executor.submit(convert_to_mp3_in_thread, aac_file, mp3_file, '24k'))
for future in concurrent.futures.as_completed(futures):
print("文件转换完成:", future.result())
def get_output_path():
print("请选择是否需要设置输出路径:(不设置默认为本程序目录下的output文件夹)")
print("1. 设置输出路径")
print("2. 不设置输出路径")
choice = input()
if choice == "1":
print("请输入输出路径:")
output_path = input()
if not os.path.exists(output_path):
os.makedirs(output_path)
return output_path
else:
return "./output"
if name == "main":
while True:
print("欢迎使用喜马拉雅音频解密工具")
print("本工具仅供学习交流使用,严禁用于商业用途")
print("请选择您想要使用的功能:")
print("1. 解密单个文件")
print("2. 批量解密文件")
print("3. 退出")
choice = input()
if choice == "1":
print("请输入需要解密的文件路径:")
file_to_decrypt = input()
if os.path.exists(file_to_decrypt) and os.path.isfile(file_to_decrypt):
output_path = get_output_path()
decrypt_xm_file_to_aac(file_to_decrypt, output_path)
else:
print("您输入的不是一个有效的文件路径,请重新输入!")
elif choice == "2":
print("请输入包含需要解密的文件的文件夹路径:")
dir_to_decrypt = input()
if os.path.exists(dir_to_decrypt) and os.path.isdir(dir_to_decrypt):
output_path = get_output_path()
batch_decrypt_and_convert(dir_to_decrypt, output_path)
else:
print("您输入的不是一个有效的文件夹路径,请重新输入!")
elif choice == "3":
print("退出程序。")
sys.exit()
else:
print("输入错误,请重新输入!")
import base64 import concurrent.futures import glob import io import os import pathlib import subprocess import sys import mutagen from Crypto.Cipher import AES from Crypto.Util.Padding import pad from mutagen.easyid3 import ID3 from wasmer import Store, Module, Instance, Uint8Array, Int32Array, engine from wasmer_compiler_cranelift import Compiler
class XMInfo: def init(self): self.title = "" self.artist = "" self.album = "" self.tracknumber = 0 self.size = 0 self.header_size = 0 self.ISRC = "" self.encodedby = "" self.encoding_technology = ""
def get_str(x): if x is None: return "" return x
def read_file(x): with open(x, "rb") as f: return f.read()
return number of id3 bytes
def get_xm_info(data: bytes):
print(EasyID3(io.BytesIO(data)))
def get_printable_count(x: bytes): i = 0 for i, c in enumerate(x):
all pritable
def get_printable_bytes(x: bytes): return x[:get_printable_count(x)]
def xm_decrypt(raw_data):
load xm encryptor
def replace_invalid_chars(name): invalid_chars = ['/', '\', ':', '*', '?', '"', '<', '>', '|'] for char in invalid_chars: if char in name: name = name.replace(char, " ") return name
def convert_to_mp3(input_file, output_file, bitrate='24k'): command = ['ffmpeg', '-i', input_file, '-acodec', 'libmp3lame', '-b:a', bitrate, output_file] subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def decrypt_xm_file_to_aac(from_file, output_path='./output'): data = read_file(from_file) info, audio_data = xm_decrypt(data)
def convert_to_mp3_in_thread(aac_file, mp3_file, bitrate='24k'): convert_to_mp3(aac_file, mp3_file, bitrate) os.remove(aac_file) # 删除临时AAC文件
def batch_decrypt_and_convert(directory, output_path='./output'): xm_files = glob.glob(os.path.join(directory, "*.xm")) aac_files = []
def get_output_path(): print("请选择是否需要设置输出路径:(不设置默认为本程序目录下的output文件夹)") print("1. 设置输出路径") print("2. 不设置输出路径") choice = input() if choice == "1": print("请输入输出路径:") output_path = input() if not os.path.exists(output_path): os.makedirs(output_path) return output_path else: return "./output"
if name == "main": while True: print("欢迎使用喜马拉雅音频解密工具") print("本工具仅供学习交流使用,严禁用于商业用途") print("请选择您想要使用的功能:") print("1. 解密单个文件") print("2. 批量解密文件") print("3. 退出") choice = input() if choice == "1": print("请输入需要解密的文件路径:") file_to_decrypt = input() if os.path.exists(file_to_decrypt) and os.path.isfile(file_to_decrypt): output_path = get_output_path() decrypt_xm_file_to_aac(file_to_decrypt, output_path) else: print("您输入的不是一个有效的文件路径,请重新输入!") elif choice == "2": print("请输入包含需要解密的文件的文件夹路径:") dir_to_decrypt = input() if os.path.exists(dir_to_decrypt) and os.path.isdir(dir_to_decrypt): output_path = get_output_path() batch_decrypt_and_convert(dir_to_decrypt, output_path) else: print("您输入的不是一个有效的文件夹路径,请重新输入!") elif choice == "3": print("退出程序。") sys.exit() else: print("输入错误,请重新输入!")