[xiph-commits] r15054 - trunk/subtle

jmesquita at svn.xiph.org jmesquita at svn.xiph.org
Sat Jun 21 22:24:31 PDT 2008


Author: jmesquita
Date: 2008-06-21 22:24:31 -0700 (Sat, 21 Jun 2008)
New Revision: 15054

Modified:
   trunk/subtle/GPlayer.py
   trunk/subtle/MediaInfo.py
   trunk/subtle/Subtitles.py
Log:
* GPL Disclaimer on all files and proper identation

Modified: trunk/subtle/GPlayer.py
===================================================================
--- trunk/subtle/GPlayer.py	2008-06-22 05:09:07 UTC (rev 15053)
+++ trunk/subtle/GPlayer.py	2008-06-22 05:24:31 UTC (rev 15054)
@@ -32,180 +32,180 @@
 ## GstPlayer class.
 # Class for playing media in GStreamer.
 class GstPlayer:
-	## Construstor
-	# \param videowidget - VideoWidget class.
-	def __init__(self, videowidget):
-		self.playing = False
-		bin = gst.Bin('my-bin')
-		self.textoverlay = gst.element_factory_make('textoverlay')
-		bin.add(self.textoverlay)
-		pad = self.textoverlay.get_pad("video_sink")
-		ghostpad = gst.GhostPad("sink", pad)
-		bin.add_pad(ghostpad)
-		color = gst.element_factory_make('ffmpegcolorspace')
-		bin.add(color)
-		scale = gst.element_factory_make('videoscale')
-		bin.add(scale)
-		self.videosink = gst.element_factory_make('autovideosink')
-		bin.add(self.videosink)
-		gst.element_link_many(self.textoverlay, color, scale, self.videosink)
-		self.player = gst.element_factory_make("playbin", "player")
-		self.player.set_property("video-sink", bin)
-		self.videowidget = videowidget
+    ## Construstor
+    # \param videowidget - VideoWidget class.
+    def __init__(self, videowidget):
+        self.playing = False
+        bin = gst.Bin('my-bin')
+        self.textoverlay = gst.element_factory_make('textoverlay')
+        bin.add(self.textoverlay)
+        pad = self.textoverlay.get_pad("video_sink")
+        ghostpad = gst.GhostPad("sink", pad)
+        bin.add_pad(ghostpad)
+        color = gst.element_factory_make('ffmpegcolorspace')
+        bin.add(color)
+        scale = gst.element_factory_make('videoscale')
+        bin.add(scale)
+        self.videosink = gst.element_factory_make('autovideosink')
+        bin.add(self.videosink)
+        gst.element_link_many(self.textoverlay, color, scale, self.videosink)
+        self.player = gst.element_factory_make("playbin", "player")
+        self.player.set_property("video-sink", bin)
+        self.videowidget = videowidget
 
-		bus = self.player.get_bus()
-		bus.enable_sync_message_emission()
-		bus.add_signal_watch()
-		bus.connect('sync-message::element', self.on_sync_message)
-		bus.connect('message', self.on_message)
-		self.cur_frame = 0
-		
-	def on_sync_message(self, bus, message):
-		if message.structure is None:
-			return
-		if message.structure.get_name() == 'prepare-xwindow-id':
-			self.videowidget.set_sink(message.src)
-			message.src.set_property('force-aspect-ratio', True)
+        bus = self.player.get_bus()
+        bus.enable_sync_message_emission()
+        bus.add_signal_watch()
+        bus.connect('sync-message::element', self.on_sync_message)
+        bus.connect('message', self.on_message)
+        self.cur_frame = 0
+        
+    def on_sync_message(self, bus, message):
+        if message.structure is None:
+            return
+        if message.structure.get_name() == 'prepare-xwindow-id':
+            self.videowidget.set_sink(message.src)
+            message.src.set_property('force-aspect-ratio', True)
 
-	def on_message(self, bus, message):
-		t = message.type
-		if t == gst.MESSAGE_ERROR:
-			err, debug = message.parse_error()
-			print "Error: %s" % err, debug
-			self.playing = False
-		elif t == gst.MESSAGE_EOS:
-			self.playing = False
+    def on_message(self, bus, message):
+        t = message.type
+        if t == gst.MESSAGE_ERROR:
+            err, debug = message.parse_error()
+            print "Error: %s" % err, debug
+            self.playing = False
+        elif t == gst.MESSAGE_EOS:
+            self.playing = False
 
-	## Set location.
-	# Set location of the source.
-	# \param location - URI of the source.
-	def set_location(self, location):
-		self.player.set_state(gst.STATE_NULL)
-		self.player.set_property('uri', location)
+    ## Set location.
+    # Set location of the source.
+    # \param location - URI of the source.
+    def set_location(self, location):
+        self.player.set_state(gst.STATE_NULL)
+        self.player.set_property('uri', location)
 
