
正文
Python脚本之Lrc歌词去时间轴转Txt文件,附带酷狗音乐APP关联已有krc歌词
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
一、Lrc歌词去时间轴转Txt文件
环境:Python2.7.x, Mac(Windows需装cygwin环境,当然你也可以自己改代码,Python新手,勿喷)
# -*- coding: UTF-8 -*-import reimport sysimport os,shutilreload(sys)sys.setdefaultencoding("utf-8")rootdir = os.getcwd()def delfile(str): if os.path.exists(str): os.remove(str) print 'delete '+str+' success' else: print 'no such file:%s'%strdef file_extension(path): return os.path.splitext(path)[1]def fileMove(pathname, dstfile): shutil.move(pathname, dstfile)def delListDir(rootDir): for filename in os.listdir(rootDir): pathname = os.path.join(rootDir, filename) if (os.path.isfile(pathname)): fileExt = file_extension(pathname) if fileExt == ".txt" : delfile(pathname) else: delListDir(pathname)delListDir(rootdir+'/../')def delUnuseWords(str): outStr = str if str[1:3] == 'ar': outStr = str[4:-2]+'\n' elif str[1:3] == 'ti': outStr = str[4:-2]+'\n' else: outStr = str[10:] return outStrdef writefile(pathname, filename): print pathname filename = filename.strip('.lrc') f_out_path = os.path.abspath(os.path.dirname(rootdir)+os.path.sep+filename+".txt") f_out = open(f_out_path,'a') file_object = open(pathname,'rU') try: for line in file_object: if line.count('\n')==len(line): continue else: line = delUnuseWords(line) f_out.write(line) finally: file_object.close() f_out.close() def listDir(rootDir): for filename in os.listdir(rootDir): pathname = os.path.join(rootDir, filename) fileExt = file_extension(pathname) if fileExt == ".lrc": if (os.path.isfile(pathname)): writefile(pathname, filename) else: listDir(pathname)listDir(rootdir)# writefile(rootdir)print "恭喜您,转换完成!"
操作:保存代码为create.py 歌词文件放置于与create.py同目录或同目录下的文件夹里
说明:此脚本主要是方便批量去lrc歌词时间轴,当然你也可以选择用Word去去除时间轴。
二、酷狗APP歌词关联已有krc歌词(仅限于2019年03月28日18:59:29更新,之后更新不管)
步骤:
1、酷狗自制歌词,可输入任意字符,几行就行,然后随便敲一下,之后保存至本地,则此时本地KuGou/make_lyrics/目录下就会生成歌曲对应的歌词文件
2、复制生成的歌词文件名,把准备好的krc歌词替换为新文件名,并替换KuGou/make_lyrics/下的歌词文件。
3、重新播放歌曲就会发现歌词已关联。
总结:利用酷狗生成歌词信息,替换为新的歌词文件。







