]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/voxmedia.py
New upstream version 2020.06.16.1
[youtubedl] / youtube_dl / extractor / voxmedia.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .once import OnceIE
6 from ..compat import compat_urllib_parse_unquote
7 from ..utils import (
8 ExtractorError,
9 int_or_none,
10 )
11
12
13 class VoxMediaVolumeIE(OnceIE):
14 _VALID_URL = r'https?://volume\.vox-cdn\.com/embed/(?P<id>[0-9a-f]{9})'
15
16 def _real_extract(self, url):
17 video_id = self._match_id(url)
18 webpage = self._download_webpage(url, video_id)
19
20 setup = self._parse_json(self._search_regex(
21 r'setup\s*=\s*({.+});', webpage, 'setup'), video_id)
22 video_data = setup.get('video') or {}
23 info = {
24 'id': video_id,
25 'title': video_data.get('title_short'),
26 'description': video_data.get('description_long') or video_data.get('description_short'),
27 'thumbnail': video_data.get('brightcove_thumbnail')
28 }
29 asset = setup.get('asset') or setup.get('params') or {}
30
31 formats = []
32 hls_url = asset.get('hls_url')
33 if hls_url:
34 formats.extend(self._extract_m3u8_formats(
35 hls_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
36 mp4_url = asset.get('mp4_url')
37 if mp4_url:
38 tbr = self._search_regex(r'-(\d+)k\.', mp4_url, 'bitrate', default=None)
39 format_id = 'http'
40 if tbr:
41 format_id += '-' + tbr
42 formats.append({
43 'format_id': format_id,
44 'url': mp4_url,
45 'tbr': int_or_none(tbr),
46 })
47 if formats:
48 self._sort_formats(formats)
49 info['formats'] = formats
50 return info
51
52 for provider_video_type in ('ooyala', 'youtube', 'brightcove'):
53 provider_video_id = video_data.get('%s_id' % provider_video_type)
54 if not provider_video_id:
55 continue
56 if provider_video_type == 'brightcove':
57 info['formats'] = self._extract_once_formats(provider_video_id)
58 self._sort_formats(info['formats'])
59 else:
60 info.update({
61 '_type': 'url_transparent',
62 'url': provider_video_id if provider_video_type == 'youtube' else '%s:%s' % (provider_video_type, provider_video_id),
63 'ie_key': provider_video_type.capitalize(),
64 })
65 return info
66 raise ExtractorError('Unable to find provider video id')
67
68
69 class VoxMediaIE(InfoExtractor):
70 _VALID_URL = r'https?://(?:www\.)?(?:(?:theverge|vox|sbnation|eater|polygon|curbed|racked|funnyordie)\.com|recode\.net)/(?:[^/]+/)*(?P<id>[^/?]+)'
71 _TESTS = [{
72 # Volume embed, Youtube
73 'url': 'http://www.theverge.com/2014/6/27/5849272/material-world-how-google-discovered-what-software-is-made-of',
74 'info_dict': {
75 'id': 'j4mLW6x17VM',
76 'ext': 'mp4',
77 'title': 'Material world: how Google discovered what software is made of',
78 'description': 'md5:dfc17e7715e3b542d66e33a109861382',
79 'upload_date': '20190710',
80 'uploader_id': 'TheVerge',
81 'uploader': 'The Verge',
82 },
83 'add_ie': ['Youtube'],
84 }, {
85 # Volume embed, Youtube
86 'url': 'http://www.theverge.com/2014/10/21/7025853/google-nexus-6-hands-on-photos-video-android-phablet',
87 'md5': '4c8f4a0937752b437c3ebc0ed24802b5',
88 'info_dict': {
89 'id': 'Gy8Md3Eky38',
90 'ext': 'mp4',
91 'title': 'The Nexus 6: hands-on with Google\'s phablet',
92 'description': 'md5:d9f0216e5fb932dd2033d6db37ac3f1d',
93 'uploader_id': 'TheVerge',
94 'upload_date': '20141021',
95 'uploader': 'The Verge',
96 },
97 'add_ie': ['Youtube'],
98 'skip': 'similar to the previous test',
99 }, {
100 # Volume embed, Youtube
101 'url': 'http://www.vox.com/2016/3/31/11336640/mississippi-lgbt-religious-freedom-bill',
102 'info_dict': {
103 'id': 'YCjDnX-Xzhg',
104 'ext': 'mp4',
105 'title': "Mississippi's laws are so bad that its anti-LGBTQ law isn't needed to allow discrimination",
106 'description': 'md5:fc1317922057de31cd74bce91eb1c66c',
107 'uploader_id': 'voxdotcom',
108 'upload_date': '20150915',
109 'uploader': 'Vox',
110 },
111 'add_ie': ['Youtube'],
112 'skip': 'similar to the previous test',
113 }, {
114 # youtube embed
115 'url': 'http://www.vox.com/2016/3/24/11291692/robot-dance',
116 'md5': '83b3080489fb103941e549352d3e0977',
117 'info_dict': {
118 'id': 'FcNHTJU1ufM',
119 'ext': 'mp4',
120 'title': 'How "the robot" became the greatest novelty dance of all time',
121 'description': 'md5:b081c0d588b8b2085870cda55e6da176',
122 'upload_date': '20160324',
123 'uploader_id': 'voxdotcom',
124 'uploader': 'Vox',
125 },
126 'add_ie': ['Youtube'],
127 'skip': 'Page no longer contain videos',
128 }, {
129 # SBN.VideoLinkset.entryGroup multiple ooyala embeds
130 'url': 'http://www.sbnation.com/college-football-recruiting/2015/2/3/7970291/national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
131 'info_dict': {
132 'id': 'national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
133 'title': '25 lies you will tell yourself on National Signing Day',
134 'description': 'It\'s the most self-delusional time of the year, and everyone\'s gonna tell the same lies together!',
135 },
136 'playlist': [{
137 'md5': '721fededf2ab74ae4176c8c8cbfe092e',
138 'info_dict': {
139 'id': 'p3cThlMjE61VDi_SD9JlIteSNPWVDBB9',
140 'ext': 'mp4',
141 'title': 'Buddy Hield vs Steph Curry (and the world)',
142 'description': 'Let’s dissect only the most important Final Four storylines.',
143 },
144 }, {
145 'md5': 'bf0c5cc115636af028be1bab79217ea9',
146 'info_dict': {
147 'id': 'BmbmVjMjE6esPHxdALGubTrouQ0jYLHj',
148 'ext': 'mp4',
149 'title': 'Chasing Cinderella 2016: Syracuse basketball',
150 'description': 'md5:e02d56b026d51aa32c010676765a690d',
151 },
152 }],
153 'skip': 'Page no longer contain videos',
154 }, {
155 # volume embed, Brightcove Once
156 'url': 'https://www.recode.net/2014/6/17/11628066/post-post-pc-ceo-the-full-code-conference-video-of-microsofts-satya',
157 'md5': '2dbc77b8b0bff1894c2fce16eded637d',
158 'info_dict': {
159 'id': '1231c973d',
160 'ext': 'mp4',
161 'title': 'Post-Post-PC CEO: The Full Code Conference Video of Microsoft\'s Satya Nadella',
162 'description': 'The longtime veteran was chosen earlier this year as the software giant\'s third leader in its history.',
163 },
164 'add_ie': ['VoxMediaVolume'],
165 }]
166
167 def _real_extract(self, url):
168 display_id = self._match_id(url)
169 webpage = compat_urllib_parse_unquote(self._download_webpage(url, display_id))
170
171 def create_entry(provider_video_id, provider_video_type, title=None, description=None):
172 video_url = {
173 'youtube': '%s',
174 'ooyala': 'ooyala:%s',
175 'volume': 'http://volume.vox-cdn.com/embed/%s',
176 }[provider_video_type] % provider_video_id
177 return {
178 '_type': 'url_transparent',
179 'url': video_url,
180 'title': title or self._og_search_title(webpage),
181 'description': description or self._og_search_description(webpage),
182 }
183
184 entries = []
185 entries_data = self._search_regex([
186 r'Chorus\.VideoContext\.addVideo\((\[{.+}\])\);',
187 r'var\s+entry\s*=\s*({.+});',
188 r'SBN\.VideoLinkset\.entryGroup\(\s*(\[.+\])',
189 ], webpage, 'video data', default=None)
190 if entries_data:
191 entries_data = self._parse_json(entries_data, display_id)
192 if isinstance(entries_data, dict):
193 entries_data = [entries_data]
194 for video_data in entries_data:
195 provider_video_id = video_data.get('provider_video_id')
196 provider_video_type = video_data.get('provider_video_type')
197 if provider_video_id and provider_video_type:
198 entries.append(create_entry(
199 provider_video_id, provider_video_type,
200 video_data.get('title'), video_data.get('description')))
201
202 provider_video_id = self._search_regex(
203 r'data-ooyala-id="([^"]+)"', webpage, 'ooyala id', default=None)
204 if provider_video_id:
205 entries.append(create_entry(provider_video_id, 'ooyala'))
206
207 volume_uuid = self._search_regex(
208 r'data-volume-uuid="([^"]+)"', webpage, 'volume uuid', default=None)
209 if volume_uuid:
210 entries.append(create_entry(volume_uuid, 'volume'))
211
212 if len(entries) == 1:
213 return entries[0]
214 else:
215 return self.playlist_result(entries, display_id, self._og_search_title(webpage), self._og_search_description(webpage))