diff --git a/core/youtube_client.py b/core/youtube_client.py index dd128f82..686c40f8 100644 --- a/core/youtube_client.py +++ b/core/youtube_client.py @@ -125,10 +125,24 @@ class YouTubeClient: # tests that bypass the orchestrator. self._engine = None + def rate_limit_policy(self): + """YouTube reads its download delay from user-tunable config + (``youtube.download_delay``, default 3s). Engine reads this + at ``register_plugin`` time, then ``set_engine`` runs and + re-applies if the config changed since instance construction.""" + from core.download_engine import RateLimitPolicy + return RateLimitPolicy( + download_concurrency=1, + download_delay_seconds=float(self._download_delay), + ) + def set_engine(self, engine): """Engine callback — gives the client access to the central thread worker + state store. Engine calls this during - ``register_plugin`` if the plugin defines it.""" + ``register_plugin`` if the plugin defines it. Worker delay + was already set from rate_limit_policy() — re-apply here so + runtime ``reload_settings`` updates take effect via the + same pathway.""" self._engine = engine engine.worker.set_delay('youtube', float(self._download_delay)) diff --git a/tests/downloads/test_youtube_pinning.py b/tests/downloads/test_youtube_pinning.py index 6c65e534..59cfb71b 100644 --- a/tests/downloads/test_youtube_pinning.py +++ b/tests/downloads/test_youtube_pinning.py @@ -149,6 +149,17 @@ def test_set_engine_configures_worker_delay(yt_client_with_engine): assert engine.worker._get_delay('youtube') == 3.0 +def test_rate_limit_policy_reflects_configured_delay(yt_client_with_engine): + """Pinning (Phase E): YouTube's rate_limit_policy() returns a + RateLimitPolicy with the configured download_delay (3s default + from `youtube.download_delay` config). Engine reads this at + register_plugin time.""" + client, _ = yt_client_with_engine + policy = client.rate_limit_policy() + assert policy.download_delay_seconds == 3.0 + assert policy.download_concurrency == 1 + + # --------------------------------------------------------------------------- # Query / cancel — engine-backed reads # ---------------------------------------------------------------------------