aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2021-04-01 04:05:10 +0700
committerSergey M․ <dstftw@gmail.com>2021-04-01 04:05:10 +0700
commit14f29f087e6097feb46bdb84878924bc410a57eb (patch)
treead312deb49daf86fa24deaca611b552111c15e84
parentb97fb2edac25182ff3dcf4cb8537517a1ec9e4de (diff)
[youtube] Setup CONSENT cookie when needed (closes #28604)
-rw-r--r--youtube_dl/extractor/youtube.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index 6a92938a5..b940c0bad 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -249,7 +249,23 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
return True
+ def _initialize_consent(self):
+ 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)
+
def _real_initialize(self):
+ self._initialize_consent()
if self._downloader is None:
return
if not self._login():