"""YouTube client selection shared by the download and the duration probe. Measured 6-sep-2026 in the prod container, same static proxy, same video: cookies + yt-dlp's authed defaults -> "Video unavailable" (no formats); cookies + mweb with a PO token, or no cookies at all -> 1080p. The explicit `default,mweb` list is what keeps those videos off the per-GB proxy. """ import pytest yt_clients = pytest.importorskip("clipwright.integrations.yt_clients") def test_hd_needs_a_pot_provider(): assert yt_clients.hd_extractor_args("", "") is None def test_hd_lists_default_and_mweb_with_the_provider(): got = yt_clients.hd_extractor_args("", "/opt/gen.js") assert got["youtube"]["player_client"] == ["default", "mweb"] assert got["youtubepot-bgutilscript"] == {"script_path": ["/opt/gen.js"]} http = yt_clients.hd_extractor_args("http://pot:4416", "/opt/gen.js") assert http["youtubepot-bgutilhttp"] == {"base_url": ["http://pot:4416"]} assert "youtubepot-bgutilscript" not in http def test_fallback_never_skips_the_webpage(): # player_skip=webpage drops the account's Data Sync ID and mweb then # cannot get its PO token: only the 360p progressive format survives. for args in (yt_clients.fallback_extractor_args("", ""), yt_clients.fallback_extractor_args("", "/opt/gen.js")): assert "player_skip" not in args["youtube"] assert "mweb" in args["youtube"]["player_client"] for dead in ("tv_embed", "android"): assert dead not in args["youtube"]["player_client"] def test_fallback_keeps_the_provider_when_configured(): assert "youtubepot-bgutilscript" in yt_clients.fallback_extractor_args("", "/x.js") assert "youtubepot-bgutilscript" not in yt_clients.fallback_extractor_args("", "") def test_lists_are_copies(): a = yt_clients.hd_extractor_args("", "/x.js")["youtube"]["player_client"] a.append("web_safari") assert yt_clients.hd_extractor_args("", "/x.js")["youtube"]["player_client"] == ["default", "mweb"]