radiaSRT/gen_html.py

41 lines
1.4 KiB
Python
Raw Normal View History

2011-09-03 14:28:41 +00:00
from ox.text import findRe
2011-09-05 11:58:38 +00:00
import json
import codecs
2011-09-03 14:28:41 +00:00
def do():
2011-09-05 11:58:38 +00:00
f = codecs.open("ChronoArr_Srt.txt", mode="r", encoding="utf-8")
data = json.loads(open("radia.json").read())
2011-09-03 14:28:41 +00:00
txt = f.read()
tapes = txt.split("***")
2011-09-05 11:58:38 +00:00
indexHtml = u''
counter = 0
2011-09-03 14:28:41 +00:00
for t in tapes:
2011-09-05 11:58:38 +00:00
if counter >= len(data):
break
meta = data[counter]
padmaId = meta['hid']
audioFile = meta['name'] + u'.wav'
2011-09-03 14:28:41 +00:00
fullTxt = t.strip()
titleReg = r'Title: (.*?)\n'
2011-09-03 14:35:29 +00:00
timeReg = r'Time: (.*?)\n'
2011-09-03 14:37:27 +00:00
time = findRe(fullTxt, timeReg)
2011-09-03 14:28:41 +00:00
outfile = "tapes/%d.html" % (counter,)
title = findRe(fullTxt, titleReg)
print title
2011-09-05 11:58:38 +00:00
indexHtml += "<a target='_blank' href='%s'>%s</a><br />Time: %s<br/>\n" % (outfile, title, time,)
indexHtml += "<a target='_blank' href='http://pad.ma/%s'>View on Padma</a><br />\n" % (padmaId,)
audioHtml = "<audio controls='controls' src='wav/%s'></audio><br /><br />\n\n" % (audioFile,)
print audioHtml
indexHtml += audioHtml
out = codecs.open(outfile, mode="w", encoding="utf-8")
2011-09-05 12:01:23 +00:00
out.write("<audio controls='controls' src='wav/%s'></audio><br /><br /><pre>%s</pre>" % (audioFile, fullTxt,))
2011-09-03 14:28:41 +00:00
out.close()
counter += 1
2011-09-05 11:58:38 +00:00
indexFile = codecs.open("index.html", mode="w", encoding="utf-8")
2011-09-03 14:28:41 +00:00
indexFile.write(indexHtml)
indexFile.close()
f.close()