67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from tools.avisynth_runner import (
|
|
AvisynthRunnerSet,
|
|
runner_set_from_env_or_bundled,
|
|
validate_runner_path,
|
|
)
|
|
from tools.console import prompt_input
|
|
|
|
|
|
def ask_ffms2_plugin_path() -> Path | None:
|
|
env_path = os.environ.get("MBT_FFMS2_PLUGIN", "").strip()
|
|
if env_path:
|
|
return _validate_plugin_path(env_path)
|
|
|
|
if not sys.stdin.isatty() or not _env_truthy("MBT_ASK_FFMS2_PLUGIN"):
|
|
return None
|
|
|
|
answer = prompt_input(
|
|
"\nFFMS2 plugin path for Avisynth LoadPlugin "
|
|
"(blank = use Avisynth autoload): "
|
|
).strip()
|
|
if not answer:
|
|
return None
|
|
return _validate_plugin_path(answer)
|
|
|
|
|
|
def _env_truthy(name: str) -> bool:
|
|
return os.environ.get(name, "").strip().lower() in {"1", "true", "yes", "y", "on"}
|
|
|
|
|
|
def _validate_plugin_path(raw_path: str) -> Path:
|
|
plugin_path = Path(raw_path.strip().strip('"')).expanduser()
|
|
if not plugin_path.is_file():
|
|
raise RuntimeError(f"FFMS2 plugin file not found: {plugin_path}")
|
|
return plugin_path.resolve()
|
|
|
|
|
|
def ask_avisynth_runners() -> AvisynthRunnerSet | None:
|
|
runners = runner_set_from_env_or_bundled()
|
|
if runners is not None:
|
|
return runners
|
|
|
|
if not sys.stdin.isatty():
|
|
return None
|
|
|
|
print(
|
|
"\nAviSynth runner is needed for validation and encoding.\n"
|
|
"Use media-batch-tools' mbt_avs_runner executable. The script first "
|
|
"looks for the bundled runner automatically. On Windows, the default is "
|
|
"64-bit mbt_avs_runner.exe; 32-bit scripts can use "
|
|
"mbt_avs_runner32.exe via a trailing #32bit marker. If you leave this "
|
|
"blank, the workspace and editable .avs files are created, but "
|
|
"validation and encoding stop."
|
|
)
|
|
answer = prompt_input(
|
|
"AviSynth runner executable path (blank = create workspace only): "
|
|
).strip()
|
|
if not answer:
|
|
return None
|
|
runner = validate_runner_path(answer)
|
|
return AvisynthRunnerSet(default=runner, runner64=runner)
|