From 500de3286cd55a8f1d469d33cf91c0b75a6335fd Mon Sep 17 00:00:00 2001 From: j Date: Fri, 5 Nov 2021 09:29:12 +0000 Subject: [PATCH 1/2] tune fcp2srt --- fcp2srt.py | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/fcp2srt.py b/fcp2srt.py index c29b2c9..f768822 100755 --- a/fcp2srt.py +++ b/fcp2srt.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -from __future__ import division +#!/usr/bin/python3 import lxml import lxml.etree @@ -13,31 +12,42 @@ target = '%s.srt' % os.path.splitext(source)[0] fps = 25 data = [] tree = lxml.etree.parse(source) +''' +for g in tree.xpath('//clipitem//effect'): + if g.findall('effectid')[0].text == "GraphicAndType": + print (g.findall('name')[0].text) +''' -for g in tree.xpath('//generatoritem'): +for g in tree.xpath('//clipitem'): + if g.findall('name')[0].text != 'Graphic': + continue #start/end = relative position of the clip in the parent sequence. #in/out indicate the portion of the source media file to reference. _in = int(g.findall('in')[0].text) - _out = int(g.findall('out')[0].text) + _out = int(g.findall('out')[0].text) _start = int(g.findall('start')[0].text) _end = int(g.findall('end')[0].text) - effect = g.findall('effect') - assert len(effect) == 1 - for parameter in effect[0].findall('parameter'): - if parameter.findall('parameterid')[0].text == 'str': - value = parameter.findall('value')[0].text - if _start == -1 and _end == -1: - _start = _in - _end = _out - if _start == -1: - _start = 0 - #print _in, _out, _start, _end, value - value = '\n'.join([v.strip() for v in value.strip().split('\r')]) - value = value.replace('\n\n', '

\n') - data.append({ - 'in': _start/fps, 'out': (_end-1)/fps, 'value': value - }) - -with open(target, 'w') as f: + for efilter in g.findall('filter'): + value = None + for effect in efilter.findall('effect'): + if effect.findall('effectid')[0].text == 'GraphicAndType': + value = effect.findall('name')[0].text + if not value: + print(lxml.etree.tostring(effect).decode()) + print(value) + if _start == -1 and _end == -1: + _start = _in + _end = _out + if _start == -1: + _start = 0 + if value: + print('i', _in, 'o', _out, '-> s', _start, 'e', _end, 'v', value) + value = '\n'.join([v.strip() for v in value.strip().split('\r')]) + data.append({ + 'in': _start/fps, + 'out': (_end-1)/fps, + 'value': value + }) +with open(target, 'wb') as f: f.write(ox.srt.encode(data)) From 03101d00dd9a368d75f2fd5a88248c6c17c54918 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 5 Nov 2021 09:30:49 +0000 Subject: [PATCH 2/2] update fcp2json --- fcp2json.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/fcp2json.py b/fcp2json.py index eda254b..9785488 100755 --- a/fcp2json.py +++ b/fcp2json.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from __future__ import division import lxml @@ -45,10 +45,10 @@ for g in tree.xpath('//clipitem'): #in/out indicate the portion of the source media file to reference. #start/end = relative position of the clip in the parent sequence. _in = int(g.findall('in')[0].text) / fps - _out = int(g.findall('out')[0].text) / fps + _out = int(g.findall('out')[0].text) / fps _start = int(g.findall('start')[0].text) / fps _end = int(g.findall('end')[0].text) / fps - name= g.findall('name')[0].text.strip() + name = g.findall('name')[0].text.strip() #print _in, _out, _start, _end, name if _start == -0.04: _start = _last @@ -56,7 +56,7 @@ for g in tree.xpath('//clipitem'): _end = _start + (_out - _in) name = name.replace('.dv', '').replace('_ ', ': ') id = name.replace(' ', '%20') - value = 'Source: %s/%s-%s' % (id, _in, _out, name, ox.formatDuration(_in), ox.formatDuration(_out)) + value = 'Source: %s %s-%s' % (id, _in, _out, name, ox.format_timecode(_in), ox.format_timecode(_out)) data['descriptions'].append({ 'in': _start, 'out': _end-0.04, 'value': value }) @@ -68,24 +68,23 @@ with open(target, 'w') as f: ''' import os import ox +import ox.api -with open(os.path.expanduser('~/.ox/client.json')) as f: - config = json.load(f) +item = 'KFB' -api = ox.API('https://pad.ma/api/') -r = api.signin(username=config['username'], password=config['password']) -assert(r['status']['code'] == 200) -assert(r['data']['user'] != '') -for s in data['descriptions']: - s['item'] = 'BHK' - s['layer'] = 'descriptions' - print s - r = api.addAnnotation(s) +api = ox.api.signin('https://pad.ma/api/') +request = { + 'item': item, +} +if data['descriptions']: + request['layer'] = 'descriptions' + request['annotations'] = data['descriptions'] + r = api.addAnnotations(request) assert(r['status']['code'] == 200) -for s in data['transcripts']: - s['item'] = 'BHK' - s['layer'] = 'transcripts' - print s - r = api.addAnnotation(s) + +if data['transcripts']: + request['layer'] = 'transcripts' + request['annotations'] = data['transcripts'] + r = api.addAnnotations(request) assert(r['status']['code'] == 200) '''