Skip to content

Commit 14f29f0

Browse files
committed
[youtube] Setup CONSENT cookie when needed (closes ytdl-org#28604)
1 parent b97fb2e commit 14f29f0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

youtube_dl/extractor/youtube.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,23 @@ def warn(message):
249249

250250
return True
251251

252+
def _initialize_consent(self):
253+
cookies = self._get_cookies('https://www.youtube.com/')
254+
if cookies.get('__Secure-3PSID'):
255+
return
256+
consent_id = None
257+
consent = cookies.get('CONSENT')
258+
if consent:
259+
if 'YES' in consent.value:
260+
return
261+
consent_id = self._search_regex(
262+
r'PENDING\+(\d+)', consent.value, 'consent', default=None)
263+
if not consent_id:
264+
consent_id = random.randint(100, 999)
265+
self._set_cookie('.youtube.com', 'CONSENT', 'YES+cb.20210328-17-p0.en+FX+%s' % consent_id)
266+
252267
def _real_initialize(self):
268+
self._initialize_consent()
253269
if self._downloader is None:
254270
return
255271
if not self._login():

0 commit comments

Comments
 (0)