[xiph-commits] r15086 - in trunk/subtle: . Subtitles
jmesquita at svn.xiph.org
jmesquita at svn.xiph.org
Sat Jun 28 22:57:03 PDT 2008
Author: jmesquita
Date: 2008-06-28 22:57:02 -0700 (Sat, 28 Jun 2008)
New Revision: 15086
Added:
trunk/subtle/Subtitles/Discoverer.py
Modified:
trunk/subtle/Subtitles/Sub.py
trunk/subtle/Subtitles/__init__.py
trunk/subtle/Subtle.py
Log:
Added a new discoverer function that will negotiate which subtitle format to use. I guess this would be more suitable for contributors of new scripts for new subtitle formats (MVC kinda style). This is more or less a proof of concept so far, but I guess it is not a bad option
Added: trunk/subtle/Subtitles/Discoverer.py
===================================================================
--- trunk/subtle/Subtitles/Discoverer.py (rev 0)
+++ trunk/subtle/Subtitles/Discoverer.py 2008-06-29 05:57:02 UTC (rev 15086)
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+#
+# discoverer.py
+#
+# Copyright 2008 Joao Mesquita <jmesquita at gmail.com>
+#
+# 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 3 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
+from SubRip import SubRip
+
+def discoverer(file):
+ """
+ This procedure will negotiate and return the proper subtitle class to
+ handle the specific format. If it returns None, format is not yet
+ supported.
+ """
+ extension = os.path.splitext(file)[1]
+ if extension == ".srt":
+ return SubRip(file)
+ return None
Modified: trunk/subtle/Subtitles/Sub.py
===================================================================
--- trunk/subtle/Subtitles/Sub.py 2008-06-29 04:31:06 UTC (rev 15085)
+++ trunk/subtle/Subtitles/Sub.py 2008-06-29 05:57:02 UTC (rev 15086)
@@ -58,5 +58,3 @@
## \var Attributes
# A array of attributes of subtitle. (NOT USED YET)
-
-#==============================================================================
Modified: trunk/subtle/Subtitles/__init__.py
===================================================================
--- trunk/subtle/Subtitles/__init__.py 2008-06-29 04:31:06 UTC (rev 15085)
+++ trunk/subtle/Subtitles/__init__.py 2008-06-29 05:57:02 UTC (rev 15086)
@@ -18,5 +18,5 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
-__all__=["Subtitles", "SubRip"]
+__all__=["Subtitles", "SubRip","Discoverer"]
Modified: trunk/subtle/Subtle.py
===================================================================
--- trunk/subtle/Subtle.py 2008-06-29 04:31:06 UTC (rev 15085)
+++ trunk/subtle/Subtle.py 2008-06-29 05:57:02 UTC (rev 15086)
@@ -502,6 +502,8 @@
def cb_openMediaOpen(self, widget):
+ # TODO: Change the way we check if it is a subtitle file
+ # or if it is a media file
WND=self.windowMediaOpen.get_widget("OPEN_MEDIA")
FN=WND.get_filename()
URI=WND.get_uri()
@@ -511,7 +513,7 @@
extension = os.path.splitext(FN)[1]
if extension == ".srt":
#TODO: We should improve the way we check subtitles
- tmpSub = SubRip.SubRip(FN)
+ tmpSub = Discoverer.discoverer(FN)
self.Subtitle = tmpSub
self.Subtitles.append(tmpSub)
self.updateStreamWindow()
More information about the commits
mailing list