From b7b5e95e7c5bb1bc86cc0fc8cb0ebdea6b82b5ca Mon Sep 17 00:00:00 2001 From: victorcavero14 Date: Tue, 22 Sep 2026 22:06:18 +0200 Subject: [PATCH] fix(autopilot): send the YouTube consent cookie when checking for Shorts From the EU prod servers every /shorts/ HEAD is first a 302 to consent.youtube.com, which read as 'not a Short' and let a 53 s Short through to the pipeline. With SOCS/CONSENT set, a Short answers 200 and a regular video 303 to /watch (checked from the prod container). Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- cloud/autopilot.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f3c4ed3..52450bd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -379,7 +379,7 @@ on their socials, one a day. Paid plans only (it spends minutes unattended). clips the back catalogue) and at most 3 days old; 1 automatic job per user per 24 h; `max_minutes` per video (default 30, sent as the partial-clip `max_minutes`); YouTube Shorts are skipped (`HEAD /shorts/` answers 200 - for a Short and 303 to `/watch` for a regular video, checked on prod IPs). + for a Short and 303 to `/watch` for a regular video; the SOCS consent cookie is required, from the EU servers every request is otherwise a 302 to consent.youtube.com). - **Dedupe across the deploy handover**: two containers poll at once during a rolling deploy, so a video is claimed by INSERTing its `autopilot_runs` row (unique `user_id, video_id`) before anything is submitted. A draining diff --git a/cloud/autopilot.py b/cloud/autopilot.py index 187285b..06cc559 100644 --- a/cloud/autopilot.py +++ b/cloud/autopilot.py @@ -265,11 +265,15 @@ async def is_youtube_short(video_id: str) -> bool: """True when YouTube serves this id as a Short. ``/shorts/`` answers 200 for a Short and redirects to ``/watch`` for a - regular video. Any other answer (a consent page, a bot check) reads as - "not a Short" and the normal pipeline's own too-short gate still applies. + regular video. From the prod servers (EU) YouTube first redirects every + request to consent.youtube.com, which read as "not a Short" and let a Short + through (22-sep-2026); the SOCS/CONSENT cookies skip that page. Any other + answer (a bot check) still reads as "not a Short" and the normal + pipeline's own too-short gate applies. """ try: - async with httpx.AsyncClient(timeout=10, follow_redirects=False) as client: + async with httpx.AsyncClient(timeout=10, follow_redirects=False, + cookies={"SOCS": "CAI", "CONSENT": "YES+"}) as client: resp = await client.head(f"https://www.youtube.com/shorts/{video_id}") return resp.status_code == 200 except Exception: