python网易云ncm转mp3

gayhub上看到一个很叼很实用的脚本,可将ncm格式的音乐转为mp3,记录一下,放上大佬传送门:
https://github.com/lianglixin/ncmdump

依赖pycrypto
pip(3) install pycrypto

直接贴代码:

import binascii
import struct
import base64
import json
import os
from Crypto.Cipher import AES


def dump(file_path):
    core_key = binascii.a2b_hex("687A4852416D736F356B496E62617857")
    meta_key = binascii.a2b_hex("2331346C6A6B5F215C5D2630553C2728")
    unpad = lambda s : s[0:-(s[-1] if type(s[-1]) == int else ord(s[-1]))]
    f = open(file_path,'rb')
    header = f.read(8)
    assert binascii.b2a_hex(header) == b'4354454e4644414d'
    f.seek(2, 1)
    key_length = f.read(4)
    key_length = struct.unpack('= key_length: key_offset = 0
        key_box[i] = key_box[c]
        key_box[c] = swap
        last_byte = c
    meta_length = f.read(4)
    meta_length = struct.unpack(' 1:
    #     for file_path in sys.argv[1:]:
    #         try:
    #             dump(file_path)
    #         except:
    #             pass
    # else:
    #     print("Usage: python ncmTransfer.py \"File Name\"")

    try:
        print(os.getcwd())
        file_name(os.getcwd())
    except:
        print('不成')

把.py文件直接放到包含ncm歌曲的目录中,执行脚本就会把该目录下所有ncm歌曲转换为mp3

你可能感兴趣的:(python网易云ncm转mp3)