5 from .common
import InfoExtractor
6 from ..networking
import HEADRequest
7 from ..networking
.exceptions
import HTTPError
22 class WistiaBaseIE(InfoExtractor
):
23 _VALID_ID_REGEX
= r
'(?P<id>[a-z0-9]{10})'
24 _VALID_URL_BASE
= r
'https?://(?:\w+\.)?wistia\.(?:net|com)/(?:embed/)?'
25 _EMBED_BASE_URL
= 'http://fast.wistia.net/embed/'
27 def _download_embed_config(self
, config_type
, config_id
, referer
):
28 base_url
= self
._EMBED
_BASE
_URL
+ f
'{config_type}/{config_id}'
29 video_password
= self
.get_param('videopassword')
30 embed_config
= self
._download
_json
(
31 base_url
+ '.json', config_id
, headers
={
32 'Referer': referer
if referer
.startswith('http') else base_url
, # Some videos require this.
33 }, query
=filter_dict({'password': video_password
}))
35 error
= traverse_obj(embed_config
, 'error')
38 f
'Error while getting the playlist: {error}', expected
=True)
40 if traverse_obj(embed_config
, (
41 'media', ('embed_options', 'embedOptions'), 'plugin',
42 'passwordProtectedVideo', 'on', any
)) == 'true':
44 raise ExtractorError('Invalid video password', expected
=True)
46 'This content is password-protected. Use the --video-password option', expected
=True)
50 def _get_real_ext(self
, url
):
51 ext
= determine_ext(url
, default_ext
='bin')
53 urlh
= self
._request
_webpage
(
54 HEADRequest(url
), None, note
='Checking media extension',
55 errnote
='HEAD request returned error', fatal
=False)
57 ext
= urlhandle_detect_ext(urlh
, default
='bin')
58 return 'mp4' if ext
== 'mov' else ext
60 def _extract_media(self
, embed_config
):
61 data
= embed_config
['media']
62 video_id
= data
['hashedId']
67 for a
in data
['assets']:
71 astatus
= a
.get('status')
73 if (astatus
is not None and astatus
!= 2) or atype
in ('preview', 'storyboard'):
75 elif atype
in ('still', 'still_image'):
77 'url': aurl
.replace('.bin', f
'.{self._get_real_ext(aurl)}'),
78 'width': int_or_none(a
.get('width')),
79 'height': int_or_none(a
.get('height')),
80 'filesize': int_or_none(a
.get('size')),
83 aext
= a
.get('ext') or self
._get
_real
_ext
(aurl
)
84 display_name
= a
.get('display_name')
86 if atype
and atype
.endswith('_video') and display_name
:
87 format_id
= f
'{atype[:-6]}-{display_name}'
89 'format_id': format_id
,
91 'tbr': int_or_none(a
.get('bitrate')) or None,
92 'quality': 1 if atype
== 'original' else None,
94 if display_name
== 'Audio':
100 'width': int_or_none(a
.get('width')),
101 'height': int_or_none(a
.get('height')),
102 'vcodec': a
.get('codec'),
104 if a
.get('container') == 'm3u8' or aext
== 'm3u8':
108 'format_id': f
['format_id'].replace('hls-', 'ts-'),
109 'url': f
['url'].replace('.bin', '.ts'),
114 'protocol': 'm3u8_native',
118 'container': a
.get('container'),
120 'filesize': int_or_none(a
.get('size')),
125 for caption
in data
.get('captions', []):
126 language
= caption
.get('language')
129 subtitles
[language
] = [{
130 'url': self
._EMBED
_BASE
_URL
+ 'captions/' + video_id
+ '.vtt?language=' + language
,
136 'description': data
.get('seoDescription'),
138 'thumbnails': thumbnails
,
139 'duration': float_or_none(data
.get('duration')),
140 'timestamp': int_or_none(data
.get('createdAt')),
141 'subtitles': subtitles
,
145 def _extract_from_webpage(cls
, url
, webpage
):
146 from .teachable
import TeachableIE
148 if list(TeachableIE
._extract
_embed
_urls
(url
, webpage
)):
151 yield from super()._extract
_from
_webpage
(url
, webpage
)
154 def _extract_wistia_async_embed(cls
, webpage
):
155 # https://wistia.com/support/embed-and-share/video-on-your-website
156 # https://wistia.com/support/embed-and-share/channel-embeds
157 yield from re
.finditer(
159 <(?:div|section)[^>]+class=([\"'])(?:(?!\1).)*?(?P<type>wistia[a-z_0-9]+)\s*\bwistia_async_(?P<id>[a-z0-9]{10})\b(?:(?!\1).)*?\1
163 def _extract_url_media_id(cls
, url
):
164 mobj
= re
.search(r
'(?:wmediaid|wvideo(?:id)?)]?=(?P<id>[a-z0-9]{10})', urllib
.parse
.unquote_plus(url
))
166 return mobj
.group('id')
169 class WistiaIE(WistiaBaseIE
):
170 _VALID_URL
= rf
'(?:wistia:|{WistiaBaseIE._VALID_URL_BASE}(?:iframe|medias)/){WistiaBaseIE._VALID_ID_REGEX}'
173 <(?:meta[^>]+?content|(?:iframe|script)[^>]+?src)=["\']
174 (?P
<url
>(?
:https?
:)?
//(?
:fast\
.)?wistia\
.(?
:net|com
)/embed
/(?
:iframe|medias
)/[a
-z0
-9]{10}
)
178 'url': 'wistia:807fafadvk',
179 'md5': 'daff0f3687a41d9a71b40e0e8c2610fe',
183 'title': 'Drip Brennan Dunn Workshop',
184 'description': 'a JV Webinars video',
185 'upload_date': '20160518',
186 'timestamp': 1463607249,
189 'skip': 'video unavailable',
191 'url': 'wistia:a6ndpko1wg',
192 'md5': '10c1ce9c4dde638202513ed17a3767bd',
196 'title': 'Episode 2: Boxed Water\'s retention is thirsty',
197 'upload_date': '20210324',
198 'description': 'md5:da5994c2c2d254833b412469d9666b7a',
200 'timestamp': 1616614369,
201 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/53dc60239348dc9b9fba3755173ea4c2.png',
204 'url': 'wistia:5vd7p4bct5',
205 'md5': 'b9676d24bf30945d97060638fbfe77f0',
209 'title': 'md5:eaa9f64c4efd7b5f098b9b6118597679',
210 'description': 'md5:a9bea0315f0616aa5df2dc413ddcdd0f',
211 'upload_date': '20220915',
212 'timestamp': 1663258727,
214 'thumbnail': r're:https?://embed(?:-ssl)?.wistia.com/.+\.jpg$',
217 'url': 'wistia:sh7fpupwlt',
218 'only_matching': True,
220 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
221 'only_matching': True,
223 'url': 'http://fast.wistia.com/embed/iframe/sh7fpupwlt',
224 'only_matching': True,
226 'url': 'http://fast.wistia.net/embed/medias/sh7fpupwlt.json',
227 'only_matching': True,
231 'url': 'https://www.weidert.com/blog/wistia-channels-video-marketing-tool',
235 'title': 'How Wistia Channels Can Help Capture Inbound Value From Your Video Content',
237 'timestamp': 1618974400,
238 'description': 'md5:27abc99a758573560be72600ef95cece',
239 'upload_date': '20210421',
240 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/6c551820ae950cdee2306d6cbe9ef742.jpg',
243 'url': 'https://study.com/academy/lesson/north-american-exploration-failed-colonies-of-spain-france-england.html#lesson',
244 'md5': 'b9676d24bf30945d97060638fbfe77f0',
248 'title': 'paywall_north-american-exploration-failed-colonies-of-spain-france-england',
249 'upload_date': '20220915',
250 'timestamp': 1663258727,
252 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/83e6ec693e2c05a0ce65809cbaead86a.jpg',
253 'description': 'a Paywall Videos video',
257 def _real_extract(self, url):
258 video_id = self._match_id(url)
259 embed_config = self._download_embed_config('medias', video_id, url)
260 return self._extract_media(embed_config)
263 def _extract_embed_urls(cls, url, webpage):
264 urls = list(super()._extract_embed_urls(url, webpage))
265 for match in cls._extract_wistia_async_embed(webpage):
266 if match.group('type') != 'wistia_channel':
267 urls.append('wistia:{}'.format(match.group('id')))
268 for match in re.finditer(r'(?:data-wistia-?id=["\']|Wistia\.embed\(["\']|id=["\']wistia_)(?P<id>[a-z0-9]{10})',
270 urls.append('wistia:{}'.format(match.group('id')))
271 if not WistiaChannelIE._extract_embed_urls(url, webpage): # Fallback
272 media_id = cls._extract_url_media_id(url)
274 urls.append('wistia:{}'.format(match.group('id')))
278 class WistiaPlaylistIE(WistiaBaseIE):
279 _VALID_URL = rf'{WistiaBaseIE._VALID_URL_BASE}playlists/{WistiaBaseIE._VALID_ID_REGEX}'
282 'url': 'https://fast.wistia.net/embed/playlists/aodt9etokc',
289 def _real_extract(self, url):
290 playlist_id = self._match_id(url)
291 playlist = self._download_embed_config('playlists', playlist_id, url)
294 for media in (try_get(playlist, lambda x: x[0]['medias']) or []):
295 embed_config = media.get('embed_config')
298 entries.append(self._extract_media(embed_config))
300 return self.playlist_result(entries, playlist_id)
303 class WistiaChannelIE(WistiaBaseIE):
304 _VALID_URL = rf'(?:wistiachannel:|{WistiaBaseIE._VALID_URL_BASE}channel/){WistiaBaseIE._VALID_ID_REGEX}'
307 # JSON Embed API returns 403, should fall back to webpage
308 'url': 'https://fast.wistia.net/embed/channel/yvyvu7wjbg?wchannelid=yvyvu7wjbg',
311 'title': 'Copysmith Tutorials and Education!',
312 'description': 'Learn all things Copysmith via short and informative videos!',
314 'playlist_mincount': 7,
315 'expected_warnings': ['falling back to webpage'],
317 'url': 'https://fast.wistia.net/embed/channel/3802iirk0l',
322 'playlist_mincount': 20,
324 # link to popup video, follow --no-playlist
325 'url': 'https://fast.wistia.net/embed/channel/3802iirk0l?wchannelid=3802iirk0l&wmediaid=sp5dqjzw3n',
329 'title': 'The Roof S2: The Modern CRO',
330 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/dadfa9233eaa505d5e0c85c23ff70741.png',
332 'description': 'A sales leader on The Roof? Man, they really must be letting anyone up here this season.\n',
333 'timestamp': 1619790290,
334 'upload_date': '20210430',
336 'params': {'noplaylist': True, 'skip_download': True},
339 'url': 'https://www.profitwell.com/recur/boxed-out',
342 'title': 'Boxed Out',
343 'description': 'md5:14a8a93a1dbe236718e6a59f8c8c7bae',
345 'playlist_mincount': 30,
347 # section instead of div
348 'url': 'https://360learning.com/studio/onboarding-joei/',
351 'title': 'Onboarding Joei.',
352 'description': 'Coming to you weekly starting Feb 19th.',
354 'playlist_mincount': 20,
356 'url': 'https://amplitude.com/amplify-sessions?amp%5Bwmediaid%5D=pz0m0l0if3&%5Bwvideo%5D=pz0m0l0if3&wchannelid=emyjmwjf79&wmediaid=i8um783bdt',
359 'title': 'A Framework for Improving Product Team Performance',
361 'timestamp': 1653935275,
362 'upload_date': '20220530',
363 'description': 'Learn how to help your company improve and achieve your product related goals.',
365 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/12fd19e56413d9d6f04e2185c16a6f8854e25226.png',
367 'params': {'noplaylist': True, 'skip_download': True},
370 def _real_extract(self, url):
371 channel_id = self._match_id(url)
372 media_id = self._extract_url_media_id(url)
373 if not self._yes_playlist(channel_id, media_id, playlist_label='channel'):
374 return self.url_result(f'wistia:{media_id}', 'Wistia')
377 data = self._download_embed_config('channel', channel_id, url)
378 except (ExtractorError, HTTPError):
379 # Some channels give a 403 from the JSON API
380 self.report_warning('Failed to download channel data from API, falling back to webpage.')
381 webpage = self._download_webpage(f'https://fast.wistia.net/embed/channel/{channel_id}', channel_id)
382 data = self._parse_json(
383 self._search_regex(rf'wchanneljsonp-{channel_id}\'\]\s*=[^\"]*\"([A-Za-z0-9=/]*)', webpage, 'jsonp', channel_id),
384 channel_id, transform_source=lambda x: urllib.parse.unquote_plus(base64.b64decode(x).decode('utf-8')))
386 # XXX: can there be more than one series?
387 series = traverse_obj(data, ('series', 0), default={})
390 self.url_result(f'wistia:{video["hashedId"]}', WistiaIE, title=video.get('name'))
391 for video in traverse_obj(series, ('sections', ..., 'videos', ...)) or []
392 if video.get('hashedId')
395 return self.playlist_result(
396 entries, channel_id, playlist_title=series.get('title'), playlist_description=series.get('description'))
399 def _extract_embed_urls(cls, url, webpage):
400 yield from super()._extract_embed_urls(url, webpage)
401 for match in cls._extract_wistia_async_embed(webpage):
402 if match.group('type') == 'wistia_channel':
403 # original url may contain wmediaid query param
404 yield update_url_query(f'wistiachannel:{match.group("id")}', parse_qs(url))