使用Python脚本将酷狗音乐的缓存文件修改为可播放
来源:互联网 发布:qq三国79js奥义三板斧 编辑:程序博客网 时间:2024/06/05 19:54
假期回老家后比较郁闷的一件事就是没有网, 因为在学校一直使用的是酷狗的在线播放, 所有说连电脑里面里MP3音乐也没有, 由于之前我发现将酷狗酷狗音乐缓存文件后缀直接改成”mp3”就能播放, 所以需要将修改酷狗音乐的缓存文件的后缀, 对于重命名大量缓存文件, 可以使用命令行ren *.kgtemp *.mp3直接搞定, 另外一种就是编程处理了, 显然编程显得小题大做, 但是还是决定使用Python脚本处理, 因为脚本可以同时从歌词目录从将一部分歌曲的名字获取过来并设置.
下面是处理的脚本文件, Python34
import osimport shutilpatterCache = "kgtemp"patterLyric = "krc"suffixLen = 36newDir = "tempMP3"#遍历所有目录搜索酷狗音乐的目录def searchPath(dire): '''seal recursive function inside searchPath, ensure that most variable are locablbe''' #files means the number of files #unknown means the count of files with name's encode is not gbk, and can't output #only define like as follow can be modify print("searching...") res = {"lyrics": None, "caches" : None} def traverse(dire): '''recursive function with file counter and output file's path''' try:#give up unreadable direction os.chdir(dire) except Exception: return #traverse all files or direcions in current direction for x in os.listdir(dire): #derection then recursive search if os.path.isdir(x) and x != "$RECYCLE.BIN": traverse(os.path.abspath(x)) #find kugou cache path elif x[-len(patterCache) : ] == patterCache: if not res["caches"]: res["caches"] = os.getcwd() else: break #find kugou lyric path elif x[-len(patterLyric) : ] == patterLyric: if not res["lyrics"]: res["lyrics"] = os.getcwd() else: break os.chdir("..") #if has find the path of both lyric and cache, then return if res["lyrics"] and res["caches"]: return traverse(dire) print("finish searching!") return resdef modify(cacheDir, lyricDir): '''copy all cache in new direction and rename all file, set sufix as mp3''' #change working dir to lyric dir os.chdir(lyricDir) names = {} print("copy name list from lyrics") for x in os.listdir(): #get all lyric file name names[x[-suffixLen : -len(patterLyric) - 1]] = x[ : -suffixLen - 1] #change working dir os.chdir(cacheDir) print("check and create new direction") if not os.path.exists("../" + newDir): os.mkdir("../" + newDir) print("copying...") for item in os.listdir(): if not os.path.exists("../" + newDir + item): try: #copy cache to new direciont shutil.copy(item, "../" + newDir) core = item[ : -len(patterCache) - 1] if core in names:#rename cache if has lyric file os.rename("../" + newDir + item, "../" + newDir + names[core] + ".mp3") else:#set sufix to mp3 os.rename("../" + newDir + item, "../" + newDir + core + ".mp3") except Exception: passdef verify(dire): '''traverse all files in new direction to check whether has file not change its sufix''' print("verifying") os.chdir(dire) os.chdir("../" + newDir) for item in os.listdir(): if item[-3 : ] != "mp3": os.rename(item, item[ : -len(patterCache) - 1] + ".mp3")##################entry######################loc = str(input("请输入酷狗音乐的缓存磁盘:"))while not loc.isalpha(): print(loc, "is not valid, input again:") loc = str(input("请输入酷狗音乐的缓存磁盘:"))loc += ":\\"res = searchPath(loc)print("cache dir:", res["caches"])print("lyric dir:", res["lyrics"])modify(res["caches"], res["lyrics"])verify(res["caches"])os.chdir(res["caches"])os.chdir("../" + newDir)print("done check mp3 file in", os.getcwd())
0 0
- 使用Python脚本将酷狗音乐的缓存文件修改为可播放
- 播放音乐的脚本
- 文件管理器中打开录音文件修改为音乐播放器播放
- H.264裸流保存为可使用ffplay播放的文件
- 解决酷狗音乐缓存文件kgtemp文件无法播放的问题
- 酷狗音乐的临时缓存文件转换为MP3文件,java源码
- Python随机播放电脑里的音乐
- python实现简单的音乐播放功能
- 音乐播放例子 ios 可显示左右声道的音频
- 利用JMF可播放多种格式的音乐
- Python播放音乐
- Python音乐播放器
- python播放音乐
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
- Android音乐播放器的缓存机制设计
- 把txt文件转换为tsv文件的python脚本
- Button的使用(十四):控制音乐播放
- linearlayout线性布局属性
- Android中的对话框(二)ProgressDialog
- 【NOI2001】聪明的打字员 - 类似8数码的搜索题
- Android在layout xml中使用include
- MySql索引的原理
- 使用Python脚本将酷狗音乐的缓存文件修改为可播放
- 详解C/C++中预处理器
- IOS从屏幕截图并裁剪压缩到指定宽高
- jquery获取触发方法的对象
- hdu3416
- 【BLE】CC2541之硬件IIC(TMP102温度传感器)
- bfprt算法求最小的k个数
- LeetCode 155 Min Stack(最小栈)
- Qt中文件类型过滤器