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