# -*- coding: utf-8 -*-import threadingimport timeimport datetimeimport reimport osimport eyed3import sysreload(sys)sys.setdefaultencoding('utf8')###指定音乐文件的路径和歌词的路径.然后将歌词嵌入到音乐标签中def getstr(i):if i <10:return "0"+str(i)else:return str(i)def deallrc(str):mystr=re.sub(r'\[\d\d:\d\d.\d\d\]','',str)mystr.replace('\n','')return mystrdef checklrcfile(path,timespan):file=open(path,'r')mylrcstr=''#print timespanfor line in file.readlines(100):#errorlog(line)if line.find(timespan)>0:return deallrc(line)else:continuereturn ''def getlrcstr(lrc):mylrcstr=''#print lrcfor i in range(00,05):for j in range(00,59):for k in range(00,99):timespan=getstr(i)+":"+getstr(j)+"."+getstr(k)mylrcstr+=checklrcfile(lrc, timespan)#print timespanreturn mylrcstrdef getlrc(musicname):musicname=u''.join(musicname)musicname=musicname.encode('gb2312')for root,dirs,files in os.walk(lrcpath):for filepath in files:the_path = os.path.join(root,filepath)if (the_path.find(musicname) != -1):print the_pathreturn the_pathdef errorlog(path):file=open(r'e:\nolrc.txt','a')if path is None:path=''path=path+'\n'file.write(path)file.close()def writetag(themusic,lrcstr):music=eyed3.load(themusic)lrcstr=lrcstr.decode('utf8')lrcstr=u''.join(lrcstr)#lrcstr=unicode(lrcstr)music.tag.lyrics.set(lrcstr)music.tag.save()def dealmusic(path):print paththe_music = eyed3.load(path)the_teg = the_music.tag._getAlbum()the_artist = the_music.tag._getArtist()the_title = the_music.tag._getTitle()#print the_title#lrc=getlrc(the_title)lrc=r"E:\lrc\错的人.lrc"lrcstr=getlrcstr(lrc)writetag(path, lrcstr)"""try:except:errorlog(path)""""""try:lrc=getlrc(the_title)lrcstr=getlrcstr(lrc)writetag(path, lrcstr)except:errorlog(path)"""musicpath=r"F:\CloudMusic\Alina Baraz,Galimatias\Fantasy Single\Alina Baraz,Galimatias - Fantasy.mp3"lrcpath=r"E:\lrc"dealmusic(musicpath)print "the end"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。