#!/bin/python

import sys

import gobject
import pygst
pygst.require('0.10')
import gst

class Test(object):
    def __init__(self, source, dest):
        self.src = open(source, 'rb')
        self.dst = open(dest, 'wb')
        
        self.bin = gst.parse_launch('fdsrc fd=%i ! fdsink fd=%i'
                                    % (self.src.fileno(), self.dst.fileno()))
        
    def run(self):
        mainloop = gobject.MainLoop()
        def bus_event(bus, message):
            t = message.type
            if t == gst.MESSAGE_EOS:
                mainloop.quit()
            elif t == gst.MESSAGE_ERROR:
                err, debug = message.parse_error()
                mainloop.quit()
                raise Exception, '%s (%s)' % (err, debug)
            return True
        self.bin.get_bus().add_watch(bus_event)
        
        self.bin.set_state(gst.STATE_PLAYING)
        mainloop.run()
        self.bin.set_state(gst.STATE_NULL)

if __name__ == '__main__':
	if len(sys.argv) == 3:
		Test(sys.argv[1], sys.argv[2]).run()
	else:
		print 'Usage: %s SOURCE DEST' % sys.argv[0]
