2005-06-17 10:59:47 +00:00
|
|
|
#!/usr/bin/env python
|
2005-11-19 10:37:58 +00:00
|
|
|
# -*- Mode: Python -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2005-06-17 10:59:47 +00:00
|
|
|
|
|
|
|
# gstfile.py
|
|
|
|
# (c) 2005 Edward Hervey <edward at fluendo dot com>
|
|
|
|
# Discovers and prints out multimedia information of files
|
|
|
|
|
|
|
|
# This example shows how to use gst-python:
|
|
|
|
# _ in an object-oriented way (Discoverer class)
|
|
|
|
# _ subclassing a gst.Pipeline
|
|
|
|
# _ and overidding existing methods (do_iterate())
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import gobject
|
2006-04-29 16:59:16 +00:00
|
|
|
gobject.threads_init()
|
2005-07-13 12:31:47 +00:00
|
|
|
|
|
|
|
import pygst
|
2005-12-01 19:15:26 +00:00
|
|
|
pygst.require('0.10')
|
2005-07-13 12:31:47 +00:00
|
|
|
|
2005-12-12 15:15:28 +00:00
|
|
|
from gst.extend.discoverer import Discoverer
|
2005-06-17 10:59:47 +00:00
|
|
|
|
2005-12-12 15:15:28 +00:00
|
|
|
class GstFile:
|
2005-06-17 10:59:47 +00:00
|
|
|
"""
|
2005-12-12 15:15:28 +00:00
|
|
|
Analyses one or more files and prints out the multimedia information of
|
|
|
|
each file.
|
2005-06-17 10:59:47 +00:00
|
|
|
"""
|
|
|
|
|
2005-12-12 15:15:28 +00:00
|
|
|
def __init__(self, files):
|
|
|
|
self.files = files
|
|
|
|
self.mainloop = gobject.MainLoop()
|
|
|
|
self.current = None
|
2005-06-17 10:59:47 +00:00
|
|
|
|
2005-12-12 15:15:28 +00:00
|
|
|
def run(self):
|
|
|
|
gobject.idle_add(self._discover_one)
|
|
|
|
self.mainloop.run()
|
2005-06-17 10:59:47 +00:00
|
|
|
|
2005-12-12 15:15:28 +00:00
|
|
|
def _discovered(self, discoverer, ismedia):
|
|
|
|
discoverer.print_info()
|
|
|
|
self.current = None
|
|
|
|
if len(self.files):
|
|
|
|
print "\n"
|
|
|
|
gobject.idle_add(self._discover_one)
|
2005-06-17 10:59:47 +00:00
|
|
|
|
2005-12-12 15:15:28 +00:00
|
|
|
def _discover_one(self):
|
|
|
|
if not len(self.files):
|
|
|
|
gobject.idle_add(self.mainloop.quit)
|
|
|
|
return False
|
|
|
|
filename = self.files.pop(0)
|
2005-06-17 10:59:47 +00:00
|
|
|
if not os.path.isfile(filename):
|
2005-12-12 15:15:28 +00:00
|
|
|
gobject.idle_add(self._discover_one)
|
|
|
|
return False
|
|
|
|
print "Running on", filename
|
|
|
|
# create a discoverer for that file
|
|
|
|
self.current = Discoverer(filename)
|
|
|
|
# connect a callback on the 'discovered' signal
|
|
|
|
self.current.connect('discovered', self._discovered)
|
|
|
|
# start the discovery
|
|
|
|
self.current.discover()
|
|
|
|
return False
|
2005-06-17 10:59:47 +00:00
|
|
|
|
|
|
|
def main(args):
|
|
|
|
if len(args) < 2:
|
|
|
|
print 'usage: %s files...' % args[0]
|
|
|
|
return 2
|
|
|
|
|
2005-12-12 15:15:28 +00:00
|
|
|
gstfile = GstFile(args[1:])
|
|
|
|
gstfile.run()
|
2005-06-17 10:59:47 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|