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