dfdsf
This commit is contained in:
@@ -41,8 +41,8 @@ class PlaywrightDefaults:
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/120.0.0.0 Safari/537.36"
|
||||
)
|
||||
viewport_width: int = 1280
|
||||
viewport_height: int = 1200
|
||||
viewport_width: int = 1920
|
||||
viewport_height: int = 1080
|
||||
navigation_timeout_ms: int = 90_000
|
||||
ignore_https_errors: bool = True
|
||||
|
||||
@@ -149,6 +149,16 @@ class PlaywrightTool:
|
||||
vh = self.defaults.viewport_height if viewport_height is None else int(viewport_height)
|
||||
ihe = self.defaults.ignore_https_errors if ignore_https_errors is None else bool(ignore_https_errors)
|
||||
|
||||
# Support Playwright-native headers/user-agent.
|
||||
# If user_agent is unset/empty or explicitly set to one of these tokens,
|
||||
# we omit the user_agent override so Playwright uses its bundled Chromium UA.
|
||||
ua_value: Optional[str]
|
||||
ua_text = str(ua or "").strip()
|
||||
if not ua_text or ua_text.lower() in {"native", "playwright", "default"}:
|
||||
ua_value = None
|
||||
else:
|
||||
ua_value = ua_text
|
||||
|
||||
pw = None
|
||||
browser = None
|
||||
context = None
|
||||
@@ -164,11 +174,14 @@ class PlaywrightTool:
|
||||
headless=h,
|
||||
args=["--disable-blink-features=AutomationControlled"],
|
||||
)
|
||||
context = browser.new_context(
|
||||
user_agent=ua,
|
||||
viewport={"width": vw, "height": vh},
|
||||
ignore_https_errors=ihe,
|
||||
)
|
||||
context_kwargs: Dict[str, Any] = {
|
||||
"viewport": {"width": vw, "height": vh},
|
||||
"ignore_https_errors": ihe,
|
||||
}
|
||||
if ua_value is not None:
|
||||
context_kwargs["user_agent"] = ua_value
|
||||
|
||||
context = browser.new_context(**context_kwargs)
|
||||
page = context.new_page()
|
||||
yield page
|
||||
finally:
|
||||
|
||||
@@ -89,6 +89,11 @@ class YtDlpTool:
|
||||
def _load_defaults(self) -> YtDlpDefaults:
|
||||
cfg = self._config
|
||||
|
||||
# NOTE: `YtDlpDefaults` is a slots dataclass. Referencing defaults via
|
||||
# `YtDlpDefaults.video_format` yields a `member_descriptor`, not the
|
||||
# default string value. Use an instance for fallback defaults.
|
||||
_fallback_defaults = YtDlpDefaults()
|
||||
|
||||
tool_block = _get_nested(cfg, "tool", "ytdlp")
|
||||
if not isinstance(tool_block, dict):
|
||||
tool_block = {}
|
||||
@@ -128,8 +133,8 @@ class YtDlpTool:
|
||||
fmt_sort = _parse_csv_list(fmt_sort_val)
|
||||
|
||||
defaults = YtDlpDefaults(
|
||||
video_format=str(nested_video or video_format or YtDlpDefaults.video_format),
|
||||
audio_format=str(nested_audio or audio_format or YtDlpDefaults.audio_format),
|
||||
video_format=str(nested_video or video_format or _fallback_defaults.video_format),
|
||||
audio_format=str(nested_audio or audio_format or _fallback_defaults.audio_format),
|
||||
format_sort=fmt_sort,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user