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