def play(fnames, framerate=12): info = SWFInfo() info.framerate = framerate movie = MovieContainer(info) for fname in fnames: print 'Reading:', fname if fname.endswith('.swf'): # vnc2swf file movie.parse_vnc2swf(fname) elif fname.endswith('.vnc'): # vncrec file movie.parse_vncrec(fname) player = PygameMoviePlayer(movie) player.play() return
def main(argv): import getopt def usage(): print ('usage: %s [-d] [-n] [-o filename] [-t {flv|mpeg|swf5|swf7|vnc}]' ' [-e encoding] [-N] [-C clipping] [-r framerate] [-s scaling] [-z] [-m] [-a] [-V]' ' [-S subprocess] [-P pwdfile] [host[:display] [port]]' % argv[0]) return 100 try: (opts, args) = getopt.getopt(argv[1:], 'dno:t:e:NC:r:S:P:s:zmaVR:') except getopt.GetoptError: return usage() (debug, console, outtype, subprocess, merge, pwdfile, isfile) = (0, False, None, None, False, None, False) (cursor, host, port, preferred_encoding) = (True, 'localhost', 5900, (0,)) info = SWFInfo() for (k, v) in opts: if k == '-d': debug += 1 elif k == '-n': console = True elif k == '-t': outtype = v elif k == '-e': preferred_encoding = tuple([ int(i) for i in v.split(',') ]) elif k == '-N': cursor = False elif k == '-S': subprocess = Subprocess(v) elif k == '-a': subprocess = RecordingThread(v) elif k == '-m': merge = True elif k == '-P': pwdfile = v elif k == '-V': isfile = True elif k == '-o': info.filename = v elif k == '-R': reconnect = v elif k == '-C': try: info.set_clipping(v) except ValueError: print 'Invalid clipping specification:', v return usage() elif k == "-r": info.framerate = int(v) elif k == "-z": info.set_scalable(True) elif k == '-s': info.scaling = float(v) assert 0 < info.scaling and info.scaling <= 1.0, 'Invalid scaling.' if not outtype: if info.filename: if info.filename.endswith('.vnc'): outtype = 'vnc' elif info.filename.endswith('.swf'): outtype = 'swf5' elif info.filename.endswith('.mpg') or info.filename.endswith('.mpeg'): outtype = 'mpeg' elif info.filename.endswith('.flv'): outtype = 'flv' else: outtype = 'swf5' if outtype not in ('swf5','swf7','vnc','mpeg','flv'): print 'Please specify the output type or file extension.' return usage() if cursor: preferred_encoding += (-232,-239,) if 1 <= len(args): if ':' in args[0]: i = args[0].index(':') host = args[0][:i] or 'localhost' port = int(args[0][i+1:])+5900 else: host = args[0] if 2 <= len(args): port = int(args[1]) if console: if not info.filename: print 'Please specify the output filename.' return usage() vncfile = None if isfile: vncfile = sys.stdin if args: vncfile = file(args[0], 'rb') vnc2swf(info, outtype, host, port, preferred_encoding=preferred_encoding, subprocess=subprocess, pwdfile=pwdfile, vncfile=vncfile, merge=merge, debug=debug, reconnect=reconnect) else: tempdir = os.path.join(tempfile.gettempdir(), 'pyvnc2swf') try: os.mkdir(tempdir) except OSError: pass VNC2SWFWithTk(tempdir, info, outtype, host, port, preferred_encoding=preferred_encoding, subprocess=subprocess, pwdfile=pwdfile, debug=debug).run() return