]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/wistia.py
4 from base64
import b64decode
6 from .common
import InfoExtractor
18 class WistiaBaseIE(InfoExtractor
):
19 _VALID_ID_REGEX
= r
'(?P<id>[a-z0-9]{10})'
20 _VALID_URL_BASE
= r
'https?://(?:\w+\.)?wistia\.(?:net|com)/(?:embed/)?'
21 _EMBED_BASE_URL
= 'http://fast.wistia.net/embed/'
23 def _download_embed_config(self
, config_type
, config_id
, referer
):
24 base_url
= self
._EMBED
_BASE
_URL
+ '%s/%s' % (config_type
, config_id
)
25 embed_config
= self
._download
_json
(
26 base_url
+ '.json', config_id
, headers
={
27 'Referer': referer
if referer
.startswith('http') else base_url
, # Some videos require this.
30 error
= traverse_obj(embed_config
, 'error')
33 f
'Error while getting the playlist: {error}', expected
=True)
37 def _extract_media(self
, embed_config
):
38 data
= embed_config
['media']
39 video_id
= data
['hashedId']
44 for a
in data
['assets']:
48 astatus
= a
.get('status')
50 if (astatus
is not None and astatus
!= 2) or atype
in ('preview', 'storyboard'):
52 elif atype
in ('still', 'still_image'):
55 'width': int_or_none(a
.get('width')),
56 'height': int_or_none(a
.get('height')),
57 'filesize': int_or_none(a
.get('size')),
61 display_name
= a
.get('display_name')
63 if atype
and atype
.endswith('_video') and display_name
:
64 format_id
= '%s-%s' % (atype
[:-6], display_name
)
66 'format_id': format_id
,
68 'tbr': int_or_none(a
.get('bitrate')) or None,
69 'quality': 1 if atype
== 'original' else None,
71 if display_name
== 'Audio':
77 'width': int_or_none(a
.get('width')),
78 'height': int_or_none(a
.get('height')),
79 'vcodec': a
.get('codec'),
81 if a
.get('container') == 'm3u8' or aext
== 'm3u8':
85 'format_id': f
['format_id'].replace('hls-', 'ts-'),
86 'url': f
['url'].replace('.bin', '.ts'),
91 'protocol': 'm3u8_native',
95 'container': a
.get('container'),
97 'filesize': int_or_none(a
.get('size')),
101 self
._sort
_formats
(formats
)
104 for caption
in data
.get('captions', []):
105 language
= caption
.get('language')
108 subtitles
[language
] = [{
109 'url': self
._EMBED
_BASE
_URL
+ 'captions/' + video_id
+ '.vtt?language=' + language
,
115 'description': data
.get('seoDescription'),
117 'thumbnails': thumbnails
,
118 'duration': float_or_none(data
.get('duration')),
119 'timestamp': int_or_none(data
.get('createdAt')),
120 'subtitles': subtitles
,
124 def _extract_from_webpage(cls
, url
, webpage
):
125 from .teachable
import TeachableIE
127 if list(TeachableIE
._extract
_embed
_urls
(url
, webpage
)):
130 yield from super()._extract
_from
_webpage
(url
, webpage
)
133 def _extract_wistia_async_embed(cls
, webpage
):
134 # https://wistia.com/support/embed-and-share/video-on-your-website
135 # https://wistia.com/support/embed-and-share/channel-embeds
136 yield from re
.finditer(
138 <(?:div|section)[^>]+class=([\"'])(?:(?!\1).)*?(?P<type>wistia[a-z_0-9]+)\s*\bwistia_async_(?P<id>[a-z0-9]{10})\b(?:(?!\1).)*?\1
142 def _extract_url_media_id(cls
, url
):
143 mobj
= re
.search(r
'(?:wmediaid|wvideo(?:id)?)]?=(?P<id>[a-z0-9]{10})', urllib
.parse
.unquote_plus(url
))
145 return mobj
.group('id')
148 class WistiaIE(WistiaBaseIE
):
149 _VALID_URL
= r
'(?:wistia:|%s(?:iframe|medias)/)%s' % (WistiaBaseIE
._VALID
_URL
_BASE
, WistiaBaseIE
._VALID
_ID
_REGEX
)
152 <(?:meta[^>]+?content|(?:iframe|script)[^>]+?src)=["\']
153 (?P
<url
>(?
:https?
:)?
//(?
:fast\
.)?wistia\
.(?
:net|com
)/embed
/(?
:iframe|medias
)/[a
-z0
-9]{10}
)
157 'url': 'wistia:807fafadvk',
158 'md5': 'daff0f3687a41d9a71b40e0e8c2610fe',
162 'title': 'Drip Brennan Dunn Workshop',
163 'description': 'a JV Webinars video',
164 'upload_date': '20160518',
165 'timestamp': 1463607249,
168 'skip': 'video unavailable',
170 'url': 'wistia:a6ndpko1wg',
171 'md5': '10c1ce9c4dde638202513ed17a3767bd',
175 'title': 'Episode 2: Boxed Water\'s retention is thirsty',
176 'upload_date': '20210324',
177 'description': 'md5:da5994c2c2d254833b412469d9666b7a',
179 'timestamp': 1616614369,
180 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/53dc60239348dc9b9fba3755173ea4c2.bin',
183 'url': 'wistia:5vd7p4bct5',
184 'md5': 'b9676d24bf30945d97060638fbfe77f0',
188 'title': 'md5:eaa9f64c4efd7b5f098b9b6118597679',
189 'description': 'md5:a9bea0315f0616aa5df2dc413ddcdd0f',
190 'upload_date': '20220915',
191 'timestamp': 1663258727,
193 'thumbnail': r're:https?://embed(?:-ssl)?.wistia.com/.+\.(?:jpg|bin)$',
196 'url': 'wistia:sh7fpupwlt',
197 'only_matching': True,
199 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
200 'only_matching': True,
202 'url': 'http://fast.wistia.com/embed/iframe/sh7fpupwlt',
203 'only_matching': True,
205 'url': 'http://fast.wistia.net/embed/medias/sh7fpupwlt.json',
206 'only_matching': True,
210 'url': 'https://www.weidert.com/blog/wistia-channels-video-marketing-tool',
214 'title': 'How Wistia Channels Can Help Capture Inbound Value From Your Video Content',
216 'timestamp': 1618974400,
217 'description': 'md5:27abc99a758573560be72600ef95cece',
218 'upload_date': '20210421',
219 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/6c551820ae950cdee2306d6cbe9ef742.bin',
222 'url': 'https://study.com/academy/lesson/north-american-exploration-failed-colonies-of-spain-france-england.html#lesson',
223 'md5': 'b9676d24bf30945d97060638fbfe77f0',
227 'title': 'paywall_north-american-exploration-failed-colonies-of-spain-france-england',
228 'upload_date': '20220915',
229 'timestamp': 1663258727,
231 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/83e6ec693e2c05a0ce65809cbaead86a.bin',
232 'description': 'a Paywall Videos video',
236 def _real_extract(self, url):
237 video_id = self._match_id(url)
238 embed_config = self._download_embed_config('medias', video_id, url)
239 return self._extract_media(embed_config)
242 def _extract_embed_urls(cls, url, webpage):
243 urls = list(super()._extract_embed_urls(url, webpage))
244 for match in cls._extract_wistia_async_embed(webpage):
245 if match.group('type') != 'wistia_channel':
246 urls.append('wistia:%s' % match.group('id'))
247 for match in re.finditer(r'(?:data-wistia-?id=["\']|Wistia\.embed\(["\']|id=["\']wistia_)(?P<id>[a-z0-9]{10})',
249 urls.append('wistia:%s' % match.group('id'))
250 if not WistiaChannelIE._extract_embed_urls(url, webpage): # Fallback
251 media_id = cls._extract_url_media_id(url)
253 urls.append('wistia:%s' % match.group('id'))
257 class WistiaPlaylistIE(WistiaBaseIE):
258 _VALID_URL = r'%splaylists/%s' % (WistiaBaseIE._VALID_URL_BASE, WistiaBaseIE._VALID_ID_REGEX)
261 'url': 'https://fast.wistia.net/embed/playlists/aodt9etokc',
268 def _real_extract(self, url):
269 playlist_id = self._match_id(url)
270 playlist = self._download_embed_config('playlists', playlist_id, url)
273 for media in (try_get(playlist, lambda x: x[0]['medias']) or []):
274 embed_config = media.get('embed_config')
277 entries.append(self._extract_media(embed_config))
279 return self.playlist_result(entries, playlist_id)
282 class WistiaChannelIE(WistiaBaseIE):
283 _VALID_URL = r'(?:wistiachannel:|%schannel/)%s' % (WistiaBaseIE._VALID_URL_BASE, WistiaBaseIE._VALID_ID_REGEX)
286 # JSON Embed API returns 403, should fall back to webpage
287 'url': 'https://fast.wistia.net/embed/channel/yvyvu7wjbg?wchannelid=yvyvu7wjbg',
290 'title': 'Copysmith Tutorials and Education!',
291 'description': 'Learn all things Copysmith via short and informative videos!'
293 'playlist_mincount': 7,
294 'expected_warnings': ['falling back to webpage'],
296 'url': 'https://fast.wistia.net/embed/channel/3802iirk0l',
301 'playlist_mincount': 20,
303 # link to popup video, follow --no-playlist
304 'url': 'https://fast.wistia.net/embed/channel/3802iirk0l?wchannelid=3802iirk0l&wmediaid=sp5dqjzw3n',
308 'title': 'The Roof S2: The Modern CRO',
309 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/dadfa9233eaa505d5e0c85c23ff70741.bin',
311 'description': 'A sales leader on The Roof? Man, they really must be letting anyone up here this season.\n',
312 'timestamp': 1619790290,
313 'upload_date': '20210430',
315 'params': {'noplaylist': True, 'skip_download': True},
318 'url': 'https://www.profitwell.com/recur/boxed-out',
321 'title': 'Boxed Out',
322 'description': 'md5:14a8a93a1dbe236718e6a59f8c8c7bae',
324 'playlist_mincount': 30,
326 # section instead of div
327 'url': 'https://360learning.com/studio/onboarding-joei/',
330 'title': 'Onboarding Joei.',
331 'description': 'Coming to you weekly starting Feb 19th.',
333 'playlist_mincount': 20,
335 'url': 'https://amplitude.com/amplify-sessions?amp%5Bwmediaid%5D=pz0m0l0if3&%5Bwvideo%5D=pz0m0l0if3&wchannelid=emyjmwjf79&wmediaid=i8um783bdt',
338 'title': 'A Framework for Improving Product Team Performance',
340 'timestamp': 1653935275,
341 'upload_date': '20220530',
342 'description': 'Learn how to help your company improve and achieve your product related goals.',
344 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/12fd19e56413d9d6f04e2185c16a6f8854e25226.bin',
346 'params': {'noplaylist': True, 'skip_download': True},
349 def _real_extract(self, url):
350 channel_id = self._match_id(url)
351 media_id = self._extract_url_media_id(url)
352 if not self._yes_playlist(channel_id, media_id, playlist_label='channel'):
353 return self.url_result(f'wistia:{media_id}', 'Wistia')
356 data = self._download_embed_config('channel', channel_id, url)
357 except (ExtractorError, urllib.error.HTTPError):
358 # Some channels give a 403 from the JSON API
359 self.report_warning('Failed to download channel data from API, falling back to webpage.')
360 webpage = self._download_webpage(f'https://fast.wistia.net/embed/channel/{channel_id}', channel_id)
361 data = self._parse_json(
362 self._search_regex(r'wchanneljsonp-%s\'\]\s*=[^\"]*\"([A-Za-z0-9=/]*)' % channel_id, webpage, 'jsonp', channel_id),
363 channel_id, transform_source=lambda x: urllib.parse.unquote_plus(b64decode(x).decode('utf-8')))
365 # XXX: can there be more than one series?
366 series = traverse_obj(data, ('series', 0), default={})
369 self.url_result(f'wistia:{video["hashedId"]}', WistiaIE, title=video.get('name'))
370 for video in traverse_obj(series, ('sections', ..., 'videos', ...)) or []
371 if video.get('hashedId')
374 return self.playlist_result(
375 entries, channel_id, playlist_title=series.get('title'), playlist_description=series.get('description'))
378 def _extract_embed_urls(cls, url, webpage):
379 yield from super()._extract_embed_urls(url, webpage)
380 for match in cls._extract_wistia_async_embed(webpage):
381 if match.group('type') == 'wistia_channel':
382 # original url may contain wmediaid query param
383 yield update_url_query(f'wistiachannel:{match.group("id")}', parse_qs(url))