mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
Refactoring entity creation
This commit is contained in:
@@ -7,6 +7,7 @@ import csv
|
||||
from typing import List
|
||||
|
||||
import ptulsconv
|
||||
from .docparser.adr_entity import make_entity
|
||||
from .reporting import print_section_header_style, print_status_style, print_warning
|
||||
from .validations import *
|
||||
|
||||
@@ -139,20 +140,30 @@ def convert(input_file, output_format='fmpxml', output=sys.stdout, warnings=True
|
||||
compiler = TagCompiler()
|
||||
compiler.session = session
|
||||
compiled_events = list(compiler.compile_events())
|
||||
|
||||
# TODO: Breakdown by titles
|
||||
|
||||
if output_format == 'tagged':
|
||||
output.write(MyEncoder().encode(compiled_events))
|
||||
|
||||
else:
|
||||
lines = list(map(ADRLine.from_event, compiled_events))
|
||||
events = list(map(make_entity, compiled_events))
|
||||
lines = [event for event in events if isinstance(event, ADRLine)]
|
||||
|
||||
if warnings:
|
||||
for warning in chain(validate_unique_field(lines, field='cue_number'),
|
||||
validate_non_empty_field(lines, field='cue_number'),
|
||||
validate_non_empty_field(lines, field='character_id'),
|
||||
validate_non_empty_field(lines, field='title'),
|
||||
validate_dependent_value(lines, key_field='character_id',
|
||||
for warning in chain(validate_unique_field(lines,
|
||||
field='cue_number'),
|
||||
validate_non_empty_field(lines,
|
||||
field='cue_number'),
|
||||
validate_non_empty_field(lines,
|
||||
field='character_id'),
|
||||
validate_non_empty_field(lines,
|
||||
field='title'),
|
||||
validate_dependent_value(lines,
|
||||
key_field='character_id',
|
||||
dependent_field='character_name'),
|
||||
validate_dependent_value(lines, key_field='character_id',
|
||||
validate_dependent_value(lines,
|
||||
key_field='character_id',
|
||||
dependent_field='actor_name')):
|
||||
print_warning(warning.report_message())
|
||||
|
||||
|
||||
@@ -5,9 +5,24 @@ from fractions import Fraction
|
||||
|
||||
from ptulsconv.docparser.tag_mapping import TagMapping
|
||||
|
||||
def make_entity(from_event: Event) -> Optional[object]:
|
||||
instance = GenericEvent
|
||||
tag_map = GenericEvent.tag_mapping
|
||||
if 'QN' in from_event.tags.keys():
|
||||
instance = ADRLine
|
||||
tag_map += ADRLine.tag_mapping
|
||||
|
||||
new = instance()
|
||||
TagMapping.apply_rules(tag_map, from_event.tags,
|
||||
from_event.clip_name, from_event.track_name,
|
||||
from_event.session_name, new)
|
||||
|
||||
new.start = from_event.start
|
||||
new.finish = from_event.finish
|
||||
return new
|
||||
|
||||
@dataclass
|
||||
class ADRLine:
|
||||
class GenericEvent:
|
||||
title: Optional[str]
|
||||
supervisor: Optional[str]
|
||||
client: Optional[str]
|
||||
@@ -16,24 +31,9 @@ class ADRLine:
|
||||
reel: Optional[str]
|
||||
start: Optional[Fraction]
|
||||
finish: Optional[Fraction]
|
||||
priority: Optional[int]
|
||||
cue_number: Optional[str]
|
||||
character_id: Optional[str]
|
||||
character_name: Optional[str]
|
||||
actor_name: Optional[str]
|
||||
prompt: Optional[str]
|
||||
reason: Optional[str]
|
||||
requested_by: Optional[str]
|
||||
time_budget_mins: Optional[float]
|
||||
note: Optional[str]
|
||||
spot: Optional[str]
|
||||
shot: Optional[str]
|
||||
effort: bool
|
||||
tv: bool
|
||||
tbw: bool
|
||||
omitted: bool
|
||||
adlib: bool
|
||||
optional: bool
|
||||
note: Optional[str]
|
||||
requested_by: Optional[str]
|
||||
|
||||
tag_mapping = [
|
||||
TagMapping(source='Title', target="title", alt=TagMapping.ContentSource.Session),
|
||||
@@ -42,6 +42,33 @@ class ADRLine:
|
||||
TagMapping(source="Sc", target="scene"),
|
||||
TagMapping(source="Ver", target="version"),
|
||||
TagMapping(source="Reel", target="reel"),
|
||||
TagMapping(source="Note", target="note"),
|
||||
TagMapping(source="Rq", target="requested_by"),
|
||||
TagMapping(source="OMIT", target="omitted",
|
||||
formatter=(lambda x: len(x) > 0)),
|
||||
]
|
||||
|
||||
|
||||
@dataclass
|
||||
class ADRLine(GenericEvent):
|
||||
priority: Optional[int]
|
||||
cue_number: Optional[str]
|
||||
character_id: Optional[str]
|
||||
character_name: Optional[str]
|
||||
actor_name: Optional[str]
|
||||
prompt: Optional[str]
|
||||
reason: Optional[str]
|
||||
time_budget_mins: Optional[float]
|
||||
spot: Optional[str]
|
||||
shot: Optional[str]
|
||||
effort: bool
|
||||
tv: bool
|
||||
tbw: bool
|
||||
adlib: bool
|
||||
optional: bool
|
||||
|
||||
tag_mapping = [
|
||||
|
||||
TagMapping(source="P", target="priority"),
|
||||
TagMapping(source="QN", target="cue_number"),
|
||||
TagMapping(source="CN", target="character_id"),
|
||||
@@ -49,10 +76,8 @@ class ADRLine:
|
||||
TagMapping(source="Actor", target="actor_name"),
|
||||
TagMapping(source="Line", target="prompt", alt=TagMapping.ContentSource.Clip),
|
||||
TagMapping(source="R", target="reason"),
|
||||
TagMapping(source="Rq", target="requested_by"),
|
||||
TagMapping(source="Mins", target="time_budget_mins",
|
||||
formatter=(lambda n: float(n))),
|
||||
TagMapping(source="Note", target="note"),
|
||||
TagMapping(source="Spot", target="spot"),
|
||||
TagMapping(source="Shot", target="shot"),
|
||||
TagMapping(source="EFF", target="effort",
|
||||
@@ -61,8 +86,7 @@ class ADRLine:
|
||||
formatter=(lambda x: len(x) > 0)),
|
||||
TagMapping(source="TBW", target="tbw",
|
||||
formatter=(lambda x: len(x) > 0)),
|
||||
TagMapping(source="OMIT", target="omitted",
|
||||
formatter=(lambda x: len(x) > 0)),
|
||||
|
||||
TagMapping(source="ADLIB", target="adlib",
|
||||
formatter=(lambda x: len(x) > 0)),
|
||||
TagMapping(source="OPT", target="optional",
|
||||
@@ -97,17 +121,3 @@ class ADRLine:
|
||||
self.adlib = False
|
||||
self.optional = False
|
||||
|
||||
@classmethod
|
||||
def from_event(cls, event: Event) -> Optional['ADRLine']:
|
||||
|
||||
if 'QN' not in event.tags:
|
||||
return None
|
||||
|
||||
new = cls()
|
||||
TagMapping.apply_rules(cls.tag_mapping, event.tags,
|
||||
event.clip_name, event.track_name, event.session_name, new)
|
||||
new.start = event.start
|
||||
new.finish = event.finish
|
||||
return new
|
||||
|
||||
|
||||
|
||||
1
ptulsconv/docparser/generic_entity.py
Normal file
1
ptulsconv/docparser/generic_entity.py
Normal file
@@ -0,0 +1 @@
|
||||
from dataclasses import dataclass
|
||||
Reference in New Issue
Block a user