]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/reddit.py
7b0aa6232a0dea6ff09481560dc95f9a667e56e8
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
13 class RedditIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://v\.redd\.it/(?P<id>[^/?#&]+)'
16 # from https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/
17 'url': 'https://v.redd.it/zv89llsvexdz',
18 'md5': '0a070c53eba7ec4534d95a5a1259e253',
22 'title': 'zv89llsvexdz',
25 'format': 'bestvideo',
29 def _real_extract(self
, url
):
30 video_id
= self
._match
_id
(url
)
32 formats
= self
._extract
_m
3u8_formats
(
33 'https://v.redd.it/%s/HLSPlaylist.m3u8' % video_id
, video_id
,
34 'mp4', entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False)
36 formats
.extend(self
._extract
_mpd
_formats
(
37 'https://v.redd.it/%s/DASHPlaylist.mpd' % video_id
, video_id
,
38 mpd_id
='dash', fatal
=False))
40 self
._sort
_formats
(formats
)
49 class RedditRIE(InfoExtractor
):
50 _VALID_URL
= r
'(?P<url>https?://(?:[^/]+\.)?reddit\.com/r/[^/]+/comments/(?P<id>[^/?#&]+))'
52 'url': 'https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/',
56 'title': 'That small heart attack.',
57 'thumbnail': r
're:^https?://.*\.jpg$',
58 'timestamp': 1501941939,
59 'upload_date': '20170805',
67 'format': 'bestvideo',
68 'skip_download': True,
71 'url': 'https://www.reddit.com/r/videos/comments/6rrwyj',
72 'only_matching': True,
75 'url': 'https://www.reddit.com/r/MadeMeSmile/comments/6t7wi5/wait_for_it/',
76 'only_matching': True,
79 'url': 'https://old.reddit.com/r/MadeMeSmile/comments/6t7wi5/wait_for_it/',
80 'only_matching': True,
83 'url': 'https://www.reddit.com/r/videos/comments/6t7sg9/comedians_hilarious_joke_about_the_guam_flag/',
84 'only_matching': True,
87 'url': 'https://www.reddit.com/r/videos/comments/6t75wq/southern_man_tries_to_speak_without_an_accent/',
88 'only_matching': True,
90 # reddit video @ nm reddit
91 'url': 'https://nm.reddit.com/r/Cricket/comments/8idvby/lousy_cameraman_finds_himself_in_cairns_line_of/',
92 'only_matching': True,
95 def _real_extract(self
, url
):
96 mobj
= re
.match(self
._VALID
_URL
, url
)
97 url
, video_id
= mobj
.group('url', 'id')
99 video_id
= self
._match
_id
(url
)
101 data
= self
._download
_json
(
102 url
+ '/.json', video_id
)[0]['data']['children'][0]['data']
104 video_url
= data
['url']
106 # Avoid recursing into the same reddit URL
107 if 'reddit.com/' in video_url
and '/%s/' % video_id
in video_url
:
108 raise ExtractorError('No media found', expected
=True)
110 over_18
= data
.get('over_18')
113 elif over_18
is False:
119 '_type': 'url_transparent',
121 'title': data
.get('title'),
122 'thumbnail': data
.get('thumbnail'),
123 'timestamp': float_or_none(data
.get('created_utc')),
124 'uploader': data
.get('author'),
125 'like_count': int_or_none(data
.get('ups')),
126 'dislike_count': int_or_none(data
.get('downs')),
127 'comment_count': int_or_none(data
.get('num_comments')),
128 'age_limit': age_limit
,