-	## Set Subtitle Text
-	# Set subtitle text to be overlayed.
-	# \param text - Text (may have pango tags) 
-	# \param font - Pango FontDescrition for the text
-	def set_subtitle_text(self, text, font=None):
-		if font:
-			self.textoverlay.set_property('subtitle-font-desc', font)
-			self.textoverlay.set_property('text', text)
+    ## Set Subtitle Text
+    # Set subtitle text to be overlayed.
+    # \param text - Text (may have pango tags) 
+    # \param font - Pango FontDescrition for the text
+    def set_subtitle_text(self, text, font=None):
+        if font:
+            self.textoverlay.set_property('subtitle-font-desc', font)
+            self.textoverlay.set_property('text', text)
 
-	## Get location.
-	# Get location of the source.
-	def get_location(self):
-		return self.player.get_property('uri')
+    ## Get location.
+    # Get location of the source.
+    def get_location(self):
+        return self.player.get_property('uri')
 
-	def query_position(self):
-		"Returns a (position, duration) tuple"
-		try:
-			position, format = self.player.query_position(gst.FORMAT_TIME)
-		except:
-			position = gst.CLOCK_TIME_NONE
+    def query_position(self):
+        "Returns a (position, duration) tuple"
+        try:
+            position, format = self.player.query_position(gst.FORMAT_TIME)
+        except:
+            position = gst.CLOCK_TIME_NONE
 
-		try:
-			duration, format = self.player.query_duration(gst.FORMAT_TIME)
-		except:
-			duration = gst.CLOCK_TIME_NONE
+        try:
+            duration, format = self.player.query_duration(gst.FORMAT_TIME)
+        except:
+            duration = gst.CLOCK_TIME_NONE
 
-		return (position, duration)
-		
-	def query_frame(self, position):
-		"Query the frame position"
-		if position != gst.CLOCK_TIME_NONE:
-			pad = self.videosink.get_pad('sink')
-			caps = pad.get_negotiated_caps()
-			if caps is not None:
-				framerate = caps[0]['framerate']
-				position = float(position)/float(1000000000)
-				self.cur_frame = (float(position)*float(framerate.num))/float(framerate.denom)
-		return self.cur_frame
+        return (position, duration)
+        
+    def query_frame(self, position):
+        "Query the frame position"
+        if position != gst.CLOCK_TIME_NONE:
+            pad = self.videosink.get_pad('sink')
+            caps = pad.get_negotiated_caps()
+            if caps is not None:
+                framerate = caps[0]['framerate']
+                position = float(position)/float(1000000000)
+                self.cur_frame = (float(position)*float(framerate.num))/float(framerate.denom)
+        return self.cur_frame
 
-	## Seek.
-	# Seek media.
-	# \param location - location to the seek.
-	def seek(self, location):
-		gst.debug("seeking to %r" % location)
-		event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
-			gst.SEEK_FLAG_FLUSH,
-			gst.SEEK_TYPE_SET, location,
-			gst.SEEK_TYPE_NONE, 0)
+    ## Seek.
+    # Seek media.
+    # \param location - location to the seek.
+    def seek(self, location):
+        gst.debug("seeking to %r" % location)
+        event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
+            gst.SEEK_FLAG_FLUSH,
+            gst.SEEK_TYPE_SET, location,
+            gst.SEEK_TYPE_NONE, 0)
 
-		res = self.player.send_event(event)
-		if res:
-			gst.info("setting new stream time to 0")
-			self.player.set_new_stream_time(0L)
-		else:
-			gst.error("seek to %r failed" % location)
+        res = self.player.send_event(event)
+        if res:
+            gst.info("setting new stream time to 0")
+            self.player.set_new_stream_time(0L)
+        else:
+            gst.error("seek to %r failed" % location)
 
-	## Pause.
-	# Media pause.
-	def pause(self):
-		gst.info("pausing player")
-		self.player.set_state(gst.STATE_PAUSED)
-		self.playing = False
+    ## Pause.
+    # Media pause.
+    def pause(self):
+        gst.info("pausing player")
+        self.player.set_state(gst.STATE_PAUSED)
+        self.playing = False
 
-	## Play.
-	# Media play.
-	def play(self):
-		gst.info("playing player")
-		self.player.set_state(gst.STATE_PLAYING)
-		self.playing = True
+    ## Play.
+    # Media play.
+    def play(self):
+        gst.info("playing player")
+        self.player.set_state(gst.STATE_PLAYING)
+        self.playing = True
 
