]>
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')),
102 for caption
in data
.get('captions', []):
103 language
= caption
.get('language')
106 subtitles
[language
] = [{
107 'url': self
._EMBED
_BASE
_URL
+ 'captions/' + video_id
+ '.vtt?language=' + language
,
113 'description': data
.get('seoDescription'),
115 'thumbnails': thumbnails
,
116 'duration': float_or_none(data
.get('duration')),
117 'timestamp': int_or_none(data
.get('createdAt')),
118 'subtitles': subtitles
,
122 def _extract_from_webpage(cls
, url
, webpage
):
123 from .teachable
import TeachableIE
125 if list(TeachableIE
._extract
_embed
_urls
(url
, webpage
)):
128 yield from super()._extract
_from
_webpage
(url
, webpage
)
131 def _extract_wistia_async_embed(cls
, webpage
):
132 # https://wistia.com/support/embed-and-share/video-on-your-website
133 # https://wistia.com/support/embed-and-share/channel-embeds
134 yield from re
.finditer(
136 <(?:div|section)[^>]+class=([\"'])(?:(?!\1).)*?(?P<type>wistia[a-z_0-9]+)\s*\bwistia_async_(?P<id>[a-z0-9]{10})\b(?:(?!\1).)*?\1
140 def _extract_url_media_id(cls
, url
):
141 mobj
= re
.search(r
'(?:wmediaid|wvideo(?:id)?)]?=(?P<id>[a-z0-9]{10})', urllib
.parse
.unquote_plus(url
))
143 return mobj
.group('id')
146 class WistiaIE(WistiaBaseIE
):
147 _VALID_URL
= r
'(?:wistia:|%s(?:iframe|medias)/)%s' % (WistiaBaseIE
._VALID
_URL
_BASE
, WistiaBaseIE
._VALID
_ID
_REGEX
)
150 <(?:meta[^>]+?content|(?:iframe|script)[^>]+?src)=["\']
151 (?P
<url
>(?
:https?
:)?
//(?
:fast\
.)?wistia\
.(?
:net|com
)/embed
/(?
:iframe|medias
)/[a
-z0
-9]{10}
)
155 'url': 'wistia:807fafadvk',
156 'md5': 'daff0f3687a41d9a71b40e0e8c2610fe',
160 'title': 'Drip Brennan Dunn Workshop',
161 'description': 'a JV Webinars video',
162 'upload_date': '20160518',
163 'timestamp': 1463607249,
166 'skip': 'video unavailable',
168 'url': 'wistia:a6ndpko1wg',
169 'md5': '10c1ce9c4dde638202513ed17a3767bd',
173 'title': 'Episode 2: Boxed Water\'s retention is thirsty',
174 'upload_date': '20210324',
175 'description': 'md5:da5994c2c2d254833b412469d9666b7a',
177 'timestamp': 1616614369,
178 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/53dc60239348dc9b9fba3755173ea4c2.bin',
181 'url': 'wistia:5vd7p4bct5',
182 'md5': 'b9676d24bf30945d97060638fbfe77f0',
186 'title': 'md5:eaa9f64c4efd7b5f098b9b6118597679',
187 'description': 'md5:a9bea0315f0616aa5df2dc413ddcdd0f',
188 'upload_date': '20220915',
189 'timestamp': 1663258727,
191 'thumbnail': r're:https?://embed(?:-ssl)?.wistia.com/.+\.(?:jpg|bin)$',
194 'url': 'wistia:sh7fpupwlt',
195 'only_matching': True,
197 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
198 'only_matching': True,
200 'url': 'http://fast.wistia.com/embed/iframe/sh7fpupwlt',
201 'only_matching': True,
203 'url': 'http://fast.wistia.net/embed/medias/sh7fpupwlt.json',
204 'only_matching': True,
208 'url': 'https://www.weidert.com/blog/wistia-channels-video-marketing-tool',
212 'title': 'How Wistia Channels Can Help Capture Inbound Value From Your Video Content',
214 'timestamp': 1618974400,
215 'description': 'md5:27abc99a758573560be72600ef95cece',
216 'upload_date': '20210421',
217 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/6c551820ae950cdee2306d6cbe9ef742.bin',
220 'url': 'https://study.com/academy/lesson/north-american-exploration-failed-colonies-of-spain-france-england.html#lesson',
221 'md5': 'b9676d24bf30945d97060638fbfe77f0',
225 'title': 'paywall_north-american-exploration-failed-colonies-of-spain-france-england',
226 'upload_date': '20220915',
227 'timestamp': 1663258727,
229 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/83e6ec693e2c05a0ce65809cbaead86a.bin',
230 'description': 'a Paywall Videos video',
234 def _real_extract(self, url):
235 video_id = self._match_id(url)
236 embed_config = self._download_embed_config('medias', video_id, url)
237 return self._extract_media(embed_config)
240 def _extract_embed_urls(cls, url, webpage):
241 urls = list(super()._extract_embed_urls(url, webpage))
242 for match in cls._extract_wistia_async_embed(webpage):
243 if match.group('type') != 'wistia_channel':
244 urls.append('wistia:%s' % match.group('id'))
245 for match in re.finditer(r'(?:data-wistia-?id=["\']|Wistia\.embed\(["\']|id=["\']wistia_)(?P<id>[a-z0-9]{10})',
247 urls.append('wistia:%s' % match.group('id'))
248 if not WistiaChannelIE._extract_embed_urls(url, webpage): # Fallback
249 media_id = cls._extract_url_media_id(url)
251 urls.append('wistia:%s' % match.group('id'))
255 class WistiaPlaylistIE(WistiaBaseIE):
256 _VALID_URL = r'%splaylists/%s' % (WistiaBaseIE._VALID_URL_BASE, WistiaBaseIE._VALID_ID_REGEX)
259 'url': 'https://fast.wistia.net/embed/playlists/aodt9etokc',
266 def _real_extract(self, url):
267 playlist_id = self._match_id(url)
268 playlist = self._download_embed_config('playlists', playlist_id, url)
271 for media in (try_get(playlist, lambda x: x[0]['medias']) or []):
272 embed_config = media.get('embed_config')
275 entries.append(self._extract_media(embed_config))
277 return self.playlist_result(entries, playlist_id)
280 class WistiaChannelIE(WistiaBaseIE):
281 _VALID_URL = r'(?:wistiachannel:|%schannel/)%s' % (WistiaBaseIE._VALID_URL_BASE, WistiaBaseIE._VALID_ID_REGEX)
284 # JSON Embed API returns 403, should fall back to webpage
285 'url': 'https://fast.wistia.net/embed/channel/yvyvu7wjbg?wchannelid=yvyvu7wjbg',
288 'title': 'Copysmith Tutorials and Education!',
289 'description': 'Learn all things Copysmith via short and informative videos!'
291 'playlist_mincount': 7,
292 'expected_warnings': ['falling back to webpage'],
294 'url': 'https://fast.wistia.net/embed/channel/3802iirk0l',
299 'playlist_mincount': 20,
301 # link to popup video, follow --no-playlist
302 'url': 'https://fast.wistia.net/embed/channel/3802iirk0l?wchannelid=3802iirk0l&wmediaid=sp5dqjzw3n',
306 'title': 'The Roof S2: The Modern CRO',
307 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/dadfa9233eaa505d5e0c85c23ff70741.bin',
309 'description': 'A sales leader on The Roof? Man, they really must be letting anyone up here this season.\n',
310 'timestamp': 1619790290,
311 'upload_date': '20210430',
313 'params': {'noplaylist': True, 'skip_download': True},
316 'url': 'https://www.profitwell.com/recur/boxed-out',
319 'title': 'Boxed Out',
320 'description': 'md5:14a8a93a1dbe236718e6a59f8c8c7bae',
322 'playlist_mincount': 30,
324 # section instead of div
325 'url': 'https://360learning.com/studio/onboarding-joei/',
328 'title': 'Onboarding Joei.',
329 'description': 'Coming to you weekly starting Feb 19th.',
331 'playlist_mincount': 20,
333 'url': 'https://amplitude.com/amplify-sessions?amp%5Bwmediaid%5D=pz0m0l0if3&%5Bwvideo%5D=pz0m0l0if3&wchannelid=emyjmwjf79&wmediaid=i8um783bdt',
336 'title': 'A Framework for Improving Product Team Performance',
338 'timestamp': 1653935275,
339 'upload_date': '20220530',
340 'description': 'Learn how to help your company improve and achieve your product related goals.',
342 'thumbnail': 'https://embed-ssl.wistia.com/deliveries/12fd19e56413d9d6f04e2185c16a6f8854e25226.bin',
344 'params': {'noplaylist': True, 'skip_download': True},
347 def _real_extract(self, url):
348 channel_id = self._match_id(url)
349 media_id = self._extract_url_media_id(url)
350 if not self._yes_playlist(channel_id, media_id, playlist_label='channel'):
351 return self.url_result(f'wistia:{media_id}', 'Wistia')
354 data = self._download_embed_config('channel', channel_id, url)
355 except (ExtractorError, urllib.error.HTTPError):
356 # Some channels give a 403 from the JSON API
357 self.report_warning('Failed to download channel data from API, falling back to webpage.')
358 webpage = self._download_webpage(f'https://fast.wistia.net/embed/channel/{channel_id}', channel_id)
359 data = self._parse_json(
360 self._search_regex(r'wchanneljsonp-%s\'\]\s*=[^\"]*\"([A-Za-z0-9=/]*)' % channel_id, webpage, 'jsonp', channel_id),
361 channel_id, transform_source=lambda x: urllib.parse.unquote_plus(b64decode(x).decode('utf-8')))
363 # XXX: can there be more than one series?
364 series = traverse_obj(data, ('series', 0), default={})
367 self.url_result(f'wistia:{video["hashedId"]}', WistiaIE, title=video.get('name'))
368 for video in traverse_obj(series, ('sections', ..., 'videos', ...)) or []
369 if video.get('hashedId')
372 return self.playlist_result(
373 entries, channel_id, playlist_title=series.get('title'), playlist_description=series.get('description'))
376 def _extract_embed_urls(cls, url, webpage):
377 yield from super()._extract_embed_urls(url, webpage)
378 for match in cls._extract_wistia_async_embed(webpage):
379 if match.group('type') == 'wistia_channel':
380 # original url may contain wmediaid query param
381 yield update_url_query(f'wistiachannel:{match.group("id")}', parse_qs(url))