下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
#!/usr/bin/python# -*- Coding: utf-8 -*-#=========================================# filename : music.py# filetype : Python# Author : Colben# Create : 2015-06-30 22:17:15#=========================================import sys,os,time,subprocess,re,chardetdef load_lrc(lrc_file): try: lrc_contains = open(lrc_file,'rb').read() enCoding = chardet.detect(lrc_contains)['enCoding'] if 'utf-8' != enCoding: lrc_contains = lrc_contains.decode(enCoding).encode('utf-8') except Exception,e: print '3[4;0H3[K\tNo lrc or in enCoding found' return {} lrc = {} for eachline in re.split(r'\n',lrc_contains): line = re.split(r']',eachline) if 1 < len(line): for tm in line[0:-1]: try: time = re.match(r'(\d\d)\s*:\s*(\d\d)',tm.strip(' [')).groups() pos = 60*int(time[0]) + int(time[1]) lrc[pos] = line[-1] except Exception,e: #print '3[4;0H3[K\tLrc fromat error' #lrc_fp.close() #return {} pass #lrc_fp.close() return lrcdef main(song): print '3[2J3[2;0H\tPlaying %s ...'%song[:60] p = subprocess.Popen('mplayer %s 2>/dev/null'%song,stdout = subprocess.PIPE,shell = True) while True: match = re.match(r'A:.*[\d:.()]* of (\d+)',p.stdout.read(30)) if None != p.poll(): print '3[9;0H\tFailed to recognize file format .' return 1 if not match: output = p.stdout.readline() else: tot_time = int(match.group(1)) - 1 for jump in range(1,10): if 70 >= tot_time/jump: break #print '3[15;0H\ttotal time: %d'%tot_time break print '3[?25l' lrc = load_lrc(os.path.splitext(song)[0] + '.lrc') while True: cur_char = p.stdout.read(1) if 'A' == cur_char: try: cur_time = int(p.stdout.read(5)[1:]) print '3[6;0H3[K\tCurrent %d / Total %d'%(cur_time,tot_time) print '3[1;0H','-'*(tot_time/jump) print '3[1;0H','='*(cur_time/jump) print '3[7;0H','-'*(tot_time/jump) print '3[7;0H','='*(cur_time/jump) if tot_time <= cur_time: print '3[8;0H3[K\tquit' break print '3[4;0H3[K\t%s'%lrc[cur_time] except Exception,e: #print '3[17;0H\tERROR:',e pass elif 'E' == cur_char: print '3[8;0H3[K\tquit' break p.wait() print '3[10;0H3[?25h' return 0if '__main__' == __name__: if 2 != len(sys.argv) or not os.path.isfile(sys.argv[1]): print '\nUsage:',sys.argv[0],'{exist music filename}\n' else: main(sys.argv[1])
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的linux终端播放音乐歌词同步显示全部内容,希望文章能够帮你解决linux终端播放音乐歌词同步显示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)