python : 走遍美国 lrc 转为 html
程序员文章站
2022-07-13 23:38:34
...
curl -O http://mp3.en8848.com/zhuo-bian-mei-guo/u01-1.lrc
curl -O http://mp3.en8848.com/zhuo-bian-mei-guo/u01-2.lrc
curl -O http://mp3.en8848.com/zhuo-bian-mei-guo/u01-3.lrc
lrc2htm.py
curl -O http://mp3.en8848.com/zhuo-bian-mei-guo/u01-2.lrc
curl -O http://mp3.en8848.com/zhuo-bian-mei-guo/u01-3.lrc
lrc2htm.py
# -*- coding: cp936 -*- import os, sys import glob if len(sys.argv) ==2: pattern = sys.argv[1] else: print 'usage: lrc2htm.py *.lrc ' print 'create ?????.htm ' sys.exit(1) for f1 in glob.glob(pattern): print f1 fn,ext = os.path.splitext(f1) if ext != '.lrc': print 'Error: %s is not lrc file ' % f1 sys.exit(4) if fn[-1]=='1': N='I' elif fn[-1]=='2': N='II' elif fn[-1]=='3': N='III' else: N='?' headline ="""<!DOCTYPE html> <html> <head> <title> 走遍美国 %s </title> </head> <body> <h3> EPISODE %s <a href=\"index.htm\">返回目录 </a></h3> <audio controls="controls"> <source src="./%s.mp3" type="audio/mp3" /> <embed height="100" width="100" src="./%s.mp3" /> </audio> <p>ACT %s """ % (fn,fn[1:3],fn,fn,N) fp1 = open(f1,'r') f2 = fn +'.htm' fp2 = open(f2,'w') fp2.write(headline) ln =0 for line in fp1: ln +=1 if ln >4: if len(line.strip()) >12: i = line.find(']',0) aline = '<br>'+line[i+1:] fp2.write(aline) else: aline = '<br>'+line fp2.write(aline) # fp2.write("</p>\n</body>\n</html>\n") fp1.close() fp2.close() #