]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/wistia.py
3 from .common
import InfoExtractor
13 class WistiaBaseIE(InfoExtractor
):
14 _VALID_ID_REGEX
= r
'(?P<id>[a-z0-9]{10})'
15 _VALID_URL_BASE
= r
'https?://(?:\w+\.)?wistia\.(?:net|com)/(?:embed/)?'
16 _EMBED_BASE_URL
= 'http://fast.wistia.com/embed/'
18 def _download_embed_config(self
, config_type
, config_id
, referer
):
19 base_url
= self
._EMBED
_BASE
_URL
+ '%ss/%s' % (config_type
, config_id
)
20 embed_config
= self
._download
_json
(
21 base_url
+ '.json', config_id
, headers
={
22 'Referer': referer
if referer
.startswith('http') else base_url
, # Some videos require this.
25 if isinstance(embed_config
, dict) and embed_config
.get('error'):
27 'Error while getting the playlist', expected
=True)
31 def _extract_media(self
, embed_config
):
32 data
= embed_config
['media']
33 video_id
= data
['hashedId']
38 for a
in data
['assets']:
42 astatus
= a
.get('status')
44 if (astatus
is not None and astatus
!= 2) or atype
in ('preview', 'storyboard'):
46 elif atype
in ('still', 'still_image'):
49 'width': int_or_none(a
.get('width')),
50 'height': int_or_none(a
.get('height')),
51 'filesize': int_or_none(a
.get('size')),
55 display_name
= a
.get('display_name')
57 if atype
and atype
.endswith('_video') and display_name
:
58 format_id
= '%s-%s' % (atype
[:-6], display_name
)
60 'format_id': format_id
,
62 'tbr': int_or_none(a
.get('bitrate')) or None,
63 'quality': 1 if atype
== 'original' else None,
65 if display_name
== 'Audio':
71 'width': int_or_none(a
.get('width')),
72 'height': int_or_none(a
.get('height')),
73 'vcodec': a
.get('codec'),
75 if a
.get('container') == 'm3u8' or aext
== 'm3u8':
79 'format_id': f
['format_id'].replace('hls-', 'ts-'),
80 'url': f
['url'].replace('.bin', '.ts'),
85 'protocol': 'm3u8_native',
89 'container': a
.get('container'),
91 'filesize': int_or_none(a
.get('size')),
95 self
._sort
_formats
(formats
)
98 for caption
in data
.get('captions', []):
99 language
= caption
.get('language')
102 subtitles
[language
] = [{
103 'url': self
._EMBED
_BASE
_URL
+ 'captions/' + video_id
+ '.vtt?language=' + language
,
109 'description': data
.get('seoDescription'),
111 'thumbnails': thumbnails
,
112 'duration': float_or_none(data
.get('duration')),
113 'timestamp': int_or_none(data
.get('createdAt')),
114 'subtitles': subtitles
,
118 class WistiaIE(WistiaBaseIE
):
119 _VALID_URL
= r
'(?:wistia:|%s(?:iframe|medias)/)%s' % (WistiaBaseIE
._VALID
_URL
_BASE
, WistiaBaseIE
._VALID
_ID
_REGEX
)
123 'url': 'wistia:807fafadvk',
124 'md5': 'daff0f3687a41d9a71b40e0e8c2610fe',
128 'title': 'Drip Brennan Dunn Workshop',
129 'description': 'a JV Webinars video',
130 'upload_date': '20160518',
131 'timestamp': 1463607249,
135 'url': 'wistia:sh7fpupwlt',
136 'only_matching': True,
138 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
139 'only_matching': True,
141 'url': 'http://fast.wistia.com/embed/iframe/sh7fpupwlt',
142 'only_matching': True,
144 'url': 'http://fast.wistia.net/embed/medias/sh7fpupwlt.json',
145 'only_matching': True,
148 # https://wistia.com/support/embed-and-share/video-on-your-website
150 def _extract_url(webpage
):
151 urls
= WistiaIE
._extract
_urls
(webpage
)
152 return urls
[0] if urls
else None
155 def _extract_urls(webpage
):
157 for match
in re
.finditer(
158 r
'<(?:meta[^>]+?content|(?:iframe|script)[^>]+?src)=["\'](?P
<url
>(?
:https?
:)?
//(?
:fast\
.)?wistia\
.(?
:net|com
)/embed
/(?
:iframe|medias
)/[a
-z0
-9]{10}
)', webpage):
159 urls.append(unescapeHTML(match.group('url
')))
160 for match in re.finditer(
162 <div[^>]+class=(["'])(?
:(?
!\
1).)*?
\bwistia
_async
_(?P
<id>[a
-z0
-9]{10}
)\b(?
:(?
!\
1).)*?\
1
164 urls.append('wistia:%s' % match.group('id'))
165 for match in re.finditer(r'(?:data-wistia-?id=["\']|Wistia\.embed\(["\']|id=["\']wistia_)(?P<id>[a-z0-9]{10})', webpage):
166 urls.append('wistia:%s' % match.group('id'))
169 def _real_extract(self, url):
170 video_id = self._match_id(url)
171 embed_config = self._download_embed_config('media', video_id, url)
172 return self._extract_media(embed_config)
175 class WistiaPlaylistIE(WistiaBaseIE):
176 _VALID_URL = r'%splaylists/%s' % (WistiaBaseIE._VALID_URL_BASE, WistiaBaseIE._VALID_ID_REGEX)
179 'url': 'https://fast.wistia.net/embed/playlists/aodt9etokc',
186 def _real_extract(self, url):
187 playlist_id = self._match_id(url)
188 playlist = self._download_embed_config('playlist', playlist_id, url)
191 for media in (try_get(playlist, lambda x: x[0]['medias']) or []):
192 embed_config = media.get('embed_config')
195 entries.append(self._extract_media(embed_config))
197 return self.playlist_result(entries, playlist_id)