├── README.md └── ncmTranslator.py /README.md: -------------------------------------------------------------------------------- 1 | # ncmTranslatorScript_python 2 | 网易云音乐.ncm音乐格式转换python脚本 3 | 4 | 使用方法: 5 | 6 | 方法一: 7 | 1、将 ncmTranslator.py 脚本放到需要处理的文件夹下 8 | 2、执行 ./ncmTranslator.py 9 | 方法二: 10 | ./ncmTranslator.py {参数:指定要处理的绝对路径} 11 | 12 | ps:只在ubuntu下使用过, 使用的python3 13 | ps2: 顺便会下载专辑图片到音乐文件所在的路径 14 | 引用代码:https://github.com/lianglixin/ncmdump/blob/master/folder_dump.py 15 | 16 | 17 | 后台使用:nohup ./ncmTranslator.py > ./process.log 2>&1 & 18 | 后台使用的方法查看日志:tail -f process.log 19 | 20 | ## Star History 21 | 22 | ## Stargazers over time 23 | [![Star History](https://starchart.cc/waterkokoro/ncmTranslatorScript_python.svg?variant=light)](https://starchart.cc/waterkokoro/ncmTranslatorScript_python) 24 | 25 | -------------------------------------------------------------------------------- /ncmTranslator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # Modifier: Liang Lixin 3 | # Folder dump version by LiangLixin 4 | import binascii 5 | import struct 6 | import base64 7 | import json 8 | import os 9 | import logging 10 | import urllib 11 | import requests 12 | import time 13 | 14 | from Crypto.Cipher import AES 15 | 16 | music_suffix_list = ['mp3', 'wav', 'ape', 'flac', 'MP3', 'WAV', 'APE', 'FLAC'] 17 | def dump(file_path, file_name_no_suffix): 18 | core_key = binascii.a2b_hex("687A4852416D736F356B496E62617857") 19 | meta_key = binascii.a2b_hex("2331346C6A6B5F215C5D2630553C2728") 20 | unpad = lambda s : s[0:-(s[-1] if type(s[-1]) == int else ord(s[-1]))] 21 | f = open(file_path,'rb') 22 | header = f.read(8) 23 | assert binascii.b2a_hex(header) == b'4354454e4644414d' 24 | f.seek(2, 1) 25 | key_length = f.read(4) 26 | key_length = struct.unpack('= key_length: key_offset = 0 44 | key_box[i] = key_box[c] 45 | key_box[c] = swap 46 | last_byte = c 47 | meta_length = f.read(4) 48 | meta_length = struct.unpack('>>>>>>>>>>>>>>> 当前文件: ' + full_file) 114 | if file_extension(full_file) == ".ncm": 115 | # 校验文件存在同名 116 | if file_exist(file_name, file_list, root_dir): 117 | print('>>>>>>>>>>>>>>> 同名文件跳过: ' + full_file) 118 | return 119 | try: 120 | print('>>>>>>>>>>>>>>> 开始转码文件: ' + full_file) 121 | dump(full_file, file_no_extension(file_name)); 122 | print('>>>>>>>>>>>>>>> 转码文件成功: ' + full_file) 123 | except Exception as err: 124 | print('转码文件失败: ' + full_file + ' error: ' + err) 125 | else: 126 | print('>>>>>>>>>>>>>>> 非ncm文件, 跳过') 127 | elif os.path.isdir(full_file): 128 | print('>>>>>>>>>>>>>>> 处理当前文件夹内容: ' + full_file) 129 | list = os.listdir(full_file) 130 | for i in range(0, len(list)): 131 | recursion(list[i], full_file, list) 132 | if __name__ == '__main__': 133 | import sys 134 | if len(sys.argv) > 1: 135 | rootdir = sys.argv[1]; #如果有输入路径参数,取当前路径参数 136 | else: 137 | # 没写路径默认走当前文件夹 138 | rootdir = os.path.split(os.path.realpath(__file__))[0]; 139 | print('>>>>>>>>>>>>>>> 初始路径层级: ' + rootdir) 140 | list = os.listdir(rootdir) # Get all files in folder.is 141 | for i in range(0,len(list)): 142 | try: 143 | recursion(list[i], rootdir, list) 144 | except Exception as e: 145 | print('递归处理出现错误'); 146 | logging.exception(e) 147 | finally: 148 | pass 149 | 150 | print('全部文件处理完成 ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())); 151 | --------------------------------------------------------------------------------