mkv2cast.integrity

File integrity checking for mkv2cast.

Verifies source files before processing to avoid corrupted outputs. Includes: - File size stability check (for files being downloaded/copied) - Basic ffprobe validation - Optional deep decode verification

Functions

check_deep_decode(path[, log_path, ...])

Perform deep decode verification by decoding the entire video stream.

check_ffprobe_valid(path[, timeout])

Check if file is valid using ffprobe.

check_file_stable(path[, wait_seconds])

Check if file size is stable (not being written to).

file_size(path)

Get file size in bytes, returns 0 on error.

integrity_check(path[, enabled, ...])

Perform complete integrity check on a file.

run_quiet(cmd[, timeout])

Run a command quietly, return True if successful.

mkv2cast.integrity.file_size(path: Path) int[source]

Get file size in bytes, returns 0 on error.

mkv2cast.integrity.run_quiet(cmd: list, timeout: float = 10.0) bool[source]

Run a command quietly, return True if successful.

mkv2cast.integrity.check_file_stable(path: Path, wait_seconds: int = 3) bool[source]

Check if file size is stable (not being written to).

Parameters:
  • path – Path to the file.

  • wait_seconds – Number of seconds to wait between checks.

Returns:

True if file size is stable, False otherwise.

mkv2cast.integrity.check_ffprobe_valid(path: Path, timeout: float = 8.0) bool[source]

Check if file is valid using ffprobe.

Parameters:
  • path – Path to the file.

  • timeout – Timeout in seconds.

Returns:

True if ffprobe reports valid duration.

mkv2cast.integrity.check_deep_decode(path: Path, log_path: Path | None = None, progress_callback: Callable[[int, str], None] | None = None, dur_ms: int = 0) bool[source]

Perform deep decode verification by decoding the entire video stream.

This is slow but catches files that are truncated or have decode errors.

Parameters:
  • path – Path to the file.

  • log_path – Optional path to write logs.

  • progress_callback – Optional callback(pct, speed) for progress updates.

  • dur_ms – Duration in milliseconds for progress calculation.

Returns:

True if decode succeeds, False otherwise.

mkv2cast.integrity.integrity_check(path: Path, enabled: bool = True, stable_wait: int = 3, deep_check: bool = False, log_path: Path | None = None, progress_callback: Callable[[str, int, str], None] | None = None) Tuple[bool, float][source]

Perform complete integrity check on a file.

Parameters:
  • path – Path to the file to check.

  • enabled – If False, skip all checks and return True.

  • stable_wait – Seconds to wait for file size stability.

  • deep_check – If True, perform full decode verification.

  • log_path – Optional path to write logs.

  • progress_callback – Optional callback(stage, pct, message) for UI updates.

Returns:

Tuple of (success, elapsed_seconds).