mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 00:40:49 +00:00
Implemeneted direct reading session data with PTSL
This commit is contained in:
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
Parse and convert Pro Tools text exports
|
||||
"""
|
||||
|
||||
__version__ = '1.0.7'
|
||||
__version__ = '1.1.0'
|
||||
__author__ = 'Jamie Hardt'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = "%s %s (c) 2023 %s. All rights reserved." % (__name__, __version__, __author__)
|
||||
|
||||
@@ -30,7 +30,7 @@ def dump_formats():
|
||||
def main():
|
||||
"""Entry point for the command-line invocation"""
|
||||
parser = OptionParser()
|
||||
parser.usage = "ptulsconv [options] TEXT_EXPORT.txt"
|
||||
parser.usage = "ptulsconv [options] [TEXT_EXPORT.txt]"
|
||||
|
||||
parser.add_option('-f', '--format',
|
||||
dest='output_format',
|
||||
@@ -85,15 +85,17 @@ def main():
|
||||
elif options.show_formats:
|
||||
dump_formats()
|
||||
sys.exit(0)
|
||||
|
||||
if len(args) < 2:
|
||||
print_fatal_error("Error: No input file")
|
||||
parser.print_help(sys.stderr)
|
||||
sys.exit(22)
|
||||
|
||||
try:
|
||||
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:
|
||||
print_fatal_error("Error trying to read input file")
|
||||
|
||||
@@ -11,6 +11,8 @@ import csv
|
||||
from typing import List
|
||||
from fractions import Fraction
|
||||
|
||||
import ptsl
|
||||
|
||||
from .docparser.adr_entity import make_entities
|
||||
from .reporting import print_section_header_style, print_status_style, print_warning
|
||||
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)
|
||||
|
||||
|
||||
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
|
||||
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 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
|
||||
|
||||
if major_mode == 'raw':
|
||||
|
||||
@@ -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.
|
||||
:param path: path to a file
|
||||
:param session_text: Pro Tools session text export
|
||||
:return: the session descriptor
|
||||
"""
|
||||
with open(path, 'r') as f:
|
||||
ast = protools_text_export_grammar.parse(f.read())
|
||||
return DocParserVisitor().visit(ast)
|
||||
ast = protools_text_export_grammar.parse(session_text)
|
||||
return DocParserVisitor().visit(ast)
|
||||
|
||||
|
||||
class DocParserVisitor(NodeVisitor):
|
||||
|
||||
@@ -25,7 +25,12 @@ requires-python = ">=3.7"
|
||||
dynamic = ["version", "description"]
|
||||
keywords = ["text-processing", "parsers", "film",
|
||||
"broadcast", "editing", "editorial"]
|
||||
dependencies = ['parsimonious', 'tqdm', 'reportlab']
|
||||
dependencies = [
|
||||
'parsimonious',
|
||||
'tqdm',
|
||||
'reportlab',
|
||||
'py-ptsl >= 101.1.0'
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
doc = [
|
||||
|
||||
Reference in New Issue
Block a user