]> git.parisson.com Git - telemeta.git/commitdiff
Fixed parsing of kdenlive files for new version of kdenlive
authorGael Le Mignot <gael@pilotsystems.net>
Fri, 13 Dec 2019 13:37:16 +0000 (14:37 +0100)
committerGael Le Mignot <gael@pilotsystems.net>
Fri, 13 Dec 2019 13:37:16 +0000 (14:37 +0100)
telemeta/util/kdenlive/session.py

index 909e2bbb39e9b698abfa865af2d84d63e8f90767..bb040d0087ebe664665efe048d06778205748d7a 100644 (file)
@@ -54,7 +54,7 @@ class KDEnLiveSession(object):
     def video_entries(self):
         entries = []
         for attr in self.session['children']:
-            if 'playlist' in attr['name'] and 'children' in attr:
+            if 'playlist' in attr['name'] and 'children' in attr and not 'main' in attr['attributes']['id']:
                 for att in attr['children']:
                     if 'entry' in att['name'] and att['attributes']['producer'] != 'black' \
                             and not 'audio' in att['attributes']['producer']:
@@ -65,23 +65,22 @@ class KDEnLiveSession(object):
         return sorted(self.entries(), key=lambda k: int(k['in']), reverse=False)
 
     def entries_video_seconds(self):
-        fps = float(self.profile()['frame_rate_num'])/1000
+        profile = self.profile()
+        fps = float(profile['frame_rate_num'])/float(profile['frame_rate_den'])
         #fps= 25
-        list = []
+        res = []
+        start = 0
         entries = self.video_entries()
-        for i in range(0,len(entries)):
-            id = entries[i]['producer'].split('_')[0]
-            t_in = int(entries[i]['in'])/fps
-            t_out = int(entries[i]['out'])/fps
-
-            if i == 0:
-                t = 0
-            else:
-                t = list[i-1]['t'] + int(entries[i-1]['out'])/fps - int(entries[i-1]['in'])/fps
 
-            list.append({'id' : id, 't': t, 'in': t_in , 'out': t_out })
-
-        return list
+        for entry in entries:
+            id = entry['producer'].split('_')[0]
+            t_in = int(entry['in'])/fps
+            t_out = int(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 })
+            start = end
+        return res
 
     def cuts(self, entries):
         i = 0
@@ -131,17 +130,18 @@ class KDEnLiveSession(object):
                         name = att['attributes']['name']
                         if 'marker' in name:
                             name = name.encode('utf8')
-                            print(name)
                             marker_time = float(name.split(':')[-1].replace(',','.').replace(' ', ''))
-                            id = name.split(':')[-2].split('.')[-1]
+                            id = str(name.split(':')[-2].split('.')[-1])
                             rel_time = 0
 
                             for entry in entries:
-                                if marker_time >= entry['in'] and marker_time <= entry['out'] and id == entry['id']:
+                                if entry['in'] <= marker_time <= entry['out'] and id == entry['id']:
                                     if i == 0 and from_first_marker:
                                         abs_time = entry['t']
                                     rel_time = entry['t'] + (marker_time - entry['in']) - abs_time + offset
                                     break
+                            else:
+                                continue
 
                             marker['time'] = rel_time
                             marker['session_timecode'] = time.strftime('%H:%M:%S', time.gmtime(rel_time))