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