`
belldeep
  • 浏览: 40844 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

python : 走遍美国 lrc 转为 html

阅读更多
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
# -*- 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 &nbsp;&nbsp;&nbsp;<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()
#
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics