2021-11-05 09:30:49 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-09-09 12:09:55 +00:00
|
|
|
from __future__ import division
|
|
|
|
|
|
|
|
import lxml
|
|
|
|
import lxml.etree
|
|
|
|
import ox
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
fps = 25
|
|
|
|
tree = lxml.etree.parse(sys.argv[1])
|
|
|
|
source = sys.argv[1]
|
|
|
|
target = '%s.json' % os.path.splitext(source)[0]
|
|
|
|
data = {
|
|
|
|
'descriptions': [],
|
|
|
|
'transcripts': []
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
_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 = '<br>\n'.join([v.strip() for v in value.strip().split('\r')])
|
|
|
|
data['transcripts'].append({
|
|
|
|
'in': _start/fps, 'out': (_end-1)/fps, 'value': value
|
|
|
|
})
|
|
|
|
|
|
|
|
_last = 0
|
|
|
|
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
|
2021-11-05 09:30:49 +00:00
|
|
|
_out = int(g.findall('out')[0].text) / fps
|
2018-09-09 12:09:55 +00:00
|
|
|
_start = int(g.findall('start')[0].text) / fps
|
|
|
|
_end = int(g.findall('end')[0].text) / fps
|
2021-11-05 09:30:49 +00:00
|
|
|
name = g.findall('name')[0].text.strip()
|
2018-09-09 12:09:55 +00:00
|
|
|
#print _in, _out, _start, _end, name
|
|
|
|
if _start == -0.04:
|
|
|
|
_start = _last
|
|
|
|
if _end == -0.04:
|
|
|
|
_end = _start + (_out - _in)
|
|
|
|
name = name.replace('.dv', '').replace('_ ', ': ')
|
|
|
|
id = name.replace(' ', '%20')
|
2021-11-05 09:30:49 +00:00
|
|
|
value = 'Source: <a href="/%s/%.3f,%.3f">%s %s-%s</a>' % (id, _in, _out, name, ox.format_timecode(_in), ox.format_timecode(_out))
|
2018-09-09 12:09:55 +00:00
|
|
|
data['descriptions'].append({
|
|
|
|
'in': _start, 'out': _end-0.04, 'value': value
|
|
|
|
})
|
|
|
|
_last = _end
|
|
|
|
|
|
|
|
with open(target, 'w') as f:
|
|
|
|
json.dump(data, f, indent=2)
|
|
|
|
|
|
|
|
'''
|
|
|
|
import os
|
|
|
|
import ox
|
2021-11-05 09:30:49 +00:00
|
|
|
import ox.api
|
2018-09-09 12:09:55 +00:00
|
|
|
|
2021-11-05 09:30:49 +00:00
|
|
|
item = 'KFB'
|
2018-09-09 12:09:55 +00:00
|
|
|
|
2021-11-05 09:30:49 +00:00
|
|
|
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)
|
2018-09-09 12:09:55 +00:00
|
|
|
assert(r['status']['code'] == 200)
|
2021-11-05 09:30:49 +00:00
|
|
|
|
|
|
|
if data['transcripts']:
|
|
|
|
request['layer'] = 'transcripts'
|
|
|
|
request['annotations'] = data['transcripts']
|
|
|
|
r = api.addAnnotations(request)
|
2018-09-09 12:09:55 +00:00
|
|
|
assert(r['status']['code'] == 200)
|
|
|
|
'''
|