]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/reddit.py
01c85ee016306aa30b44c7521e736e6094b14f9c
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
_m
3u8_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))
45 class RedditRIE(InfoExtractor
):
46 _VALID_URL
= r
'https?://(?:www\.)?reddit\.com/r/[^/]+/comments/(?P<id>[^/]+)'
48 'url': 'https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/',
52 'title': 'That small heart attack.',
53 'thumbnail': r
're:^https?://.*\.jpg$',
54 'timestamp': 1501941939,
55 'upload_date': '20170805',
63 'format': 'bestvideo',
64 'skip_download': True,
67 'url': 'https://www.reddit.com/r/videos/comments/6rrwyj',
68 'only_matching': True,
71 'url': 'https://www.reddit.com/r/MadeMeSmile/comments/6t7wi5/wait_for_it/',
72 'only_matching': True,
75 'url': 'https://www.reddit.com/r/videos/comments/6t7sg9/comedians_hilarious_joke_about_the_guam_flag/',
76 'only_matching': True,
79 'url': 'https://www.reddit.com/r/videos/comments/6t75wq/southern_man_tries_to_speak_without_an_accent/',
80 'only_matching': True,
83 def _real_extract(self
, url
):
84 video_id
= self
._match
_id
(url
)
86 data
= self
._download
_json
(
87 url
+ '.json', video_id
)[0]['data']['children'][0]['data']
89 video_url
= data
['url']
91 # Avoid recursing into the same reddit URL
92 if 'reddit.com/' in video_url
and '/%s/' % video_id
in video_url
:
93 raise ExtractorError('No media found', expected
=True)
95 over_18
= data
.get('over_18')
98 elif over_18
is False:
104 '_type': 'url_transparent',
106 'title': data
.get('title'),
107 'thumbnail': data
.get('thumbnail'),
108 'timestamp': float_or_none(data
.get('created_utc')),
109 'uploader': data
.get('author'),
110 'like_count': int_or_none(data
.get('ups')),
111 'dislike_count': int_or_none(data
.get('downs')),
112 'comment_count': int_or_none(data
.get('num_comments')),
113 'age_limit': age_limit
,