From b43e9f64e3e8508a8ac183c5822e5eac601e2011 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 5 Nov 2021 09:50:32 +0000 Subject: [PATCH] keep fcp and premier version --- fcp2srt.py | 54 +++++++++++++++++++--------------------------- fcp_premier2srt.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 32 deletions(-) create mode 100755 fcp_premier2srt.py diff --git a/fcp2srt.py b/fcp2srt.py index f768822..c29b2c9 100755 --- a/fcp2srt.py +++ b/fcp2srt.py @@ -1,4 +1,5 @@ -#!/usr/bin/python3 +#!/usr/bin/env python +from __future__ import division import lxml import lxml.etree @@ -12,42 +13,31 @@ 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('//clipitem'): - if g.findall('name')[0].text != 'Graphic': - continue +for g in tree.xpath('//generatoritem'): #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 - 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: + 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: f.write(ox.srt.encode(data)) diff --git a/fcp_premier2srt.py b/fcp_premier2srt.py new file mode 100755 index 0000000..f768822 --- /dev/null +++ b/fcp_premier2srt.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 + +import lxml +import lxml.etree +import ox +import os +import json +import sys + +source = sys.argv[1] +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('//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) + _start = int(g.findall('start')[0].text) + _end = int(g.findall('end')[0].text) + + 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))