[pitivi] formatters: Add new playlist read-only Formatter



commit 6249b2931bc9f18c7965e5235e5e065ec122ff1b
Author: Edward Hervey <bilboed bilboed com>
Date:   Tue Apr 21 15:56:27 2009 +0200

    formatters: Add new playlist read-only Formatter
    
    I mostly did this to try another kind of formatter... and man is it easy :)
---
 pitivi/formatters/Makefile.am |    4 ++-
 pitivi/formatters/format.py   |    6 +++-
 pitivi/formatters/playlist.py |   71 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/pitivi/formatters/Makefile.am b/pitivi/formatters/Makefile.am
index b83ff30..e4010fc 100644
--- a/pitivi/formatters/Makefile.am
+++ b/pitivi/formatters/Makefile.am
@@ -3,7 +3,9 @@ formattersdir = $(libdir)/pitivi/python/pitivi/formatters
 formatters_PYTHON = \
 	__init__.py	\
 	base.py		\
-	format.py
+	format.py	\
+	etree.py	\
+	playlist.py
 
 clean-local:
 	rm -rf *.pyc *.pyo
diff --git a/pitivi/formatters/format.py b/pitivi/formatters/format.py
index 8dc43f2..a91978e 100644
--- a/pitivi/formatters/format.py
+++ b/pitivi/formatters/format.py
@@ -101,7 +101,11 @@ def list_formats():
     sequence of extensions for this format ('.' omitted).
     """
     from pitivi.formatters.etree import ElementTreeFormatter
-    return [(ElementTreeFormatter, "PiTiVi Native (XML)", ('xptv',))]
+    from pitivi.formatters.playlist import PlaylistFormatter
+    return [
+        (ElementTreeFormatter, "PiTiVi Native (XML)", ('xptv',)),
+        (PlaylistFormatter, "Playlist format", ('pls', ))
+        ]
 
 def get_formatter_for_uri(uri):
     """
diff --git a/pitivi/formatters/playlist.py b/pitivi/formatters/playlist.py
new file mode 100644
index 0000000..9d9667c
--- /dev/null
+++ b/pitivi/formatters/playlist.py
@@ -0,0 +1,71 @@
+# PiTiVi , Non-linear video editor
+#
+#       formatters/playlist.py
+#
+# Copyright (c) 2009, Edward Hervey <bilboed bilboed com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os.path
+import gst
+from pitivi.stream import AudioStream, VideoStream
+from pitivi.formatters.base import LoadOnlyFormatter
+from pitivi.timeline.track import Track
+
+class PlaylistFormatter(LoadOnlyFormatter):
+    """A simple playlist formatter"""
+
+    description = "Playlist (one uri/location per line)"
+
+    def __init__(self, *args, **kwargs):
+        LoadOnlyFormatter.__init__(self, *args, **kwargs)
+        self._uris = []
+        self._basedir = None
+
+    def _parseLine(self, ln):
+        if ln.startswith('/'):
+            # absolute path
+            return 'file://' + ln.strip()
+        return 'file://' + os.path.join(self._basedir, ln.strip())
+
+    def _parse(self, location):
+        path = location.split('file://', 1)[1]
+        self._basedir = os.path.dirname(path)
+        res = []
+        # simple list of location/uri
+        f = file(path)
+        for ln in f.readlines():
+            res.append(self._parseLine(ln))
+        self._uris = res
+
+    def _getSources(self):
+        return self._uris
+
+    def _fillTimeline(self):
+        # audio and video track
+        video = VideoStream(gst.Caps('video/x-raw-rgb; video/x-raw-yuv'))
+        track = Track(video)
+        self.project.timeline.addTrack(track)
+        audio = AudioStream(gst.Caps('audio/x-raw-int; audio/x-raw-float'))
+        track = Track(audio)
+        self.project.timeline.addTrack(track)
+        for u in self._uris:
+            if u in self.project.sources:
+                self.project.timeline.addSourceFactory(self.project.sources[u])
+
+    @classmethod
+    def canHandle(cls, uri):
+        return uri.endswith('.pls')



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]