aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbashonly <88596187+bashonly@users.noreply.github.com>2025-02-11 15:32:25 -0600
committerGitHub <noreply@github.com>2025-02-11 21:32:25 +0000
commit6ca23ffaa4663cb552f937f0b1e9769b66db11bd (patch)
treee21bd99c044f8fd0d837ad77e69454a698979a7f
parentf53553087d3fde9dcd61d6e9f98caf09db1d8ef2 (diff)
[ie/reddit] Bypass gated subreddit warning (#12335)
Closes #12331 Authored by: bashonly
-rw-r--r--yt_dlp/extractor/reddit.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/yt_dlp/extractor/reddit.py b/yt_dlp/extractor/reddit.py
index 7325e547b..d5150fd8f 100644
--- a/yt_dlp/extractor/reddit.py
+++ b/yt_dlp/extractor/reddit.py
@@ -199,6 +199,25 @@ class RedditIE(InfoExtractor):
'writesubtitles': True,
},
}, {
+ # "gated" subreddit post
+ 'url': 'https://old.reddit.com/r/ketamine/comments/degtjo/when_the_k_hits/',
+ 'info_dict': {
+ 'id': 'gqsbxts133r31',
+ 'ext': 'mp4',
+ 'display_id': 'degtjo',
+ 'title': 'When the K hits',
+ 'uploader': '[deleted]',
+ 'channel_id': 'ketamine',
+ 'comment_count': int,
+ 'like_count': int,
+ 'dislike_count': int,
+ 'age_limit': 18,
+ 'duration': 34,
+ 'thumbnail': r're:https?://.+/.+\.(?:jpg|png)',
+ 'timestamp': 1570438713.0,
+ 'upload_date': '20191007',
+ },
+ }, {
'url': 'https://www.reddit.com/r/videos/comments/6rrwyj',
'only_matching': True,
}, {
@@ -245,6 +264,15 @@ class RedditIE(InfoExtractor):
elif not traverse_obj(login, ('json', 'data', 'cookie', {str})):
raise ExtractorError('Unable to login, no cookie was returned')
+ def _real_initialize(self):
+ # Set cookie to opt-in to age-restricted subreddits
+ self._set_cookie('reddit.com', 'over18', '1')
+ # Set cookie to opt-in to "gated" subreddits
+ options = traverse_obj(self._get_cookies('https://www.reddit.com/'), (
+ '_options', 'value', {urllib.parse.unquote}, {json.loads}, {dict})) or {}
+ options['pref_gated_sr_optin'] = True
+ self._set_cookie('reddit.com', '_options', urllib.parse.quote(json.dumps(options)))
+
def _get_subtitles(self, video_id):
# Fallback if there were no subtitles provided by DASH or HLS manifests
caption_url = f'https://v.redd.it/{video_id}/wh_ben_en.vtt'