当前位置: 移动技术网 > IT编程>脚本编程>Python > Python解密网易云音乐缓存文件获取MP3

Python解密网易云音乐缓存文件获取MP3

2019年12月18日  | 移动技术网IT编程  | 我要评论

新氧ubuntu,熟女剩男爱作战,romantz

 

前言
本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。
作者:generalmonkey

python解密网易云音乐缓存文件获取mp3
1、安装mutagen
2、获取缓存文件目录文件
3、缓存文件解码
4、获取mp3歌曲信息
5、循环进行保存文件到指定目录
全部源码
1、安装mutagen
首先进行安装mutagen,直接命令行安装,前提条件,你需要先安装pip工具,如果你解密或者这个工具不懂,或者你也刚学python不久,建议去小编的python交流.裙 :一久武其而而流一思(数字的谐音)转换下可以找到了,里面有最新python教程项目可拿,多跟里面的人交流,进步更快哦!
pip install mutagen

2、获取缓存文件目录文件
网易云音乐客户端中设置,找到你的音乐缓存目录,里面有一个.uc文件,通过比较,发现uc文件和mp3文件大小基本一致,网上查询得知每字节和0xa3做异或即可, ^0xa3,我们将缓存先进行保存到一个列表中。

#获取uc文件列表
def listfiles(path):
for root, dirs, files in os.walk(path):
for file in files:
if os.path.splitext(file)[1] == '.uc':
flist.append(file)
print(flist)
3、缓存文件解码
拿到缓存文件的列表之后,我们开始进行异或运算,然后保存成mp3文件,期间需要进行获取mp3文件信息,由于文件中有可能获取不到歌曲的信息,我们做了一个操作,凡是获取的不到歌曲名称信息的文件,一律保存"未知歌曲"+序号的方式作为新文件名称,当然你也可以自定义。

#音乐文件解码
def decodefile(filepath, newfilepath,index):
with open(filepath,'rb') as infile:
bytearr = bytearray(infile.read())
with open(newfilepath, 'wb') as outfile:
for i,j in enumerate(bytearr):
bytearr[i] = j ^ 0xa3
outfile.write(bytearr)
outfile.close()
name = wirtefilename(newfilepath)
if name is not none:
try:
os.rename(newfilepath, os.path.join(savepath, name)+'.mp3')
except fileexistserror as e:
print("file exist")
except oserror as e:
name = "未知曲目" + str(index)
os.rename(newfilepath, os.path.join(savepath, name) + '.mp3')
finally:
...
else:
name = "未知曲目"+str(index)
try:
os.rename(newfilepath, os.path.join(savepath, name)+'.mp3')
except fileexistserror as e:
print("file exist")
finally:
4、获取mp3歌曲信息
利用mutagen模块中的mp3进行获取歌曲信息,部分歌曲可能获取不到信息。

# 获取mp3歌曲名称
def wirtefilename(musicpath):
#print(musicpath)
fileinfo = mp3(musicpath, id3 = easyid3)
print(fileinfo)
if fileinfo != {}:
print(fileinfo['title'][0])
name = str(fileinfo['title'][0])
5、循环进行保存文件到指定目录
最后我们逐文件进行保存即可。

if __name__ == "__main__":
listfiles(cachepath)
index = 0
print(len(flist))
for i in flist:
decodefile(os.path.join(cachepath, i),os.path.join(savepath, "temp.mp3"), index)
index = index+1
全部源码
import os
from mutagen.mp3 import mp3
from mutagen.easyid3 import easyid3

cachepath = "f:/缓存temp/cache"
savepath = "c:/users/administrator/desktop/save"
flist = []

#获取uc文件列表
def listfiles(path):
for root, dirs, files in os.walk(path):
for file in files:
if os.path.splitext(file)[1] == '.uc':
flist.append(file)
print(flist)

#音乐文件解码
def decodefile(filepath, newfilepath,index):
with open(filepath,'rb') as infile:
bytearr = bytearray(infile.read())
with open(newfilepath, 'wb') as outfile:
for i,j in enumerate(bytearr):
bytearr[i] = j ^ 0xa3
outfile.write(bytearr)
outfile.close()
name = wirtefilename(newfilepath)
if name is not none:
try:
os.rename(newfilepath, os.path.join(savepath, name)+'.mp3')
except fileexistserror as e:
print("file exist")
except oserror as e:
name = "未知曲目" + str(index)
os.rename(newfilepath, os.path.join(savepath, name) + '.mp3')
finally:
...
else:
name = "未知曲目"+str(index)
try:
os.rename(newfilepath, os.path.join(savepath, name)+'.mp3')
except fileexistserror as e:
print("file exist")
finally:
...

# 获取mp3歌曲名称
def wirtefilename(musicpath):
#print(musicpath)
fileinfo = mp3(musicpath, id3 = easyid3)
print(fileinfo)
if fileinfo != {}:
print(fileinfo['title'][0])
name = str(fileinfo['title'][0])
return str(name)

if __name__ == "__main__":
listfiles(cachepath)
index = 0
print(len(flist))
for i in flist:
decodefile(os.path.join(cachepath, i),os.path.join(savepath, "temp.mp3"), index)
index = index+1

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网