Restructure the 37 root-level Python modules into a proper package:
clipwright/{core,api,pipeline,layouts,media,integrations,tools}
- Rewrite every local import (module-level and deferred) to absolute
clipwright.<group>.<mod> form; no legacy root shims or re-exports.
- Add clipwright/core/paths.py and route fonts/assets/cookies through it.
- Entry points: uvicorn clipwright.api.app:app; jobs run as
python -m clipwright.pipeline.main; probe as -m ...quality_probe.
- child_env() appends REPO_ROOT to PYTHONPATH so the -m workers work.
- transcribe_backends: sys.modules key now clipwright.media.scene_detection.
- Tooling: root pyproject.toml (pytest pythonpath=[.], ruff), shared
requirements-test.txt, CI installs it, Docker PYTHONPATH=/app.
- Tests: all imports/fakes/source-scans repointed; new tests/test_package_layout.py
enforces no root modules, docstring-only __init__, and no legacy imports.
- Docs/comments updated for the new layout.
Backend: 744 passed, 19 skipped. Frontend lint+build green.
45 lines
2 KiB
Python
45 lines
2 KiB
Python
"""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"]
|