Skip to content

Commit c079ca8

Browse files
author
Michal Warda
committed
Route Dailymotion directly when impersonation is available
1 parent 5749b19 commit c079ca8

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

deploy/pipeline/sam-cinematic-continuous.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ SAM_CONTINUOUS_PROVIDER_CIRCUIT_COOLDOWN_SECONDS=300
5050
SAM_CONTINUOUS_PROVIDER_CIRCUIT_MAX_COOLDOWN_SECONDS=3600
5151
SAM_CONTINUOUS_SOURCE_PROVIDER_WEIGHTS=dailymotion=12,bilibili=1,youtube=0.25,vimeo=1,tiktok=1,soundcloud=1,internet_archive=1
5252
SAM_YTDLP_CONCURRENT_FRAGMENTS=4
53+
# Dailymotion's CDN is faster and more reliable direct when curl-cffi is
54+
# installed; keep the proxy pool for providers that need IP rotation.
55+
SAM_YTDLP_DIRECT_PLATFORMS=dailymotion
5356
SAM_CONTINUOUS_SOURCE_SCAN_WORKERS=4
5457
SAM_CONTINUOUS_SCANNED_HIGH_WATER=64
5558
SAM_CONTINUOUS_SOURCE_EXTRACT_WORKERS=16

pipeline/src/sam_audio_pipeline/youtube_random.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
YTDLP_CONCURRENT_FRAGMENTS = max(
5151
1, int(os.environ.get("SAM_YTDLP_CONCURRENT_FRAGMENTS", "4"))
5252
)
53+
YTDLP_DIRECT_PLATFORMS = frozenset(
54+
value.strip().lower()
55+
for value in os.environ.get("SAM_YTDLP_DIRECT_PLATFORMS", "").split(",")
56+
if value.strip()
57+
)
5358
OUTPUT_SAMPLE_RATE = 48_000
5459
MIN_SOURCE_SAMPLE_RATE = 44_100
5560
MIN_SOURCE_BITRATE_KBPS = 120.0
@@ -551,6 +556,8 @@ def _protected_proxy_configs(path: Path) -> list[Path]:
551556

552557
def _yt_dlp_proxy_args(source_platform: str, affinity_key: str = "") -> list[str]:
553558
"""Select a protected all-provider proxy without credentials in argv."""
559+
if source_platform.strip().lower() in YTDLP_DIRECT_PLATFORMS:
560+
return []
554561
if YOUTUBE_PROXY_CONFIG is None:
555562
return []
556563
path = Path(YOUTUBE_PROXY_CONFIG)

pipeline/tests/test_youtube_random.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ def test_proxy_config_is_secret_backed_and_applies_to_all_providers(
117117
]
118118

119119

120+
def test_direct_platform_bypasses_proxy_pool(tmp_path: Path, monkeypatch) -> None:
121+
config = tmp_path / "proxy.conf"
122+
config.write_text("--proxy http://user:secret@proxy.example:80\n")
123+
config.chmod(0o600)
124+
monkeypatch.setattr(youtube_random, "YOUTUBE_PROXY_CONFIG", config)
125+
monkeypatch.setattr(
126+
youtube_random,
127+
"YTDLP_DIRECT_PLATFORMS",
128+
frozenset({"dailymotion"}),
129+
)
130+
131+
assert youtube_random._yt_dlp_proxy_args("dailymotion") == []
132+
assert youtube_random._yt_dlp_proxy_args("youtube") == [
133+
"--config-locations",
134+
str(config),
135+
]
136+
137+
120138
def test_yt_dlp_transfer_args_use_bounded_fragment_concurrency(monkeypatch) -> None:
121139
monkeypatch.setattr(youtube_random, "YTDLP_CONCURRENT_FRAGMENTS", 4)
122140

0 commit comments

Comments
 (0)