]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/reddit.py
[reddit] Workaround for 429 by redirecting to old.reddit.com
[yt-dlp.git] / yt_dlp / extractor / reddit.py
index 638f2b6a84bb8b488b1d9ba3e9113c1baf24f4c0..8e1463d5be9bbe3029f089157f4c66514a7d350a 100644 (file)
@@ -49,7 +49,7 @@ def _real_extract(self, url):
 
 
 class RedditRIE(InfoExtractor):
-    _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?reddit\.com/r/[^/]+/comments/(?P<id>[^/?#&]+))'
+    _VALID_URL = r'https?://(?:[^/]+\.)?reddit\.com/r/(?P<slug>[^/]+/comments/(?P<id>[^/?#&]+))'
     _TESTS = [{
         'url': 'https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/',
         'info_dict': {
@@ -97,15 +97,11 @@ class RedditRIE(InfoExtractor):
     }]
 
     def _real_extract(self, url):
-        mobj = self._match_valid_url(url)
-        url, video_id = mobj.group('url', 'id')
-
-        video_id = self._match_id(url)
+        slug, video_id = self._match_valid_url(url).group('slug', 'id')
 
         self._set_cookie('reddit.com', '_options', '%7B%22pref_quarantine_optin%22%3A%20true%7D')
-
         data = self._download_json(
-            url + '/.json', video_id)[0]['data']['children'][0]['data']
+            f'https://old.reddit.com/r/{slug}/.json', video_id)[0]['data']['children'][0]['data']
 
         video_url = data['url']