1 from __future__ import unicode_literals
3 from .common import InfoExtractor
11 class RedditIE(InfoExtractor):
12 _VALID_URL = r'https?://v\.redd\.it/(?P<id>[^/?#&]+)'
14 # from https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/
15 'url': 'https://v.redd.it/zv89llsvexdz',
16 'md5': '655d06ace653ea3b87bccfb1b27ec99d',
20 'title': 'zv89llsvexdz',
23 'format': 'bestvideo',
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
30 formats = self._extract_m3u8_formats(
31 'https://v.redd.it/%s/HLSPlaylist.m3u8' % video_id, video_id,
32 'mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
34 formats.extend(self._extract_mpd_formats(
35 'https://v.redd.it/%s/DASHPlaylist.mpd' % video_id, video_id,
36 mpd_id='dash', fatal=False))
38 self._sort_formats(formats)
47 class RedditRIE(InfoExtractor):
48 _VALID_URL = r'https?://(?:www\.)?reddit\.com/r/[^/]+/comments/(?P<id>[^/]+)'
50 'url': 'https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/',
54 'title': 'That small heart attack.',
55 'thumbnail': r're:^https?://.*\.jpg$',
56 'timestamp': 1501941939,
57 'upload_date': '20170805',
65 'format': 'bestvideo',
66 'skip_download': True,
69 'url': 'https://www.reddit.com/r/videos/comments/6rrwyj',
70 'only_matching': True,
73 'url': 'https://www.reddit.com/r/MadeMeSmile/comments/6t7wi5/wait_for_it/',
74 'only_matching': True,
77 'url': 'https://www.reddit.com/r/videos/comments/6t7sg9/comedians_hilarious_joke_about_the_guam_flag/',
78 'only_matching': True,
81 'url': 'https://www.reddit.com/r/videos/comments/6t75wq/southern_man_tries_to_speak_without_an_accent/',
82 'only_matching': True,
85 def _real_extract(self, url):
86 video_id = self._match_id(url)
88 data = self._download_json(
89 url + '.json', video_id)[0]['data']['children'][0]['data']
91 video_url = data['url']
93 # Avoid recursing into the same reddit URL
94 if 'reddit.com/' in video_url and '/%s/' % video_id in video_url:
95 raise ExtractorError('No media found', expected=True)
97 over_18 = data.get('over_18')
100 elif over_18 is False:
106 '_type': 'url_transparent',
108 'title': data.get('title'),
109 'thumbnail': data.get('thumbnail'),
110 'timestamp': float_or_none(data.get('created_utc')),
111 'uploader': data.get('author'),
112 'like_count': int_or_none(data.get('ups')),
113 'dislike_count': int_or_none(data.get('downs')),
114 'comment_count': int_or_none(data.get('num_comments')),
115 'age_limit': age_limit,