kjk
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
import traceback
|
||||
from dataclasses import dataclass
|
||||
@@ -74,6 +76,7 @@ class PlaywrightDefaults:
|
||||
viewport_height: int = 1080
|
||||
navigation_timeout_ms: int = 90_000
|
||||
ignore_https_errors: bool = True
|
||||
ffmpeg_path: Optional[str] = None # Path to ffmpeg executable; auto-detected if None
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -101,6 +104,7 @@ class PlaywrightTool:
|
||||
- sync_playwright start/stop
|
||||
- browser launch/context creation
|
||||
- user-agent/viewport defaults
|
||||
- ffmpeg path resolution (for video recording)
|
||||
|
||||
Config overrides (top-level keys):
|
||||
- playwright.browser="chromium"
|
||||
@@ -110,6 +114,13 @@ class PlaywrightTool:
|
||||
- playwright.viewport_height=1200
|
||||
- playwright.navigation_timeout_ms=90000
|
||||
- playwright.ignore_https_errors=true
|
||||
- playwright.ffmpeg_path="/path/to/ffmpeg" (auto-detected if not set)
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
def __init__(self, config: Optional[Dict[str, Any]] = None) -> None:
|
||||
@@ -162,6 +173,32 @@ class PlaywrightTool:
|
||||
|
||||
ignore_https = bool(_get("ignore_https_errors", defaults.ignore_https_errors))
|
||||
|
||||
# Try to find ffmpeg: config override, environment variable, bundled, then system
|
||||
ffmpeg_path: Optional[str] = None
|
||||
config_ffmpeg = _get("ffmpeg_path", None)
|
||||
if config_ffmpeg:
|
||||
ffmpeg_path = str(config_ffmpeg).strip()
|
||||
else:
|
||||
# Check environment variable (supports project ffmpeg)
|
||||
env_ffmpeg = os.environ.get("PLAYWRIGHT_FFMPEG_PATH")
|
||||
if env_ffmpeg:
|
||||
ffmpeg_path = env_ffmpeg
|
||||
else:
|
||||
# Try to find bundled ffmpeg in the project (if available)
|
||||
try:
|
||||
repo_root = Path(__file__).resolve().parent.parent
|
||||
bundled_ffmpeg = repo_root / "MPV" / "ffmpeg" / "bin"
|
||||
if bundled_ffmpeg.exists():
|
||||
ffmpeg_exe = bundled_ffmpeg / ("ffmpeg.exe" if os.name == "nt" else "ffmpeg")
|
||||
if ffmpeg_exe.exists():
|
||||
ffmpeg_path = str(ffmpeg_exe)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Try system ffmpeg if bundled not found
|
||||
if not ffmpeg_path:
|
||||
ffmpeg_path = shutil.which("ffmpeg")
|
||||
|
||||
return PlaywrightDefaults(
|
||||
browser=browser,
|
||||
headless=headless,
|
||||
@@ -170,6 +207,7 @@ class PlaywrightTool:
|
||||
viewport_height=vh,
|
||||
navigation_timeout_ms=nav_timeout,
|
||||
ignore_https_errors=ignore_https,
|
||||
ffmpeg_path=ffmpeg_path,
|
||||
)
|
||||
|
||||
def require(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user