mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
Enhancements to output
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import ptulsconv
|
||||
import json
|
||||
import sys
|
||||
import os.path
|
||||
|
||||
def fmp_dump(data, output):
|
||||
def fmp_dump(data, input_file_name, output):
|
||||
from xml.etree.ElementTree import TreeBuilder, ElementTree, tostring
|
||||
doc = TreeBuilder(element_factory=None)
|
||||
|
||||
@@ -14,6 +15,8 @@ def fmp_dump(data, output):
|
||||
(['Reel'], 'Reel', str),
|
||||
(['PT.Clip.Start'], 'Start', str),
|
||||
(['PT.Clip.Finish'], 'Finish', str),
|
||||
(['PT.Clip.Start_Seconds'], 'Start Seconds', float),
|
||||
(['PT.Clip.Finish_Seconds'], 'Finish Seconds', float),
|
||||
(['PT.Clip.Start_Frames'], 'Start Frames', int),
|
||||
(['PT.Clip.Finish_Frames'], 'Finish Frames', int),
|
||||
(['P'], 'Priority', int),
|
||||
@@ -45,7 +48,7 @@ def fmp_dump(data, output):
|
||||
doc.end('PRODUCT')
|
||||
|
||||
doc.start('DATABASE', {'DATEFORMAT': 'MM/dd/yy', 'LAYOUT':'summary', 'TIMEFORMAT':'hh:mm:ss',
|
||||
'RECORDS': str(len(data['events'])), 'NAME': 'OUTPUT'})
|
||||
'RECORDS': str(len(data['events'])), 'NAME': os.path.basename(input_file_name)})
|
||||
doc.end('DATABASE')
|
||||
|
||||
doc.start('METADATA')
|
||||
@@ -89,22 +92,22 @@ def convert(input_file, format='fmp', start=None, end=None, output=sys.stdout):
|
||||
with open(input_file, 'r') as file:
|
||||
ast = ptulsconv.protools_text_export_grammar.parse(file.read())
|
||||
dict_parser = ptulsconv.DictionaryParserVisitor()
|
||||
raw_parsed = dict_parser.visit(ast)
|
||||
parsed = dict_parser.visit(ast)
|
||||
|
||||
tcxform = ptulsconv.transformations.TimecodeInterpreter()
|
||||
tagxform = ptulsconv.transformations.TagInterpreter()
|
||||
|
||||
parsed = tagxform.transform(tcxform.transform(raw_parsed))
|
||||
parsed = tagxform.transform(tcxform.transform(parsed))
|
||||
|
||||
if start is not None and end is not None:
|
||||
|
||||
start_fs = tcxform.convert_time(start,
|
||||
frame_rate=raw_parsed['header']['timecode_format'],
|
||||
drop_frame=raw_parsed['header']['timecode_drop_frame'])['frame_count']
|
||||
frame_rate=parsed['header']['timecode_format'],
|
||||
drop_frame=parsed['header']['timecode_drop_frame'])['frame_count']
|
||||
|
||||
end_fs = tcxform.convert_time(end,
|
||||
frame_rate=raw_parsed['header']['timecode_format'],
|
||||
drop_frame=raw_parsed['header']['timecode_drop_frame'])['frame_count']
|
||||
frame_rate=parsed['header']['timecode_format'],
|
||||
drop_frame=parsed['header']['timecode_drop_frame'])['frame_count']
|
||||
|
||||
subclipxform = ptulsconv.transformations.SubclipOfSequence(start=start_fs, end=end_fs)
|
||||
parsed = subclipxform.transform(parsed)
|
||||
@@ -112,5 +115,5 @@ def convert(input_file, format='fmp', start=None, end=None, output=sys.stdout):
|
||||
if format == 'json':
|
||||
json.dump(parsed, output)
|
||||
elif format == 'fmp':
|
||||
fmp_dump(parsed, output)
|
||||
fmp_dump(parsed, input_file, output)
|
||||
|
||||
|
||||
@@ -157,6 +157,8 @@ class TagInterpreter(Transformation):
|
||||
event['PT.Clip.Finish'] = clip['end_time']
|
||||
event['PT.Clip.Start_Frames'] = clip_start
|
||||
event['PT.Clip.Finish_Frames'] = clip['end_time_decoded']['frame_count']
|
||||
event['PT.Clip.Start_Seconds'] = clip_start / input_dict['header']['timecode_format']
|
||||
event['PT.Clip.Finish_Seconds'] = clip['end_time_decoded']['frame_count'] / input_dict['header']['timecode_format']
|
||||
transformed.append(event)
|
||||
|
||||
elif clip_tags['mode'] == 'Append':
|
||||
@@ -172,7 +174,7 @@ class TagInterpreter(Transformation):
|
||||
tags=clip_tags['tags'])
|
||||
timespan_rules.append(rule)
|
||||
|
||||
return dict(events=transformed)
|
||||
return dict(header=input_dict['header'], events=transformed)
|
||||
|
||||
def effective_timespan_tags_at_time(_, rules, time) -> dict:
|
||||
retval = dict()
|
||||
@@ -210,11 +212,15 @@ class SubclipOfSequence(Transformation):
|
||||
|
||||
def transform(self, input_dict: dict) -> dict:
|
||||
out_events = []
|
||||
offset = self.start
|
||||
offset_sec = self.start / input_dict['header']['timecode_format']
|
||||
for event in input_dict['events']:
|
||||
if self.start <= event['PT.Clip.Start_Frames'] <= self.end:
|
||||
e = event
|
||||
e['PT.Clip.Start_Frames'] = event['PT.Clip.Start_Frames'] - self.start
|
||||
e['PT.Clip.Finish_Frames'] = event['PT.Clip.Finish_Frames'] - self.start
|
||||
e['PT.Clip.Start_Frames'] = event['PT.Clip.Start_Frames'] - offset
|
||||
e['PT.Clip.Finish_Frames'] = event['PT.Clip.Finish_Frames'] - offset
|
||||
e['PT.Clip.Start_Seconds'] = event['PT.Clip.Start_Seconds'] - offset_sec
|
||||
e['PT.Clip.Finish_Seconds'] = event['PT.Clip.Finish_Seconds'] - offset_sec
|
||||
out_events.append(e)
|
||||
|
||||
return dict(events=out_events)
|
||||
|
||||
Reference in New Issue
Block a user