Compare commits

...

2 commits

Author SHA1 Message Date
j
03101d00dd update fcp2json 2021-11-05 09:30:49 +00:00
j
500de3286c tune fcp2srt 2021-11-05 09:29:32 +00:00
2 changed files with 51 additions and 42 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import division from __future__ import division
import lxml import lxml
@ -45,10 +45,10 @@ for g in tree.xpath('//clipitem'):
#in/out indicate the portion of the source media file to reference. #in/out indicate the portion of the source media file to reference.
#start/end = relative position of the clip in the parent sequence. #start/end = relative position of the clip in the parent sequence.
_in = int(g.findall('in')[0].text) / fps _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 _start = int(g.findall('start')[0].text) / fps
_end = int(g.findall('end')[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 #print _in, _out, _start, _end, name
if _start == -0.04: if _start == -0.04:
_start = _last _start = _last
@ -56,7 +56,7 @@ for g in tree.xpath('//clipitem'):
_end = _start + (_out - _in) _end = _start + (_out - _in)
name = name.replace('.dv', '').replace('_ ', ': ') name = name.replace('.dv', '').replace('_ ', ': ')
id = name.replace(' ', '%20') id = name.replace(' ', '%20')
value = 'Source: <a href="/%s/%.3f,%.3f">%s/%s-%s</a>' % (id, _in, _out, name, ox.formatDuration(_in), ox.formatDuration(_out)) value = 'Source: <a href="/%s/%.3f,%.3f">%s %s-%s</a>' % (id, _in, _out, name, ox.format_timecode(_in), ox.format_timecode(_out))
data['descriptions'].append({ data['descriptions'].append({
'in': _start, 'out': _end-0.04, 'value': value 'in': _start, 'out': _end-0.04, 'value': value
}) })
@ -68,24 +68,23 @@ with open(target, 'w') as f:
''' '''
import os import os
import ox import ox
import ox.api
with open(os.path.expanduser('~/.ox/client.json')) as f: item = 'KFB'
config = json.load(f)
api = ox.API('https://pad.ma/api/') api = ox.api.signin('https://pad.ma/api/')
r = api.signin(username=config['username'], password=config['password']) request = {
assert(r['status']['code'] == 200) 'item': item,
assert(r['data']['user'] != '') }
for s in data['descriptions']: if data['descriptions']:
s['item'] = 'BHK' request['layer'] = 'descriptions'
s['layer'] = 'descriptions' request['annotations'] = data['descriptions']
print s r = api.addAnnotations(request)
r = api.addAnnotation(s)
assert(r['status']['code'] == 200) assert(r['status']['code'] == 200)
for s in data['transcripts']:
s['item'] = 'BHK' if data['transcripts']:
s['layer'] = 'transcripts' request['layer'] = 'transcripts'
print s request['annotations'] = data['transcripts']
r = api.addAnnotation(s) r = api.addAnnotations(request)
assert(r['status']['code'] == 200) assert(r['status']['code'] == 200)
''' '''

View file

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/python3
from __future__ import division
import lxml import lxml
import lxml.etree import lxml.etree
@ -13,31 +12,42 @@ target = '%s.srt' % os.path.splitext(source)[0]
fps = 25 fps = 25
data = [] data = []
tree = lxml.etree.parse(source) 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. #start/end = relative position of the clip in the parent sequence.
#in/out indicate the portion of the source media file to reference. #in/out indicate the portion of the source media file to reference.
_in = int(g.findall('in')[0].text) _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) _start = int(g.findall('start')[0].text)
_end = int(g.findall('end')[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: for efilter in g.findall('filter'):
_start = _in value = None
_end = _out for effect in efilter.findall('effect'):
if _start == -1: if effect.findall('effectid')[0].text == 'GraphicAndType':
_start = 0 value = effect.findall('name')[0].text
#print _in, _out, _start, _end, value if not value:
value = '\n'.join([v.strip() for v in value.strip().split('\r')]) print(lxml.etree.tostring(effect).decode())
value = value.replace('\n\n', '<br><br>\n') print(value)
data.append({ if _start == -1 and _end == -1:
'in': _start/fps, 'out': (_end-1)/fps, 'value': value _start = _in
}) _end = _out
if _start == -1:
with open(target, 'w') as f: _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)) f.write(ox.srt.encode(data))