[xiph-commits] r15089 - in trunk/subtle: . Subtitles

jmesquita at svn.xiph.org jmesquita at svn.xiph.org
Sun Jun 29 09:51:17 PDT 2008


Author: jmesquita
Date: 2008-06-29 09:51:17 -0700 (Sun, 29 Jun 2008)
New Revision: 15089

Modified:
   trunk/subtle/MediaInfo.py
   trunk/subtle/Subtitles/Discoverer.py
   trunk/subtle/Subtle.py
Log:
* MediaInfo.py, Subtle.py : Enhance the way we detect media and throw message box when we do not support it
* Subtitles/Discoverer.py : Add a few more TODOs to the TODO list.

Modified: trunk/subtle/MediaInfo.py
===================================================================
--- trunk/subtle/MediaInfo.py	2008-06-29 11:39:27 UTC (rev 15088)
+++ trunk/subtle/MediaInfo.py	2008-06-29 16:51:17 UTC (rev 15089)
@@ -54,15 +54,17 @@
             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.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.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
+        self.notDone = False
 
     def poll(self):
         return self.notDone

Modified: trunk/subtle/Subtitles/Discoverer.py
===================================================================
--- trunk/subtle/Subtitles/Discoverer.py	2008-06-29 11:39:27 UTC (rev 15088)
+++ trunk/subtle/Subtitles/Discoverer.py	2008-06-29 16:51:17 UTC (rev 15089)
@@ -29,6 +29,8 @@
         supported.
     """
     extension = os.path.splitext(file)[1]
+    # TODO: For text based files we should check using
+    ## regex , not extensions
     if extension == ".srt":
         return SubRip(file)
     return None

Modified: trunk/subtle/Subtle.py
===================================================================
--- trunk/subtle/Subtle.py	2008-06-29 11:39:27 UTC (rev 15088)
+++ trunk/subtle/Subtle.py	2008-06-29 16:51:17 UTC (rev 15089)
@@ -502,26 +502,65 @@
 
 
     def cb_openMediaOpen(self, widget):
-        # TODO: Change the way we check if it is a subtitle file
-        # or if it is a media file
+        """
+            Callback to open a file
+            We do not add filters here because we
+            want to make subtle as dynamic as possible
+            and the number of supported files is too big and
+            sometimes not extensions based
+        """
         WND=self.windowMediaOpen.get_widget("OPEN_MEDIA")
         FN=WND.get_filename()
         URI=WND.get_uri()
         self.TEST_SUB_URI = URI
         WND.hide()
 
-        extension = os.path.splitext(FN)[1]
-        if extension == ".srt":
-            #TODO: We should improve the way we check subtitles
-            tmpSub = Discoverer.discoverer(FN)
+        tmpSub = Discoverer.discoverer(FN)
+        if tmpSub:
             self.Subtitle = tmpSub
             self.Subtitles.append(tmpSub)
             self.updateStreamWindow()
         else:
-            #TODO: Check if it is media or throw error
             MI = MediaInfo(FN, URI)
             # Lets poll for information
             gobject.timeout_add(30, self.addMedia, MI)
+    
+    def addMedia(self, mInfo):
+        """
+            This is polled untill a media file discover process
+            has ended. When it has, throw error to the user if not
+            supported.
+        """
+        if not mInfo:
+            return
+        # First, wait for media discovery 
+        if mInfo.poll():
+            return True 
+        mInfo = mInfo.getMedia()
+        if mInfo.MIME:
+            self.media.append(mInfo)
+            self.updateStreamWindow()
+            #Set videoWidget sizes according to media standards
+            self.videoWidget.set_size_request(mInfo.videoWidth, \
+                                                mInfo.videoHeight)
+            self.videoWidgetGst=VideoWidget(self.videoWidget)
+            self.player=GstPlayer(self.videoWidgetGst)
+            self.player.set_location("file://"+mInfo.source)
+            if self.videoWidget.flags() & gtk.REALIZED:
+                self.play_toggled()
+            else:
+                self.videoWidget.connect_after('realize',
+                                           lambda *x: self.play_toggled())
+        else:
+            errorDialog = gtk.MessageDialog(self.windowMainWindow, \
+                                            gtk.DIALOG_MODAL, \
+                                            gtk.MESSAGE_ERROR, \
+                                            gtk.BUTTONS_CLOSE, \
+                                            "This file format is not supported.")
+            result = errorDialog.run()
+            if (result == gtk.RESPONSE_CLOSE):
+                errorDialog.destroy()
+        return
 
 
     def cb_addNewStream(self, widget):
@@ -840,29 +879,6 @@
             WND.show()
         return
 
-
-    def addMedia(self, mInfo):
-        if not mInfo:
-            return
-        # Frist, wait for media discovery 
-        if mInfo.poll():
-            return True 
-        mInfo = mInfo.getMedia()
-        self.media.append(mInfo)
-        self.updateStreamWindow()
-        #Set videoWidget sizes according to media standards
-        self.videoWidget.set_size_request(mInfo.videoWidth, mInfo.videoHeight)
-        self.videoWidgetGst=VideoWidget(self.videoWidget)
-        self.player=GstPlayer(self.videoWidgetGst)
-        self.player.set_location("file://"+mInfo.source)
-        if self.videoWidget.flags() & gtk.REALIZED:
-            self.play_toggled()
-        else:
-            self.videoWidget.connect_after('realize',
-                                       lambda *x: self.play_toggled())
-        return
-
-
     def play_toggled(self):
         if self.player.is_playing():
             if self.player.get_rate() != 1.0:



More information about the commits mailing list