mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-14 20:38:11 -05:00
[ie/reddit] Detect and raise when login is required (#11202)
Closes #10924 Authored by: pzhlkj6612
This commit is contained in:
parent
d710a6ca7c
commit
cba7868502
1 changed files with 9 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
@ -17,7 +18,7 @@
|
||||||
|
|
||||||
class RedditIE(InfoExtractor):
|
class RedditIE(InfoExtractor):
|
||||||
_NETRC_MACHINE = 'reddit'
|
_NETRC_MACHINE = 'reddit'
|
||||||
_VALID_URL = r'https?://(?P<host>(?:\w+\.)?reddit(?:media)?\.com)/(?P<slug>(?:(?:r|user)/[^/]+/)?comments/(?P<id>[^/?#&]+))'
|
_VALID_URL = r'https?://(?:\w+\.)?reddit(?:media)?\.com/(?P<slug>(?:(?:r|user)/[^/]+/)?comments/(?P<id>[^/?#&]+))'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/',
|
'url': 'https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
|
@ -251,15 +252,15 @@ def _get_subtitles(self, video_id):
|
||||||
return {'en': [{'url': caption_url}]}
|
return {'en': [{'url': caption_url}]}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
host, slug, video_id = self._match_valid_url(url).group('host', 'slug', 'id')
|
slug, video_id = self._match_valid_url(url).group('slug', 'id')
|
||||||
|
|
||||||
data = self._download_json(
|
try:
|
||||||
f'https://{host}/{slug}/.json', video_id, fatal=False, expected_status=403)
|
|
||||||
if not data:
|
|
||||||
fallback_host = 'old.reddit.com' if host != 'old.reddit.com' else 'www.reddit.com'
|
|
||||||
self.to_screen(f'{host} request failed, retrying with {fallback_host}')
|
|
||||||
data = self._download_json(
|
data = self._download_json(
|
||||||
f'https://{fallback_host}/{slug}/.json', video_id, expected_status=403)
|
f'https://www.reddit.com/{slug}/.json', video_id, expected_status=403)
|
||||||
|
except ExtractorError as e:
|
||||||
|
if isinstance(e.cause, json.JSONDecodeError):
|
||||||
|
self.raise_login_required('Account authentication is required')
|
||||||
|
raise
|
||||||
|
|
||||||
if traverse_obj(data, 'error') == 403:
|
if traverse_obj(data, 'error') == 403:
|
||||||
reason = data.get('reason')
|
reason = data.get('reason')
|
||||||
|
|
Loading…
Reference in a new issue