-	## Stop
-	# Media stop.
-	def stop(self):
-		self.player.set_state(gst.STATE_NULL)
-		self.playing = False
-		gst.info("stopped player")
+    ## Stop
+    # Media stop.
+    def stop(self):
+        self.player.set_state(gst.STATE_NULL)
+        self.playing = False
+        gst.info("stopped player")
 
-	## Get state.
-	# Get current state of the media.
-	# \param timeout - time out of the operation.
-	# \raturn state of the media.
-	def get_state(self, timeout=1):
-		return self.player.get_state(timeout=timeout)
+    ## Get state.
+    # Get current state of the media.
+    # \param timeout - time out of the operation.
+    # \raturn state of the media.
+    def get_state(self, timeout=1):
+        return self.player.get_state(timeout=timeout)
 
-	## Is playing
-	# \return TRUE if media is playing.
-	def is_playing(self):
-		return self.playing
+    ## Is playing
+    # \return TRUE if media is playing.
+    def is_playing(self):
+        return self.playing
 
-	## \var playing
-	# Bool variable, TRUE - if media is playing.
+    ## \var playing
+    # Bool variable, TRUE - if media is playing.
 
-	## \var player
-	# GStreamer playerbin element.
+    ## \var player
+    # GStreamer playerbin element.
 
-	## \var videowidget
-	# GTK+ widget for video render.
+    ## \var videowidget
+    # GTK+ widget for video render.
 
 #==============================================================================
 ## VideoWidget class.
 # VideoWidget class for render video stream on GTK+ widget.
 class VideoWidget:
-	## Constructor.
-	# \param TArea - GTK+ drowing area widget.
-	def __init__(self, TArea):
-		self.Area=TArea
-		self.imagesink = None
-		self.Area.unset_flags(gtk.DOUBLE_BUFFERED)
+    ## Constructor.
+    # \param TArea - GTK+ drowing area widget.
+    def __init__(self, TArea):
+        self.Area=TArea
+        self.imagesink = None
+        self.Area.unset_flags(gtk.DOUBLE_BUFFERED)
 
-	## \var Area
-	# GTK+ drowing area widget.
+    ## \var Area
+    # GTK+ drowing area widget.
 
-	## \var imagesink
-	# Sink element for 
+    ## \var imagesink
+    # Sink element for 
 
-	def do_expose_event(self, event):
-		if self.imagesink:
-			self.imagesink.expose()
-			return False
-		else:
-			return True
+    def do_expose_event(self, event):
+        if self.imagesink:
+            self.imagesink.expose()
+            return False
+        else:
+            return True
 
-	def set_sink(self, sink):
-		assert self.Area.window.xid
-		self.imagesink = sink
-		self.imagesink.set_xwindow_id(self.Area.window.xid)
+    def set_sink(self, sink):
+        assert self.Area.window.xid
+        self.imagesink = sink
+        self.imagesink.set_xwindow_id(self.Area.window.xid)

Modified: trunk/subtle/MediaInfo.py
===================================================================
--- trunk/subtle/MediaInfo.py	2008-06-22 05:09:07 UTC (rev 15053)
+++ trunk/subtle/MediaInfo.py	2008-06-22 05:24:31 UTC (rev 15054)
@@ -1,3 +1,18 @@
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
 import os
 import pygtk
 pygtk.require('2.0')
@@ -23,34 +38,34 @@
 class MediaInfo:
 
     def __init__(self, file, uri):
-	self.media = Media()
-	self.media.source = file
-	self.media.sourceURI = uri
-	self.discover(file)
-	self.notDone = True
+        self.media = Media()
+        self.media.source = file
+        self.media.sourceURI = uri
+        self.discover(file)
+        self.notDone = True
 
     def discover(self,path):
-	d = discoverer.Discoverer(path)
-	d.connect('discovered',self.cb_discover)
-	d.discover()
+        d = discoverer.Discoverer(path)
+        d.connect('discovered',self.cb_discover)
+        d.discover()
 
     def cb_discover(self, d, ismedia):
-	if ismedia:
-	    self.media.MIME = d.mimetype
-	    if d.is_video:
-		self.media.has_video = True
-		self.media.framerate = float(d.videorate.num)/float(d.videorate.denom)
-		self.media.videoLengthNS = d.videolength
-		self.media.videoLengthS = float(d.videolength)/float(gst.MSECOND)/1000.0
-		self.media.videoCaps = d.videocaps
-		self.media.videoHeight = d.videoheight
-		self.media.videoWidth = d.videowidth
-	    if d.is_audio:
-		self.media.has_audio = True
-	    self.notDone = False
+        if ismedia:
+            self.media.MIME = d.mimetype
+            if d.is_video:
+                self.media.has_video = True
+                self.media.framerate = float(d.videorate.num)/float(d.videorate.denom)
+                self.media.videoLengthNS = d.videolength
+                self.media.videoLengthS = float(d.videolength)/float(gst.MSECOND)/1000.0
+                self.media.videoCaps = d.videocaps
+                self.media.videoHeight = d.videoheight
+                self.media.videoWidth = d.videowidth
+            if d.is_audio:
+                self.media.has_audio = True
+            self.notDone = False
 
     def poll(self):
