diff --git a/ptulsconv/__main__.py b/ptulsconv/__main__.py index ecc2bff..ed855f8 100644 --- a/ptulsconv/__main__.py +++ b/ptulsconv/__main__.py @@ -4,9 +4,11 @@ import sys parser = OptionParser() parser.usage = "ptulsconv TEXT_EXPORT.txt" -parser.add_option('-i', dest='in_time', help='Set in time to grab a subsequence of events. ' - 'Give value as a timecode in current session\'s rate.') -parser.add_option('-o', dest='out_time', help='Set out time to grab a subsequence of events.') +parser.add_option('-i', dest='in_time', help="Don't output events occurring before this timecode, and offset" + " all events relative to this timecode.", metavar='TC') +parser.add_option('-o', dest='out_time', help="Don't output events occurring after this timecode.", metavar='TC') +parser.add_option('-P','--progress', default=False, action='store_true', dest='show_progress', help='Show progress bar.') +parser.add_option('-m','--include-muted', default=False, action='store_true', dest='include_muted', help='Read muted clips.') if __name__ == "__main__": (options, args) = parser.parse_args(sys.argv) @@ -15,4 +17,5 @@ if __name__ == "__main__": parser.print_help(sys.stderr) exit(-1) - convert(input_file=args[1], start=options.in_time, end=options.out_time, output=sys.stdout) + convert(input_file=args[1], start=options.in_time, end=options.out_time, include_muted=options.include_muted, + progress=options.show_progress, output=sys.stdout) diff --git a/ptulsconv/commands.py b/ptulsconv/commands.py index 5a4e78b..5246c45 100644 --- a/ptulsconv/commands.py +++ b/ptulsconv/commands.py @@ -93,14 +93,14 @@ def fmp_dump(data, input_file_name, output): output.write(xmlstr) -def convert(input_file, output_format='fmpxml', start=None, end=None, output=sys.stdout): +def convert(input_file, output_format='fmpxml', start=None, end=None, progress=False, include_muted=False, output=sys.stdout): with open(input_file, 'r') as file: ast = ptulsconv.protools_text_export_grammar.parse(file.read()) dict_parser = ptulsconv.DictionaryParserVisitor() parsed = dict_parser.visit(ast) tcxform = ptulsconv.transformations.TimecodeInterpreter() - tagxform = ptulsconv.transformations.TagInterpreter() + tagxform = ptulsconv.transformations.TagInterpreter(show_progress=progress, ignore_muted=(not include_muted) ) parsed = tagxform.transform(tcxform.transform(parsed)) diff --git a/ptulsconv/transformations.py b/ptulsconv/transformations.py index a124023..ccf8a4a 100644 --- a/ptulsconv/transformations.py +++ b/ptulsconv/transformations.py @@ -121,9 +121,10 @@ class TagInterpreter(Transformation): def generic_visit(self, node, visited_children): return visited_children or node - def __init__(self, ignore_muted=True): + def __init__(self, ignore_muted=True, show_progress=False): self.visitor = TagInterpreter.TagListVisitor() self.ignore_muted = ignore_muted + self.show_progress = show_progress def transform(self, input_dict: dict) -> dict: transformed = list() @@ -132,8 +133,12 @@ class TagInterpreter(Transformation): title_tags = self.parse_tags(input_dict['header']['session_name'], "") markers = sorted(input_dict['markers'], key=lambda m: m['location_decoded']['frame_count']) + if self.show_progress: + track_iter = tqdm(input_dict['tracks'], desc="Reading tracks...", unit='Track') + else: + track_iter = input_dict['tracks'] - for track in tqdm(input_dict['tracks'], desc="Reading tracks...", unit='Track'): + for track in track_iter: if 'Muted' in track['state'] and self.ignore_muted: continue @@ -210,13 +215,18 @@ class TagInterpreter(Transformation): break return retval + def report(self, mesg, *args): + print(mesg % ( args) , file=sys.stderr) + sys.stderr.write("\033[F") + sys.stderr.write("\033[K") + def parse_tags(self, source, context_str=None): try: parse_tree = self.tag_grammar.parse(source) return self.visitor.visit(parse_tree) except IncompleteParseError as e: if context_str is not None: - print("Error reading tags in: ", context_str, file=sys.stderr) + self.report("Error reading tags in: ") trimmed_source = source[:e.pos] parse_tree = self.tag_grammar.parse(trimmed_source)