Fix converting paths to URIs
authorAntonio Ospite <ao2@ao2.it>
Sun, 27 Nov 2016 15:05:47 +0000 (16:05 +0100)
committerAntonio Ospite <ao2@ao2.it>
Sun, 27 Nov 2016 18:23:00 +0000 (19:23 +0100)
In particular this fixes adding clips with a filename which has to be
quoted when becoming part of a URI, like sample_F#5.mkv

examples/ges-simple-player.py
vidi-player.py
vidi/Timeline.py

index bfcf330..c7946c0 100755 (executable)
@@ -38,7 +38,7 @@ def play_clip(video_path):
     timeline = GES.Timeline.new_audio_video()
     layer = timeline.append_layer()
 
-    video_uri = "file://" + video_path
+    video_uri = Gst.filename_to_uri(video_path)
     asset = GES.UriClipAsset.request_sync(video_uri)
     clip = layer.add_asset(asset, 0, 0, asset.get_duration(), GES.TrackType.UNKNOWN)
 
index dbd5a75..04c8941 100755 (executable)
@@ -65,9 +65,9 @@ def timeline_from_midi(midi_file, video_font_path):
             print("Note name: %s start_time: %f duration: %f" %
                   (note.name, start_time, duration))
 
-            video_sample_uri = "file://%s/sample_%s.mkv" % (video_font_path, note.name)
+            video_sample_path = "%s/sample_%s.mkv" % (video_font_path, note.name)
 
-            timeline.add_clip(video_sample_uri, start_time, duration)
+            timeline.add_clip(video_sample_path, start_time, duration)
 
     return timeline
 
@@ -103,8 +103,7 @@ def main():
     timeline = timeline_from_midi(midi_file, video_font_path)
 
     if len(sys.argv) > 3:
-        destination_uri = 'file://' + os.path.realpath(sys.argv[3])
-        timeline.save(destination_uri)
+        timeline.save(sys.argv[3])
     else:
         timeline.play()
 
index 48c6181..43bb9c9 100755 (executable)
@@ -43,7 +43,8 @@ class Timeline(object):
 
         self.layer = self.timeline.append_layer()
 
-    def add_clip(self, clip_uri, start_time, duration):
+    def add_clip(self, clip_path, start_time, duration):
+        clip_uri = Gst.filename_to_uri(clip_path)
         asset = GES.UriClipAsset.request_sync(clip_uri)
         self.layer.add_asset(asset, start_time * Gst.SECOND, 0,
                              duration * Gst.SECOND, GES.TrackType.UNKNOWN)
@@ -55,5 +56,6 @@ class Timeline(object):
         ges_pipeline.set_timeline(self.timeline)
         Player(ges_pipeline).play()
 
-    def save(self, uri):
+    def save(self, path):
+        uri = Gst.filename_to_uri(path)
         self.project.save(self.timeline, uri, None, False)