]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/reddit.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  14 class RedditIE(InfoExtractor
): 
  15     _VALID_URL 
= r
'https?://v\.redd\.it/(?P<id>[^/?#&]+)' 
  17         # from https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/ 
  18         'url': 'https://v.redd.it/zv89llsvexdz', 
  19         'md5': '0a070c53eba7ec4534d95a5a1259e253', 
  23             'title': 'zv89llsvexdz', 
  26             'format': 'bestvideo', 
  30     def _real_extract(self
, url
): 
  31         video_id 
= self
._match
_id
(url
) 
  33         formats 
= self
._extract
_m
3u8_formats
( 
  34             'https://v.redd.it/%s/HLSPlaylist.m3u8' % video_id
, video_id
, 
  35             'mp4', entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False) 
  37         formats
.extend(self
._extract
_mpd
_formats
( 
  38             'https://v.redd.it/%s/DASHPlaylist.mpd' % video_id
, video_id
, 
  39             mpd_id
='dash', fatal
=False)) 
  41         self
._sort
_formats
(formats
) 
  50 class RedditRIE(InfoExtractor
): 
  51     _VALID_URL 
= r
'(?P<url>https?://(?:[^/]+\.)?reddit\.com/r/[^/]+/comments/(?P<id>[^/?#&]+))' 
  53         'url': 'https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/', 
  57             'title': 'That small heart attack.', 
  58             'thumbnail': r
're:^https?://.*\.jpg$', 
  59             'timestamp': 1501941939, 
  60             'upload_date': '20170805', 
  68             'format': 'bestvideo', 
  69             'skip_download': True, 
  72         'url': 'https://www.reddit.com/r/videos/comments/6rrwyj', 
  73         'only_matching': True, 
  76         'url': 'https://www.reddit.com/r/MadeMeSmile/comments/6t7wi5/wait_for_it/', 
  77         'only_matching': True, 
  80         'url': 'https://old.reddit.com/r/MadeMeSmile/comments/6t7wi5/wait_for_it/', 
  81         'only_matching': True, 
  84         'url': 'https://www.reddit.com/r/videos/comments/6t7sg9/comedians_hilarious_joke_about_the_guam_flag/', 
  85         'only_matching': True, 
  88         'url': 'https://www.reddit.com/r/videos/comments/6t75wq/southern_man_tries_to_speak_without_an_accent/', 
  89         'only_matching': True, 
  91         # reddit video @ nm reddit 
  92         'url': 'https://nm.reddit.com/r/Cricket/comments/8idvby/lousy_cameraman_finds_himself_in_cairns_line_of/', 
  93         'only_matching': True, 
  96     def _real_extract(self
, url
): 
  97         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  98         url
, video_id 
= mobj
.group('url', 'id') 
 100         video_id 
= self
._match
_id
(url
) 
 102         data 
= self
._download
_json
( 
 103             url 
+ '/.json', video_id
)[0]['data']['children'][0]['data'] 
 105         video_url 
= data
['url'] 
 107         # Avoid recursing into the same reddit URL 
 108         if 'reddit.com/' in video_url 
and '/%s/' % video_id 
in video_url
: 
 109             raise ExtractorError('No media found', expected
=True) 
 111         over_18 
= data
.get('over_18') 
 114         elif over_18 
is False: 
 120             '_type': 'url_transparent', 
 122             'title': data
.get('title'), 
 123             'thumbnail': url_or_none(data
.get('thumbnail')), 
 124             'timestamp': float_or_none(data
.get('created_utc')), 
 125             'uploader': data
.get('author'), 
 126             'like_count': int_or_none(data
.get('ups')), 
 127             'dislike_count': int_or_none(data
.get('downs')), 
 128             'comment_count': int_or_none(data
.get('num_comments')), 
 129             'age_limit': age_limit
,