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

Function _detect_srtin_from_reference

ffsubsync/ffsubsync.py:449–474  ·  view source on GitHub ↗

Find subtitle files that sit next to the reference and share its name. Matches ` .srt` and ` . .srt` (e.g. `movie.srt`, `movie.en.srt` for a `movie.mkv` reference) in the reference's own directory, so detection works regardless of the process's curre

(reference: str)

Source from the content-addressed store, hash-verified

447
448
449def _detect_srtin_from_reference(reference: str) -> List[str]:
450 """Find subtitle files that sit next to the reference and share its name.
451
452 Matches `<reference-stem>.srt` and `<reference-stem>.<suffix>.srt` (e.g.
453 `movie.srt`, `movie.en.srt` for a `movie.mkv` reference) in the reference&#x27;s
454 own directory, so detection works regardless of the process&#x27;s current
455 working directory. The reference itself is never returned, so this is safe
456 even when the reference is already a subtitle file.
457 """
458 reference_dir = os.path.dirname(reference) or "."
459 reference_stem = os.path.splitext(os.path.basename(reference))[0]
460 reference_abspath = os.path.abspath(reference)
461 matches = []
462 for name in sorted(os.listdir(reference_dir)):
463 stem, ext = os.path.splitext(name)
464 if ext.lower() != ".srt":
465 continue
466 if name.endswith(".synced.srt"):
467 continue # skip our own previously-synced outputs so re-runs are idempotent
468 if stem != reference_stem and not stem.startswith(reference_stem + "."):
469 continue
470 path = os.path.join(reference_dir, name)
471 if os.path.abspath(path) == reference_abspath:
472 continue
473 matches.append(path)
474 return matches
475
476
477def validate_args(args: argparse.Namespace) -> None:

Calls

no outgoing calls