| 475 | |
| 476 | |
| 477 | def validate_args(args: argparse.Namespace) -> None: |
| 478 | if args.vlc_mode: |
| 479 | logger.setLevel(logging.CRITICAL) |
| 480 | if args.reference is None: |
| 481 | if args.apply_offset_seconds == 0 or not args.srtin: |
| 482 | raise ValueError( |
| 483 | "`reference` required unless `--apply-offset-seconds` specified" |
| 484 | ) |
| 485 | if args.apply_offset_seconds != 0: |
| 486 | if not args.srtin: |
| 487 | args.srtin = [args.reference] |
| 488 | if not args.srtin: |
| 489 | raise ValueError( |
| 490 | "at least one of `srtin` or `reference` must be specified to apply offset seconds" |
| 491 | ) |
| 492 | if args.srtin: |
| 493 | if len(args.srtin) > 1 and not args.overwrite_input: |
| 494 | raise ValueError( |
| 495 | "cannot specify multiple input srt files without overwriting" |
| 496 | ) |
| 497 | if len(args.srtin) > 1 and args.make_test_case: |
| 498 | raise ValueError("cannot specify multiple input srt files for test cases") |
| 499 | if len(args.srtin) > 1 and args.gui_mode: |
| 500 | raise ValueError("cannot specify multiple input srt files in GUI mode") |
| 501 | elif ( |
| 502 | args.reference is not None |
| 503 | and not is_remote_url(args.reference) # can't list a remote dir for sibling srts |
| 504 | and args.extract_subs_from_stream is None |
| 505 | and not args.gui_mode |
| 506 | and not args.make_test_case |
| 507 | and sys.stdin.isatty() # don't hijack subtitles piped in on stdin |
| 508 | ): |
| 509 | # No input subtitles were given (and nothing is piped in), so look for |
| 510 | # subtitle files alongside the reference that share its name. |
| 511 | logger.info("no input srt specified; detecting input srt from reference") |
| 512 | detected = _detect_srtin_from_reference(args.reference) |
| 513 | if detected: |
| 514 | for path in detected: |
| 515 | logger.info("detected input srt: %s", path) |
| 516 | args.srtin = detected |
| 517 | if len(detected) > 1 and args.srtout is not None: |
| 518 | raise ValueError( |
| 519 | "detected multiple input srt files but an output file was " |
| 520 | "specified; re-run with --overwrite-input or a single input" |
| 521 | ) |
| 522 | if args.srtout is None and not args.overwrite_input: |
| 523 | args.auto_srtout = True |
| 524 | logger.info( |
| 525 | "writing synced output alongside each input as " |
| 526 | "<name>.synced.srt; pass --overwrite-input to overwrite the " |
| 527 | "input file(s) in place instead" |
| 528 | ) |
| 529 | else: |
| 530 | logger.info("no input srt detected from reference") |
| 531 | if ( |
| 532 | args.make_test_case and not args.gui_mode |
| 533 | ): # this validation not necessary for gui mode |
| 534 | if not args.srtin or args.srtout is None: |