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