-	return self.notDone
+        return self.notDone
 
     def getMedia(self):
-	return self.media
+        return self.media

Modified: trunk/subtle/Subtitles.py
===================================================================
--- trunk/subtle/Subtitles.py	2008-06-22 05:09:07 UTC (rev 15053)
+++ trunk/subtle/Subtitles.py	2008-06-22 05:24:31 UTC (rev 15054)
@@ -19,7 +19,7 @@
         self.start_time=None
         self.end_time=None
         self.Attributes=None
-	self.number=None
+        self.number=None
 
 #==============================================================================
     ## Check subtitle time.
@@ -54,9 +54,9 @@
     def __init__(self,FN):
         self.subs={}
         self.subKeys=[]
-	self.filename = FN
-	# TODO: Support more subtitles types
-	self.subType = "SubRip"
+        self.filename = FN
+        # TODO: Support more subtitles types
+        self.subType = "SubRip"
 
 #==============================================================================
     ## Load subtitles.
@@ -76,22 +76,22 @@
     # \param FN - file name.
     # \param format - the store format of subtitles. (NOT USED YET)
     def subSave(self, FN, format):
-	FUN=os.open(FN,os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
-	N=1
-	for i in self.subKeys:
-	    SUB = self.subs[int(i)]
-	    Text=str(N)+"\r\n"
-	    Hour, Min, Sec, MSec = self._subTime2SRTtime(SUB.start_time)
-	    Text+="%02d:%02d:%02d,%03d"%(Hour, Min, Sec, MSec)
-	    Text+=" --> "
-	    Hour, Min, Sec, MSec = self._subTime2SRTtime(SUB.end_time)
-	    Text+="%02d:%02d:%02d,%03d"%(Hour, Min, Sec, MSec)+"\r\n"
-	    Text+=SUB.text+"\r\n"
-	    if (SUB.text[-2]!="\r\n"):
-		Text+="\r\n"
-	    os.write(FUN, Text)
-	    N+=1
-	os.close(FUN)
+        FUN=os.open(FN,os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
+        N=1
+        for i in self.subKeys:
+            SUB = self.subs[int(i)]
+            Text=str(N)+"\r\n"
+            Hour, Min, Sec, MSec = self._subTime2SRTtime(SUB.start_time)
+            Text+="%02d:%02d:%02d,%03d"%(Hour, Min, Sec, MSec)
+            Text+=" --> "
+            Hour, Min, Sec, MSec = self._subTime2SRTtime(SUB.end_time)
+            Text+="%02d:%02d:%02d,%03d"%(Hour, Min, Sec, MSec)+"\r\n"
+            Text+=SUB.text+"\r\n"
+            if (SUB.text[-2]!="\r\n"):
+                Text+="\r\n"
+            os.write(FUN, Text)
+            N+=1
+        os.close(FUN)
 
 #==============================================================================
     ## Convert subtitle time to SRT format.
@@ -113,7 +113,7 @@
     # Load SRT formated subtitles from given string.
     # \param DATA - string of SRT subtitles.
     def _subSRTLoadFromString(self, DATA):
-	num_sub = 0
+        num_sub = 0
         if (string.find(DATA, "\r\n")==-1):
             DATA=string.split(DATA,"\n")
         else:
@@ -140,11 +140,11 @@
             ET=int(Timing[17:19])*3600000+int(Timing[20:22])*60000+int(Timing[23:25])*1000+int(Timing[26:29])
             
             TS=Sub()
-	    num_sub += 1
+            num_sub += 1
             TS.text=Text
             TS.start_time=ST
             TS.end_time=ET
-	    TS.number = num_sub
+            TS.number = num_sub
             self.subs[int(ST)]=TS
         self.updateKeys()
 
@@ -184,10 +184,10 @@
     ## Update sub text.
     # Update text for sub.
     def updateText(self, key, text):
-	if key in self.subs.keys():
-	    self.subs[key].text = text
-	else:
-	    print "Subkey %s not found" % key
+        if key in self.subs.keys():
+            self.subs[key].text = text
+        else:
+            print "Subkey %s not found" % key
 
 #==============================================================================
     ## Update subtitle.
@@ -223,4 +223,4 @@
     # Get subtitle supported types
     # \return supported subtitle types 
     def getSupportedTypes(self):
-	return [".srt"]
+        return [".srt"]



More information about the commits mailing list