From 707f63dc5e1c085744b4561042e614eb09761867 Mon Sep 17 00:00:00 2001 From: Gael Le Mignot Date: Fri, 13 Dec 2019 14:37:16 +0100 Subject: [PATCH] Fixed parsing of kdenlive files for new version of kdenlive --- telemeta/util/kdenlive/session.py | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/telemeta/util/kdenlive/session.py b/telemeta/util/kdenlive/session.py index 909e2bbb..bb040d00 100644 --- a/telemeta/util/kdenlive/session.py +++ b/telemeta/util/kdenlive/session.py @@ -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)) -- 2.39.5