"""
A utility by written by Richard Goodrow of Gallaudet
University's Academic Technology. This utility will convert Real caption files
RT to SAMI for use in Windows Media or QTtext for use in Quick-Time. It will also
convert QTtext files to SAMI. There is no expressed guarantee to the accuracy
of the conversions. As is best practice, please review any material before publishing it.
Copyright 2008 Academic Technology at Gallaudet University. All rights reserved.
"""
import cgi
# ----------------------------------------------------------------------------
# template for SAMI header
# ----------------------------------------------------------------------------
def SAMIheader():
SAMIheader = """
" return SAMIbegin # ---------------------------------------------------------------------------- # Main routine to convert line by line. Detects if the line is a time marker, # a line of content, or just junk. This also strips out a few pieces of content # unused by SAMI. # ---------------------------------------------------------------------------- def QtoSAMI_Convert(incomingText): for line in incomingText.splitlines(): if (line.find('[',0,1) != -1): print "\t
\n\t" % ConvertTime_SMTPtoSec(line.strip("[]")), elif (line.find('{QTtext}',0) != -1) | (line.find('{timescale',0) != -1): print " ", else: print "%s" % line.replace("{justify:center}", ""), # ---------------------------------------------------------------------------- # Convert time to milisec. Split SMTPE time code into units of hours, minutes, # and seconds. It converts each to seconds, adds them, and converts to milliseconds. # ---------------------------------------------------------------------------- def ConvertTime_SMTPtoSec (incomingTime): UnitsOfTime = incomingTime.split(":") theHours = float(UnitsOfTime[0]) * 3600 theMints = float(UnitsOfTime[1]) * 60 theSeconds = float(UnitsOfTime[2]) TotalMilSecs = theHours + theMints + theSeconds return int(TotalMilSecs * 1000) # ---------------------------------------------------------------------------- # RTtoSAMI_Convert(incoming text) # This function takes RT Text and converts to QT Text. The result may be # sent back to the QtoSAMI_Convert for complete conversion. # ---------------------------------------------------------------------------- def RTtoSAMI_Convert (incomingText): fileContents = incomingText.split("<") returnText = "" for eachLine in fileContents: eachLine = eachLine.strip() if eachLine.startswith("time"): returnText += "[" + eachLine.strip('time begin="<>/') + "]" + "\n" elif eachLine.endswith(">"): del eachLine else: thisEditedLine = eachLine.replace('\n', '').replace('br>', '').replace('clear/>','').strip() returnText += thisEditedLine + "\n" return returnText # ---------------------------------------------------------------------------- # GiveForm # template to produce basic form # ---------------------------------------------------------------------------- def GiveForm(textForForm): try: thisContent = textForForm except: thisContent = "" HTMLout = """
"""
#Grab Field
form = cgi.FieldStorage()
# Check if blank the form has any content. If not (perhaps due to a first run),
# show the form and halt execution.
try:
content = form["content"].value
except:
print GiveForm("")
quit()
# Output to browser
print """