mkv2cast.watcher

Watch mode for mkv2cast.

Monitors directories for new MKV files and automatically converts them. Uses watchdog library if available, falls back to polling otherwise.

Functions

watch_directory(path, convert_callback, cfg)

Watch a directory for new MKV files and convert them.

Classes

DirectoryWatcher(watch_path, ...[, ...])

Watch a directory for new MKV files.

MKVFileHandler(convert_callback, cfg[, ...])

Handler for new MKV files.

WatchdogHandler(mkv_handler)

Watchdog event handler for MKV files.

class mkv2cast.watcher.MKVFileHandler(convert_callback: Callable[[Path], None], cfg: Config, stable_wait: int = 5)[source]

Bases: object

Handler for new MKV files.

handle_file(filepath: Path) None[source]

Handle a new or moved file.

class mkv2cast.watcher.WatchdogHandler(mkv_handler: MKVFileHandler)[source]

Bases: FileSystemEventHandler

Watchdog event handler for MKV files.

on_created(event: FileCreatedEvent) None[source]

Called when a file or directory is created.

Parameters:

event (DirCreatedEvent or FileCreatedEvent) – Event representing file/directory creation.

on_moved(event: FileMovedEvent) None[source]

Called when a file or a directory is moved or renamed.

Parameters:

event (DirMovedEvent or FileMovedEvent) – Event representing file/directory movement.

class mkv2cast.watcher.DirectoryWatcher(watch_path: Path, convert_callback: Callable[[Path], None], cfg: Config, interval: float = 5.0, recursive: bool = True)[source]

Bases: object

Watch a directory for new MKV files.

Uses watchdog if available, otherwise falls back to polling.

start() None[source]

Start watching the directory.

stop() None[source]

Stop watching.

wait() None[source]

Wait until stopped (blocks).

mkv2cast.watcher.watch_directory(path: Path, convert_callback: Callable[[Path], None], cfg: Config, interval: float = 5.0, print_fn: Callable[[str], None] | None = None) None[source]

Watch a directory for new MKV files and convert them.

This function blocks until interrupted (Ctrl+C).

Parameters:
  • path – Directory to watch.

  • convert_callback – Function to call for each new MKV file.

  • cfg – Configuration instance.

  • interval – Polling interval in seconds.

  • print_fn – Optional function to print status messages.