|
|
@ -1,5 +1,4 @@
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
from ..utils import (
|
|
|
@ -49,7 +48,7 @@ class RedditIE(InfoExtractor):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RedditRIE(InfoExtractor):
|
|
|
|
class RedditRIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:[^/]+\.)?reddit(?:media)?\.com/r/(?P<slug>[^/]+/comments/(?P<id>[^/?#&]+))'
|
|
|
|
_VALID_URL = r'https?://(?P<subdomain>[^/]+\.)?reddit(?:media)?\.com/r/(?P<slug>[^/]+/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': {
|
|
|
@ -99,13 +98,22 @@ class RedditRIE(InfoExtractor):
|
|
|
|
'only_matching': True,
|
|
|
|
'only_matching': True,
|
|
|
|
}]
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
@staticmethod
|
|
|
|
slug, video_id = self._match_valid_url(url).group('slug', 'id')
|
|
|
|
def _gen_session_id():
|
|
|
|
|
|
|
|
id_length = 16
|
|
|
|
self._set_cookie('reddit.com', '_options', '%7B%22pref_quarantine_optin%22%3A%20true%7D')
|
|
|
|
rand_max = 1 << (id_length * 4)
|
|
|
|
data = self._download_json(
|
|
|
|
return '%0.*x' % (id_length, random.randrange(rand_max))
|
|
|
|
f'https://old.reddit.com/r/{slug}/.json', video_id)[0]['data']['children'][0]['data']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
|
|
|
subdomain, slug, video_id = self._match_valid_url(url).group('subdomain', 'slug', 'id')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._set_cookie('.reddit.com', 'reddit_session', self._gen_session_id())
|
|
|
|
|
|
|
|
self._set_cookie('.reddit.com', '_options', '%7B%22pref_quarantine_optin%22%3A%20true%7D')
|
|
|
|
|
|
|
|
data = self._download_json(f'https://{subdomain}.reddit.com/r/{slug}/.json', video_id, fatal=False)
|
|
|
|
|
|
|
|
if not data:
|
|
|
|
|
|
|
|
# Fall back to old.reddit.com in case the requested subdomain fails
|
|
|
|
|
|
|
|
data = self._download_json(f'https://old.reddit.com/r/{slug}/.json', video_id)
|
|
|
|
|
|
|
|
data = data[0]['data']['children'][0]['data']
|
|
|
|
video_url = data['url']
|
|
|
|
video_url = data['url']
|
|
|
|
|
|
|
|
|
|
|
|
# Avoid recursing into the same reddit URL
|
|
|
|
# Avoid recursing into the same reddit URL
|
|
|
|