]> git.parisson.com Git - telemeta.git/commitdiff
Added support for more recent kdeenlive files
authorGael Le Mignot <gael@pilotsystems.net>
Thu, 21 Apr 2022 09:06:03 +0000 (11:06 +0200)
committerGael Le Mignot <gael@pilotsystems.net>
Thu, 21 Apr 2022 09:06:03 +0000 (11:06 +0200)
telemeta/util/kdenlive/session.py

index 17525c61cc112182e61fbf227507d42d1c3503f4..d9ed7eb0ed02bcb4a0be5dc90bf1eb7c5c4fa018 100644 (file)
 import time
 from telemeta.util.xmltodict2 import *
 
+def parse_timestamp(value):
+    """
+    Parse a timestamp, either new HH:MM:SS.mmm format or old seconds format
+    """
+    if ':' in value:
+        if '.' in value:
+            value = value.split('.')[0]
+        comps = value.split(':')
+        comps = [ int(c) for c in comps ]
+        res = 0
+        for comp in comps:
+            res = res * 60 + comp
+    else:
+        res = int(value)
+    return res
+    
 
 class KDEnLiveSession(object):
 
@@ -74,8 +90,8 @@ class KDEnLiveSession(object):
 
         for entry in entries:
             id = entry['producer'].split('_')[0]
-            t_in = int(entry['in'])/fps
-            t_out = int(entry['out'])/fps
+            t_in = parse_timestamp(entry['in'])/fps
+            t_out = parse_timestamp(entry['out'])/fps
             t_len = t_out - t_in
             end = start + t_len
             res.append({ 'id': str(id), 't': start, 'in': t_in, 'out': t_out })
@@ -124,7 +140,7 @@ class KDEnLiveSession(object):
         title = ''
 
         for attr in self.session['children']:
-            if 'playlist' in attr['name']:
+            if 'playlist' in attr['name'] and 'children' in attr:
                 for att in attr['children']:
                     marker = {}
                     if 'name' in att['attributes']: