import sys
import gst

def decode(filename):
    output = filename + '.wav'
    pipeline = ('filesrc location="%s" ! spider ! audio/x-raw-int,rate=44100,stereo=2 ! wavenc ! '
                'filesink location="%s"') % (filename, output)
    
    bin = gst.parse_launch(pipeline)
    bin.set_state(gst.STATE_PLAYING)
    while bin.iterate():
        pass
    bin.set_state(gst.STATE_NULL)
    
def main(args):
    for arg in args[1:]:
        decode(arg)
        
if __name__ == '__main__':
    sys.exit(main(sys.argv))

import sys
import gst

def decode(filename):
    output = filename + '.wav'
    pipeline = ('{ filesrc location="%s" ! spider ! audio/x-raw-int,rate=44100,stereo=2 ! wavenc ! '
                'filesink location="%s" }') % (filename, output)
    
    bin = gst.parse_launch(pipeline)
    bin.set_state(gst.STATE_PLAYING)
    bin.connect('eos', lambda bin: gst.main_quit())
    gst.main()
    
def main(args):
    for arg in args[1:]:
        decode(arg)
        
if __name__ == '__main__':
    sys.exit(main(sys.argv))

Put it in a thread and run it in a mainloop
Put it in a thread and run it in a mainloop

Original commit message from CVS:
Put it in a thread and run it in a mainloop

  import sys
  import gst
  
  def decode(filename):
      output = filename + '.wav'
-     pipeline = ('filesrc location="%s" ! spider ! audio/x-raw-int,rate=44100,stereo=2 ! wavenc ! '
+     pipeline = ('{ filesrc location="%s" ! spider ! audio/x-raw-int,rate=44100,stereo=2 ! wavenc ! '
-                 'filesink location="%s"') % (filename, output)
+                 'filesink location="%s" }') % (filename, output)
      
      bin = gst.parse_launch(pipeline)
      bin.set_state(gst.STATE_PLAYING)
+     bin.connect('eos', lambda bin: gst.main_quit())
+     gst.main()
-     while bin.iterate():
-         pass
-     bin.set_state(gst.STATE_NULL)
      
  def main(args):
      for arg in args[1:]:
          decode(arg)
          
  if __name__ == '__main__':
      sys.exit(main(sys.argv))
  
Put it in a thread and run it in a mainloop
## Code Before:
import sys
import gst

def decode(filename):
    output = filename + '.wav'
    pipeline = ('filesrc location="%s" ! spider ! audio/x-raw-int,rate=44100,stereo=2 ! wavenc ! '
                'filesink location="%s"') % (filename, output)
    
    bin = gst.parse_launch(pipeline)
    bin.set_state(gst.STATE_PLAYING)
    while bin.iterate():
        pass
    bin.set_state(gst.STATE_NULL)
    
def main(args):
    for arg in args[1:]:
        decode(arg)
        
if __name__ == '__main__':
    sys.exit(main(sys.argv))

## Instruction:
Put it in a thread and run it in a mainloop
## Code After:
import sys
import gst

def decode(filename):
    output = filename + '.wav'
    pipeline = ('{ filesrc location="%s" ! spider ! audio/x-raw-int,rate=44100,stereo=2 ! wavenc ! '
                'filesink location="%s" }') % (filename, output)
    
    bin = gst.parse_launch(pipeline)
    bin.set_state(gst.STATE_PLAYING)
    bin.connect('eos', lambda bin: gst.main_quit())
    gst.main()
    
def main(args):
    for arg in args[1:]:
        decode(arg)
        
if __name__ == '__main__':
    sys.exit(main(sys.argv))
