$)')
brln_tag = re.compile('(^
$)')
line_end = re.compile('(\A<.*\Z| *<.*\Z)')
line_css = re.compile('( *--$|\A--$)')
textline = re.compile('(.*<.*\Z)')
strtline = re.compile('(\A)')
end_line = re.compile('(\Z)')
whitespc = re.compile('\A *')
code_css = re.compile('\A .*')
mainline = re.compile('(\A\n)', re.MULTILINE)
# To split all tags into a separate line with the '>' character
for line in file:
parts = line.split('>')
for part in parts:
# When the line is split, we replace the ending '>'
if line_end.match(part):
try:
part = whitespc.sub('', part)
tempsplit = part.split(' ', 2)
tempsplit[0] = str.lower(tempsplit[0])
part = str(tempsplit[0]) + ' ' + str(tempsplit[1])
except Exception:
part = str.lower(part)
part = end_line.sub('>' , part.strip())
# To ensure no empty new lines are used for parsing
if not mainline.match(part):
# To close 'sync' or 'p' tags
if sync_tag.match(part) or para_tag.match(part):
part = part.replace('>', '/>')
part = part.replace('=', '="')
datastream += part.replace('/>', '"/>') + '\n'
# To close 'br' tags
elif brln_tag.match(part):
datastream += part.replace('>', '/>') + '\n'
else:
part = whitespc.sub('', part)
datastream += part.replace('\n', '') + '\n'
# To close css marker tags
elif line_css.match(part):
part = end_line.sub('>' , part.strip())
part = whitespc.sub('', part)
datastream += part.replace('\n', '') + '\n'
# To correct tags at the end of a piece of text (ie. text
)
elif textline.match(part):
tempsplit = part.split('<', 1)
tempsplit[0] = whitespc.sub('', tempsplit[0])
datastream += tempsplit[0] + '\n'
tempsplit[1] = str.lower(tempsplit[1])
# As the tag will be missing '<' and '>' we need to replace both
tempsplit[1] = strtline.sub('<' , tempsplit[1])
tempsplit[1] = end_line.sub('>' , tempsplit[1])
# To ensure no empty new lines are saved
if not mainline.match(tempsplit[1]):
if sync_tag.match(tempsplit[1]) or para_tag.match(tempsplit[1]):
# To close 'sync' or 'p' tags
part = part.replace('>', '/>')
part = part.replace('=', '="')
datastream += tempsplit[1].replace('>', '/>') + '\n'
# To close 'br' tags
elif brln_tag.match(tempsplit[1]):
datastream += tempsplit[1].replace('>', '/>') + '\n'
else:
datastream += tempsplit[1] + '\n'
# Print remaining CSS data in between
elif code_css.match(part):
part = whitespc.sub('', part)
datastream += part.replace('\n', '') + '\n'
filetemp = open('tempfile.tmp', 'w')
filetemp.write(datastream)
filetemp.close()
elif function == 'cleanup':
os.remove('tempfile.tmp')
if __name__=='__main__':
global savecmml
global fps
fps = None
print 'Frames-per-Second of Video Required:\nEnter Frames-per-Second:'
while not fps:
try:
fps = float(raw_input())
except ValueError:
print 'Invalid FPS Entered. Try Again.'
try:
xml_correct(file(sys.argv[1]), 'create')
try:
filesave = open(sys.argv[2], 'w')
# using temp file from xml_correct
convert_sami(file('tempfile.tmp'))
filesave.write(savecmml)
filesave.close()
except IndexError:
# using temp file from xml_correct
convert_sami(file('tempfile.tmp'))
print savecmml
xml_correct('', 'cleanup')
except IndexError:
print "Usage: %s [Input SAMI File] [Output CMML File]" % sys.argv[0]