#!/usr/local/bin/python
# convert sw1.txt from swplay.jar, containing a star-wars movie, into
# a movie in play-movie's format

import string, time, sys

def write_rec(code, content=''):
    assert len(code) == 1 and type(code) is type('s')
    sys.stdout.write("%s%d:%s," % (code, len(content), content))
    sys.stdout.flush()

def convert():
    curtime = 0
    while 1:
        num = sys.stdin.readline()
        if num == '\xff\r\n':
            write_rec('e')
            return
        write_rec('s',
                  '\033[H\033[J' +   # clear screen
                  string.join([sys.stdin.readline() for i in range(13)], ''))
        # the number *before* the frame specifies how long to wait *after*
        # the frame before displaying the next one
        curtime = curtime + int(num) / 12.0
        write_rec('t', "%.2f" % curtime)
        
        
if __name__ == "__main__": convert()
