【原创源码】【python】网易云音乐缓存.uc转化MP3
如题,Python实现的将网易云的缓存文件.uc转化为MP3格式,解密.uc格式的方法是将每个字节跟0xA3异或。import os
def get_path_dfs_helper(path_collect_list: list, input_path: str, deep: int):
if not os.path.exists(input_path):
print(f'目录不存在:{input_path}')
return
if deep > 10:
return
if os.path.isfile(input_path):
path_collect_list.append(input_path)
return
files = os.listdir(input_path)
for file in files:
f_abs = os.path.join(input_path, file)
get_path_dfs_helper(path_collect_list, f_abs, deep + 1)
pass
def convert_uc_to_mp3(input_dir: str, output_dir: str):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
cache_file_list = []
get_path_dfs_helper(cache_file_list, input_dir, 0)
for f in cache_file_list:
if not f.endswith('.uc'):
continue
file_name = os.path.basename(f)
print(f'文件:{os.path.basename(f)}-->{os.path.getsize(f)}字节')
with open(f, mode='rb+') as fr:
data_bytes = fr.read()
file_name = file_name[:-3] + '.mp3'
output_file_abs_path = os.path.join(output_dir, file_name)
if os.path.exists(output_file_abs_path):
continue
with open(output_file_abs_path, 'wb+') as fw:
convert_list = list()
for data in data_bytes:
result = data ^ 0xA3
convert_list.append(result)
fw.write(bytes(convert_list))
pass
def test_function():
input_cache_dir = r'F:\99.OtherSoftwareCache\Netease\CloudmusicCache\Cache'
output_dir = r'F:\99.OtherSoftwareCache\ConvertToMp3'
convert_uc_to_mp3(input_cache_dir, output_dir)
pass
if __name__ == '__main__':
test_function()
pass 算不算改进了一下
import os
import shutil
def get_file_paths(input_path):
file_paths = []
for root, _, files in os.walk(input_path):
for file in files:
file_paths.append(os.path.join(root, file))
return file_paths
def convert_uc_to_mp3(input_path, output_dir):
if not os.path.exists(input_path):
print(f'目录不存在: {input_path}')
return
if not os.path.exists(output_dir):
os.makedirs(output_dir)
file_paths = get_file_paths(input_path)
for file_path in file_paths:
if not file_path.endswith('.uc'):
continue
file_name = os.path.basename(file_path)
output_file_name = file_name[:-3] + '.mp3'
output_file_path = os.path.join(output_dir, output_file_name)
if os.path.exists(output_file_path):
continue
try:
with open(file_path, 'rb') as fr, open(output_file_path, 'wb') as fw:
while True:
data = fr.read(4096)
if not data:
break
converted_data = bytes()
fw.write(converted_data)
except Exception as e:
print(f'处理文件 {file_name} 时出错: {str(e)}')
def main():
input_cache_dir = r'F:\99.OtherSoftwareCache\Netease\CloudmusicCache\Cache'
output_dir = r'F:\99.OtherSoftwareCache\ConvertToMp3'
convert_uc_to_mp3(input_cache_dir, output_dir)
if __name__ == '__main__':
main()
感谢大佬分享,学习了,谢谢! 厉害,好好学习,天天成长! 这个加密方式这么原始的吗{:301_998:} 学习学习,感谢分享。 学习了,谢谢! 三滑稽甲苯 发表于 2023-8-18 09:55
这个加密方式这么原始的吗
就是这么原始,当初看别的帖子的时候我也惊呆了 自己试了下确实如此,论坛里还有网易云下载的ncm格式的解密 那个复杂多了 这种方式应该不是原声的吧 这个厉害了,省钱 感谢大佬分享