1 Star 1 Fork 0

且听风吟/python

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
singel.py 2.62 KB
Copy Edit Raw Blame History
# -*- coding: utf-8 -*-
import threading
import time
import datetime
import re
import os
import eyed3
import sys
reload(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 mystr
def checklrcfile(path,timespan):
file=open(path,'r')
mylrcstr=''
#print timespan
for line in file.readlines(100):
#errorlog(line)
if line.find(timespan)>0:
return deallrc(line)
else:
continue
return ''
def getlrcstr(lrc):
mylrcstr=''
#print lrc
for 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 timespan
return mylrcstr
def 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_path
return the_path
def 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 path
the_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"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/lylinux/python.git
git@gitee.com:lylinux/python.git
lylinux
python
python
master

Search