Implemeneted direct reading session data with PTSL

This commit is contained in:
Jamie Hardt
2023-07-21 12:33:59 -07:00
parent 617f34a515
commit 58277367c5
6 changed files with 42 additions and 17 deletions

Binary file not shown.

View File

@@ -2,7 +2,7 @@
Parse and convert Pro Tools text exports Parse and convert Pro Tools text exports
""" """
__version__ = '1.0.7' __version__ = '1.1.0'
__author__ = 'Jamie Hardt' __author__ = 'Jamie Hardt'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = "%s %s (c) 2023 %s. All rights reserved." % (__name__, __version__, __author__) __copyright__ = "%s %s (c) 2023 %s. All rights reserved." % (__name__, __version__, __author__)

View File

@@ -30,7 +30,7 @@ def dump_formats():
def main(): def main():
"""Entry point for the command-line invocation""" """Entry point for the command-line invocation"""
parser = OptionParser() parser = OptionParser()
parser.usage = "ptulsconv [options] TEXT_EXPORT.txt" parser.usage = "ptulsconv [options] [TEXT_EXPORT.txt]"
parser.add_option('-f', '--format', parser.add_option('-f', '--format',
dest='output_format', dest='output_format',
@@ -85,15 +85,17 @@ def main():
elif options.show_formats: elif options.show_formats:
dump_formats() dump_formats()
sys.exit(0) sys.exit(0)
if len(args) < 2:
print_fatal_error("Error: No input file")
parser.print_help(sys.stderr)
sys.exit(22)
try: try:
major_mode = options.output_format major_mode = options.output_format
convert(input_file=args[1], major_mode=major_mode, warnings=options.warnings)
if len(args) < 2:
print_status_style("No input file provided, will connect to Pro Tools with PTSL...")
convert(major_mode=major_mode,
warnings=options.warnings)
else:
convert(input_file=args[1],
major_mode=major_mode,
warnings=options.warnings)
except FileNotFoundError as e: except FileNotFoundError as e:
print_fatal_error("Error trying to read input file") print_fatal_error("Error trying to read input file")

View File

@@ -11,6 +11,8 @@ import csv
from typing import List from typing import List
from fractions import Fraction from fractions import Fraction
import ptsl
from .docparser.adr_entity import make_entities from .docparser.adr_entity import make_entities
from .reporting import print_section_header_style, print_status_style, print_warning from .reporting import print_section_header_style, print_status_style, print_warning
from .validations import * from .validations import *
@@ -154,7 +156,7 @@ def create_adr_reports(lines: List[ADRLine], tc_display_format: TimecodeFormat,
output_talent_sides(lines, tc_display_format=tc_display_format) output_talent_sides(lines, tc_display_format=tc_display_format)
def convert(input_file, major_mode, output=sys.stdout, warnings=True): def convert(major_mode, input_file = None, output=sys.stdout, warnings=True):
""" """
Primary worker function, accepts the input file and decides Primary worker function, accepts the input file and decides
what to do with it based on the `major_mode`. what to do with it based on the `major_mode`.
@@ -162,7 +164,24 @@ def convert(input_file, major_mode, output=sys.stdout, warnings=True):
:param input_file: a path to the input file. :param input_file: a path to the input file.
:param major_mode: the selected output mode, 'raw', 'tagged' or 'doc'. :param major_mode: the selected output mode, 'raw', 'tagged' or 'doc'.
""" """
session = parse_document(input_file) session_text = ""
if input_file is not None:
with open(input_file, "r") as file:
session_text = file.read()
else:
with ptsl.open_engine(
company_name="The ptulsconv developers",
application_name="ptulsconv") as engine:
req = engine.export_session_as_text()
req.utf8_encoding()
req.include_track_edls()
req.include_markers()
req.time_type("tc")
req.dont_show_crossfades()
req.selected_tracks_only()
session_text = req.export_string()
session = parse_document(session_text)
session_tc_format = session.header.timecode_format session_tc_format = session.header.timecode_format
if major_mode == 'raw': if major_mode == 'raw':

View File

@@ -79,15 +79,14 @@ protools_text_export_grammar = Grammar(
""") """)
def parse_document(path: str) -> SessionDescriptor: def parse_document(session_text: str) -> SessionDescriptor:
""" """
Parse a Pro Tools text export. Parse a Pro Tools text export.
:param path: path to a file :param session_text: Pro Tools session text export
:return: the session descriptor :return: the session descriptor
""" """
with open(path, 'r') as f: ast = protools_text_export_grammar.parse(session_text)
ast = protools_text_export_grammar.parse(f.read()) return DocParserVisitor().visit(ast)
return DocParserVisitor().visit(ast)
class DocParserVisitor(NodeVisitor): class DocParserVisitor(NodeVisitor):

View File

@@ -25,7 +25,12 @@ requires-python = ">=3.7"
dynamic = ["version", "description"] dynamic = ["version", "description"]
keywords = ["text-processing", "parsers", "film", keywords = ["text-processing", "parsers", "film",
"broadcast", "editing", "editorial"] "broadcast", "editing", "editorial"]
dependencies = ['parsimonious', 'tqdm', 'reportlab'] dependencies = [
'parsimonious',
'tqdm',
'reportlab',
'py-ptsl >= 101.1.0'
]
[project.optional-dependencies] [project.optional-dependencies]
doc = [ doc = [