Linux下歌词编辑器,Linux歌词编辑器,#!/usr/bin/e
#!/usr/bin/env python#-*- coding:utf-8 -*- '''使用audacious编辑lrc歌词。'''import Tkinterimport tkMessageBoxfrom Tkinter import *import osimport reos.system("audtool current-song-length-frames>/tmp/tmp.txt")song_length=open("/tmp/tmp.txt").read()os.system("audtool current-song-filename >/tmp/tmp.txt")file_name0=open("/tmp/tmp.txt").read()file_dir=os.path.dirname(file_name0)file_basename=os.path.basename(file_name0)file_name1=os.path.splitext(file_basename) [-0] #分离文件名与扩展名print ('file_name1='+file_name1)filename='%s%s%s.lrc' %(file_dir,"/",file_name1)#filename='/home/ziyan/Desktop/123.lrc'#fi=open(filename,"r")#lrc=[l.strip() for l in fi.read()]lrcfile= open(filename,"a+")lrc=lrcfile.read() #打开文件,“a+”若文件不存在则创建文件lrcfile.close()os.system("audtool current-song-length-seconds>/tmp/tmp.txt")song_time_length=open("/tmp/tmp.txt").read()mark="mark"class TEXT: def __init__(self,root): self.text=Tkinter.Text(root) self.text.pack() self.text.insert(INSERT,lrc) self.text.bind("<1>", self.OnMouseDown) self.text.mark_set(mark,1.0) p = Button(root, text = "preview",width=10, command = pre).pack(side=LEFT,fill=X) B = Button(root, text = "Insert", command = Insert_time).pack(side=LEFT) n = Button(root, text = "next", command = next).pack(side=LEFT) save = Button(root, text = "保存", command = saveme).pack(side=RIGHT,fill=X) ###self.text.bind('<F10>',self.pre) def OnMouseDown(self, event): self.text.mark_set(mark,CURRENT) ###def pre(): ###self.text.mark_set(mark,mark + '-1l') def Insert_time(): os.system("audtool current-song-output-length-frames>/tmp/tmp.txt") #tmp=open("/tmp/tmp.txt") current=open("/tmp/tmp.txt").read() current_time=float(current)/float(song_length)*float(song_time_length)-0.2 minute=int(current_time)/60 sec= (int(current_time*100)%6000)/100.0 ###print "second1:"+second #text.insert(INSERT,song_time_length) #t='['+str(minute)+':'+str(second)+']' second= sec if minute<10 : minute='0%s' %(minute) if sec<10 : second='0%s' %(sec) if int(sec*100)%10==0: second='%s0' %(second) ###print "second2:"+second #if int(second.split(".") [-1] )<10 : # second='%s0' %(second) # print "second3:"+second t='[%s:%s]' %(minute,second) ##合并 #i=3 ####j='%s.0'%(line.count) ###text.winfo_pointerxy() ###text.mark_set(t,CURRENT + '+5 chars') #text.insert(j, t)#current_time) print(t) app.text.mark_set(mark,mark + ' linestart') app.text.insert(mark, t)#current_time) app.text.mark_set(mark,mark + '+1l')def pre(): app.text.mark_set(mark,mark + '-1l') #text.tag_add("a",'%s.0' %(line.count) ,'%s.end' %(line.count)) #text.tag_remove("b",'%s.0' %(line.count) ,'%s.end' %(line.count)) #line.count-=1 #if line.count<1: # line.count=1 #text.tag_add("b",'%s.0' %(line.count) ,'%s.end' %(line.count))def next(event=None): app.text.mark_set(mark,mark + '+1l') #text.tag_remove("b",'%s.0' %(line.count) ,'%s.end' %(line.count)) #text.tag_add("a",'%s.0' %(line.count) ,'%s.end' %(line.count)) #line.count+=1 #text.tag_add("b",'%s.0' %(line.count) ,'%s.end' %(line.count))def saveme(): f=open(filename,'w') #text_=app.text.get(1.0,END) #print(text_) #print >>f,text_ f.write(app.text.get(1.0,END).encode("UTF-8")) f.close()root=Tkinter.Tk()root.title(filename)app=TEXT(root)#next = Button(root, text = "next2", command = next).pack(side=LEFT)#next.bind('<F10>',next)root.mainloop()#该片段来自于http://byrx.net
评论关闭