mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 17:00:46 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3718541e09 | ||
|
|
a58451d225 | ||
|
|
319ef3800d | ||
|
|
1d63234447 | ||
|
|
edb641b7ec | ||
|
|
eaf24ad6a8 | ||
|
|
6d5cd04c50 | ||
|
|
013081ef96 | ||
|
|
d57ee88bc2 | ||
|
|
d29a08dadf | ||
|
|
e806de0c1f | ||
|
|
22edecdbbf | ||
|
|
7c8a74aed9 | ||
|
|
96a4cdb612 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -102,3 +102,4 @@ venv.bak/
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.DS_Store
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
language: python
|
||||
python:
|
||||
- "3.7"
|
||||
- "3.8
|
||||
script:
|
||||
- "python -m unittest discover tests"
|
||||
install:
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
[](https://travis-ci.com/iluvcapra/ptulsconv)
|
||||
  [](https://pypi.org/project/ptulsconv/) 
|
||||
|
||||

|
||||
|
||||
# ptulsconv
|
||||
Read Pro Tools text exports and generate XML, JSON, reports
|
||||
|
||||
@@ -110,3 +113,4 @@ A clip name beginning with "&" will have its parsed clip name appended to the pr
|
||||
cues will be applied (later clips having precedence). The clips need not be touching, and the clips will be combined
|
||||
into a single row of the output. The start time of the first clip will become the start time of the row, and the finish
|
||||
time of the last clip will become the finish time of the row.
|
||||
|
||||
|
||||
24
man/ptulsconv.1
Normal file
24
man/ptulsconv.1
Normal file
@@ -0,0 +1,24 @@
|
||||
.\" Manpage for ptulsconv
|
||||
.\" Contact https://github.com/iluvcapra/ptulsconv
|
||||
.TH ptulsconv 1 "12 Feb 2020" "0.3.3" "ptulsconv man page"
|
||||
.SH NAME
|
||||
.BR "ptulsconv" " \- convert
|
||||
.IR "Avid Pro Tools" " text exports"
|
||||
.SH SYNOPSIS
|
||||
ptulsconv [OPTIONS] Export.txt
|
||||
.SH DESCRIPTION
|
||||
Description
|
||||
.SH OPTIONS
|
||||
.IP "-h, --help"
|
||||
show a help message and exit
|
||||
.TP
|
||||
.RI "-i " "TC"
|
||||
Don't output events before this timecode, and offset all remaining
|
||||
events to start at this timecode.
|
||||
.TP
|
||||
.RI "-o " "TC"
|
||||
Don't output events occurring after this timecode.
|
||||
.SH SEE ALSO
|
||||
See Also
|
||||
.SH AUTHOR
|
||||
Jamie Hardt (contact at https://github.com/iluvcapra/ptulsconv)
|
||||
@@ -2,6 +2,6 @@ from .ptuls_grammar import protools_text_export_grammar
|
||||
from .ptuls_parser_visitor import DictionaryParserVisitor
|
||||
from .transformations import TimecodeInterpreter
|
||||
|
||||
__version__ = '0.3.1'
|
||||
__version__ = '0.4.0'
|
||||
__author__ = 'Jamie Hardt'
|
||||
__license__ = 'MIT'
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from ptulsconv.commands import convert, dump_field_map
|
||||
from ptulsconv.commands import convert, dump_field_map, dump_xform_options
|
||||
from ptulsconv import __name__, __version__, __author__
|
||||
from optparse import OptionParser, OptionGroup
|
||||
from .reporting import print_status_style, print_banner_style, print_section_header_style, print_fatal_error
|
||||
import datetime
|
||||
import sys
|
||||
|
||||
import traceback
|
||||
|
||||
def main():
|
||||
parser = OptionParser()
|
||||
parser.usage = "ptulsconv TEXT_EXPORT.txt"
|
||||
@@ -21,9 +23,15 @@ def main():
|
||||
action='store_true',
|
||||
default=False, help='Display tag mappings for the FMP XML output style and exit.')
|
||||
|
||||
parser.add_option('--show-available-transforms', dest='show_transforms',
|
||||
action='store_true',
|
||||
default=False, help='Display available built-in XSLT transforms.')
|
||||
|
||||
parser.add_option('--xform', dest='xslt', help="Convert with built-is XSLT transform.",
|
||||
default=None, metavar='NAME')
|
||||
(options, args) = parser.parse_args(sys.argv)
|
||||
|
||||
print_banner_style("%s %s (c) 2019 %s. All rights reserved." % (__name__, __version__, __author__))
|
||||
print_banner_style("%s %s (c) 2020 %s. All rights reserved." % (__name__, __version__, __author__))
|
||||
|
||||
print_section_header_style("Startup")
|
||||
print_status_style("This run started %s" % (datetime.datetime.now().isoformat() ) )
|
||||
@@ -32,6 +40,10 @@ def main():
|
||||
dump_field_map('ADR')
|
||||
sys.exit(0)
|
||||
|
||||
if options.show_transforms:
|
||||
dump_xform_options()
|
||||
sys.exit(0)
|
||||
|
||||
if len(args) < 2:
|
||||
print_fatal_error("Error: No input file")
|
||||
parser.print_help(sys.stderr)
|
||||
@@ -55,7 +67,7 @@ def main():
|
||||
|
||||
try:
|
||||
convert(input_file=args[1], start=options.in_time, end=options.out_time,
|
||||
include_muted=options.include_muted,
|
||||
include_muted=options.include_muted, xsl=options.xslt,
|
||||
progress=False, output=sys.stdout, log_output=sys.stderr)
|
||||
except FileNotFoundError as e:
|
||||
print_fatal_error("Error trying to read input file")
|
||||
@@ -63,6 +75,7 @@ def main():
|
||||
except Exception as e:
|
||||
print_fatal_error("Error trying to convert file")
|
||||
print("\033[31m" + e.__repr__() + "\033[0m", file=sys.stderr)
|
||||
print(traceback.format_exc())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
from xml.etree.ElementTree import TreeBuilder, tostring
|
||||
import subprocess
|
||||
import pathlib
|
||||
import ptulsconv
|
||||
|
||||
from .reporting import print_section_header_style, print_status_style
|
||||
@@ -91,6 +94,21 @@ def fmp_dump(data, input_file_name, output):
|
||||
output.write(xmlstr)
|
||||
|
||||
|
||||
import glob
|
||||
|
||||
xslt_path = os.path.join(pathlib.Path(__file__).parent.absolute(), 'xslt')
|
||||
|
||||
def xform_options():
|
||||
return glob.glob(os.path.join(xslt_path, "*.xsl"))
|
||||
|
||||
def dump_xform_options(output=sys.stdout):
|
||||
print("# Available transforms:", file=output)
|
||||
print("# Transform dir: %s" % (xslt_path), file=output)
|
||||
for f in xform_options():
|
||||
base = os.path.basename(f)
|
||||
name, _ = os.path.splitext(base)
|
||||
print("# " + name, file=output)
|
||||
|
||||
def dump_field_map(field_map_name, output=sys.stdout):
|
||||
output.write("# Map of Tag fields to XML output columns\n")
|
||||
output.write("# (in order of precedence)\n")
|
||||
@@ -106,13 +124,28 @@ def dump_field_map(field_map_name, output=sys.stdout):
|
||||
|
||||
for n, field in enumerate(field_map):
|
||||
for tag in field[0]:
|
||||
output.write("# %-24s-> %-20s | %-8s| %-7i\n" % (tag[:24], field[1][:20], field[2].__name__, n+1 ))
|
||||
output.write("# %-24s-> %-20s | %-8s| %-7i\n" % (tag[:24], field[1][:20], field[2].__name__, n + 1))
|
||||
|
||||
|
||||
def fmp_transformed_dump(data, input_file, xsl_name, output):
|
||||
pipe = io.StringIO()
|
||||
print_status_style("Generating base XML")
|
||||
fmp_dump(data, input_file, pipe)
|
||||
|
||||
strdata = pipe.getvalue()
|
||||
print_status_style("Base XML size %i" % (len(strdata)))
|
||||
|
||||
print_status_style("Running xsltproc")
|
||||
|
||||
xsl_path = os.path.join(pathlib.Path(__file__).parent.absolute(), 'xslt', xsl_name + ".xsl")
|
||||
print_status_style("Using xsl: %s" % (xsl_path))
|
||||
result = subprocess.run(['xsltproc', xsl_path, '-'], input=strdata, text=True,
|
||||
stdout=output, shell=False, check=True)
|
||||
|
||||
|
||||
def convert(input_file, output_format='fmpxml', start=None, end=None,
|
||||
progress=False, include_muted=False,
|
||||
progress=False, include_muted=False, xsl=None,
|
||||
output=sys.stdout, log_output=sys.stderr):
|
||||
|
||||
with open(input_file, 'r') as file:
|
||||
print_section_header_style('Parsing')
|
||||
ast = ptulsconv.protools_text_export_grammar.parse(file.read())
|
||||
@@ -146,4 +179,9 @@ def convert(input_file, output_format='fmpxml', start=None, end=None,
|
||||
if output_format == 'json':
|
||||
json.dump(parsed, output)
|
||||
elif output_format == 'fmpxml':
|
||||
fmp_dump(parsed, input_file, output)
|
||||
if xsl is None:
|
||||
fmp_dump(parsed, input_file, output)
|
||||
else:
|
||||
print_section_header_style("Performing XSL Translation")
|
||||
print_status_style("Using builtin translation: %s" % (xsl))
|
||||
fmp_transformed_dump(parsed, input_file, xsl, output)
|
||||
|
||||
3
setup.py
3
setup.py
@@ -24,12 +24,13 @@ setup(name='ptulsconv',
|
||||
'Topic :: Multimedia',
|
||||
'Topic :: Multimedia :: Sound/Audio',
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Development Status :: 4 - Beta",
|
||||
"Topic :: Text Processing :: Filters",
|
||||
"Topic :: Text Processing :: Markup :: XML"],
|
||||
packages=['ptulsconv'],
|
||||
keywords='text-processing parsers film tv editing editorial',
|
||||
install_requires=['parsimonious','tqdm'],
|
||||
install_requires=['parsimonious', 'tqdm'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'ptulsconv = ptulsconv.__main__:main'
|
||||
|
||||
Reference in New Issue
Block a user