This commit is contained in:
2026-01-30 12:04:37 -08:00
parent ab94c57244
commit e57dcf2190
6 changed files with 462 additions and 275 deletions

View File

@@ -118,9 +118,10 @@ class PlaywrightTool:
FFmpeg resolution (in order):
1. Config key: playwright.ffmpeg_path
2. Environment variable: PLAYWRIGHT_FFMPEG_PATH
3. Project bundled: MPV/ffmpeg/bin/ffmpeg[.exe]
4. System PATH: which ffmpeg
2. Environment variable: FFMPEG_PATH (global shared env)
3. Environment variable: PLAYWRIGHT_FFMPEG_PATH (legacy)
4. Project bundled: MPV/ffmpeg/bin/ffmpeg[.exe]
5. System PATH: which ffmpeg
"""
def __init__(self, config: Optional[Dict[str, Any]] = None) -> None:
@@ -158,7 +159,19 @@ class PlaywrightTool:
headless_raw = _get("headless", defaults.headless)
headless = bool(headless_raw)
ua = str(_get("user_agent", defaults.user_agent))
# Resolve user_agent configuration. Support a 'custom' token which reads
# the actual UA from `user_agent_custom` so the UI can offer a simple
# dropdown without scattering long UA strings to users by default.
ua_raw = _get("user_agent", None)
if ua_raw is None:
ua = defaults.user_agent
else:
ua_s = str(ua_raw).strip()
if ua_s.lower() == "custom":
ua_custom = _get("user_agent_custom", "")
ua = str(ua_custom).strip() or defaults.user_agent
else:
ua = ua_s
def _int(name: str, fallback: int) -> int:
raw = _get(name, fallback)
@@ -173,26 +186,35 @@ class PlaywrightTool:
ignore_https = bool(_get("ignore_https_errors", defaults.ignore_https_errors))
# Try to find ffmpeg: config override, environment variable, bundled, then system
# This checks if ffmpeg is actually available (not just the path to it)
# Try to find ffmpeg: config override, global env FFMPEG_PATH, legacy
# PLAYWRIGHT_FFMPEG_PATH, bundled, then system. This allows Playwright to
# use the shared ffmpeg path used by other tools (FFMPEG_PATH env).
ffmpeg_path: Optional[str] = None
config_ffmpeg = _get("ffmpeg_path", None)
if config_ffmpeg:
# User explicitly configured ffmpeg path
candidate = str(config_ffmpeg).strip()
if Path(candidate).exists():
if candidate and Path(candidate).exists():
ffmpeg_path = candidate
else:
debug(f"Configured ffmpeg path does not exist: {candidate}")
if not ffmpeg_path:
# Check environment variable (supports project ffmpeg)
env_ffmpeg = os.environ.get("PLAYWRIGHT_FFMPEG_PATH")
# Prefer a global FFMPEG_PATH env var (shared by tools) before Playwright-specific one
env_ffmpeg = os.environ.get("FFMPEG_PATH")
if env_ffmpeg and Path(env_ffmpeg).exists():
ffmpeg_path = env_ffmpeg
elif env_ffmpeg:
debug(f"PLAYWRIGHT_FFMPEG_PATH set but path does not exist: {env_ffmpeg}")
debug(f"FFMPEG_PATH set but path does not exist: {env_ffmpeg}")
if not ffmpeg_path:
# Backward-compatible Playwright-specific env var
env_ffmpeg2 = os.environ.get("PLAYWRIGHT_FFMPEG_PATH")
if env_ffmpeg2 and Path(env_ffmpeg2).exists():
ffmpeg_path = env_ffmpeg2
elif env_ffmpeg2:
debug(f"PLAYWRIGHT_FFMPEG_PATH set but path does not exist: {env_ffmpeg2}")
if not ffmpeg_path:
# Try to find bundled ffmpeg in the project (Windows-only, in MPV/ffmpeg/bin)
@@ -229,6 +251,77 @@ class PlaywrightTool:
ffmpeg_path=ffmpeg_path,
)
def config_schema() -> List[Dict[str, Any]]:
"""Return a schema describing editable Playwright tool defaults for the config UI.
Notes:
- `user_agent` is a dropdown with a `custom` option; put the real UA in
`user_agent_custom` when choosing `custom`.
- Viewport dimensions are offered as convenient choices.
- `ffmpeg_path` intentionally defaults to empty; Playwright will consult
a global `FFMPEG_PATH` environment variable (or fallback to bundled/system).
"""
_defaults = PlaywrightDefaults()
browser_choices = ["chromium", "firefox", "webkit"]
viewport_width_choices = [1920, 1366, 1280, 1024, 800]
viewport_height_choices = [1080, 900, 768, 720, 600]
return [
{
"key": "browser",
"label": "Playwright browser",
"default": _defaults.browser,
"choices": browser_choices,
},
{
"key": "headless",
"label": "Headless",
"default": str(_defaults.headless),
"choices": ["true", "false"],
},
{
"key": "user_agent",
"label": "User Agent",
"default": "default",
"choices": ["default", "native", "custom"],
},
{
"key": "user_agent_custom",
"label": "Custom User Agent (used when User Agent = custom)",
"default": "",
},
{
"key": "viewport_width",
"label": "Viewport width",
"default": _defaults.viewport_width,
"choices": viewport_width_choices,
},
{
"key": "viewport_height",
"label": "Viewport height",
"default": _defaults.viewport_height,
"choices": viewport_height_choices,
},
{
"key": "navigation_timeout_ms",
"label": "Navigation timeout (ms)",
"default": _defaults.navigation_timeout_ms,
},
{
"key": "ignore_https_errors",
"label": "Ignore HTTPS errors",
"default": str(_defaults.ignore_https_errors),
"choices": ["true", "false"],
},
{
"key": "ffmpeg_path",
"label": "FFmpeg path (leave empty to use global/bundled)",
"default": "",
},
]
def require(self) -> None:
"""Ensure Playwright is present; raise a helpful RuntimeError if not."""
try: