MCPcopy Create free account
hub / github.com/smacke/ffsubsync / run

Function run

ffsubsync/ffsubsync.py:686–725  ·  view source on GitHub ↗

Synchronize subtitles. ``progress_handler``, if given, is called repeatedly during reference speech extraction with a :class:`~ffsubsync.speech_transformers.ProgressInfo` describing how much of the reference audio has been processed. This lets a host application (e.g. a web UI) disp

(
    parser_or_args: Union[argparse.ArgumentParser, argparse.Namespace],
    progress_handler: Optional[Callable[[ProgressInfo], None]] = None,
)

Source from the content-addressed store, hash-verified

684
685
686def run(
687 parser_or_args: Union[argparse.ArgumentParser, argparse.Namespace],
688 progress_handler: Optional[Callable[[ProgressInfo], None]] = None,
689) -> Dict[str, Any]:
690 """Synchronize subtitles.
691
692 ``progress_handler``, if given, is called repeatedly during reference speech
693 extraction with a :class:`~ffsubsync.speech_transformers.ProgressInfo`
694 describing how much of the reference audio has been processed. This lets a
695 host application (e.g. a web UI) display sync progress. The handler is only
696 invoked for the video-reference path; exceptions it raises are logged and
697 swallowed so a buggy handler cannot abort syncing.
698 """
699 sync_was_successful = False
700 result = {
701 "retval": 0,
702 "offset_seconds": None,
703 "framerate_scale_factor": None,
704 }
705 args = validate_and_transform_args(parser_or_args)
706 if args is None:
707 result["retval"] = 1
708 return result
709 log_path, log_handler = _setup_logging(args)
710 try:
711 sync_was_successful = _run_impl(
712 args, result, progress_handler=progress_handler
713 )
714 result["sync_was_successful"] = sync_was_successful
715 return result
716 finally:
717 if log_handler is not None and log_path is not None:
718 log_handler.close()
719 logger.removeHandler(log_handler)
720 if args.make_test_case:
721 result["retval"] += make_test_case(
722 args, _npy_savename(args), sync_was_successful
723 )
724 if args.log_dir_path is None or not os.path.isdir(args.log_dir_path):
725 os.remove(log_path)
726
727
728def add_main_args_for_cli(parser: argparse.ArgumentParser) -> None:

Callers 2

mainFunction · 0.90
mainFunction · 0.85

Calls 5

_setup_loggingFunction · 0.85
_run_implFunction · 0.85
make_test_caseFunction · 0.85
_npy_savenameFunction · 0.85

Tested by

no test coverage detected