[Youtube] Update consent cookie handling to match site
authorReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com>
Wed, 15 Nov 2023 23:54:31 +0000 (18:54 -0500)
committerdirkf <fieldhouse@gmx.net>
Wed, 29 Nov 2023 21:43:02 +0000 (21:43 +0000)
Apologies for force push!
[skip ci]

youtube_dl/extractor/youtube.py

index 9c419c002222fc307d7e0260089b51955c02e28b..3bf483c1c8a7263274112f2ac858e08bbeab2da9 100644 (file)
@@ -260,16 +260,10 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
         cookies = self._get_cookies('https://www.youtube.com/')
         if cookies.get('__Secure-3PSID'):
             return
-        consent_id = None
-        consent = cookies.get('CONSENT')
-        if consent:
-            if 'YES' in consent.value:
-                return
-            consent_id = self._search_regex(
-                r'PENDING\+(\d+)', consent.value, 'consent', default=None)
-        if not consent_id:
-            consent_id = random.randint(100, 999)
-        self._set_cookie('.youtube.com', 'CONSENT', 'YES+cb.20210328-17-p0.en+FX+%s' % consent_id)
+        socs = cookies.get('SOCS')
+        if socs and not socs.value.startswith('CAA'):  # not consented
+            return
+        self._set_cookie('.youtube.com', 'SOCS', 'CAI', secure=True)  # accept all (required for mixes)
 
     def _real_initialize(self):
         self._initialize_consent()