1 from __future__ import unicode_literals
5 from .common import InfoExtractor
14 class WistiaIE(InfoExtractor):
15 _VALID_URL = r'(?:wistia:|https?://(?:fast\.)?wistia\.(?:net|com)/embed/(?:iframe|medias)/)(?P<id>[a-z0-9]{10})'
16 _EMBED_BASE_URL = 'http://fast.wistia.com/embed/'
19 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt',
20 'md5': 'cafeb56ec0c53c18c97405eecb3133df',
24 'title': 'Being Resourceful',
25 'description': 'a Clients From Hell Video Series video from worldwidewebhosting',
26 'upload_date': '20131204',
27 'timestamp': 1386185018,
31 'url': 'wistia:sh7fpupwlt',
32 'only_matching': True,
35 'url': 'wistia:807fafadvk',
36 'only_matching': True,
38 'url': 'http://fast.wistia.com/embed/iframe/sh7fpupwlt',
39 'only_matching': True,
41 'url': 'http://fast.wistia.net/embed/medias/sh7fpupwlt.json',
42 'only_matching': True,
45 # https://wistia.com/support/embed-and-share/video-on-your-website
47 def _extract_url(webpage):
49 r'<(?:meta[^>]+?content|(?:iframe|script)[^>]+?src)=["\'](?P<url>(?:https?:)?//(?:fast\.)?wistia\.(?:net|com)/embed/(?:iframe|medias)/[a-z0-9]{10})', webpage)
51 return unescapeHTML(match.group('url'))
55 <script[^>]+src=(["'])(?:https?:)?//fast\.wistia\.com/assets/external/E-v1\.js\1[^>]*>.*?
56 <div[^>]+class=(["']).*?\bwistia_async_(?P<id>[a-z0-9]{10})\b.*?\2
59 return 'wistia:%s' % match.group('id')
61 match = re.search(r'(?:data-wistia-?id=["\']|Wistia\.embed\(["\']|id=["\']wistia_)(?P<id>[a-z0-9]{10})', webpage)
63 return 'wistia:%s' % match.group('id')
65 def _real_extract(self, url):
66 video_id = self._match_id(url)
68 data_json = self._download_json(
69 self._EMBED_BASE_URL + 'medias/%s.json' % video_id, video_id,
70 # Some videos require this.
72 'Referer': url if url.startswith('http') else self._EMBED_BASE_URL + 'iframe/' + video_id,
75 if data_json.get('error'):
77 'Error while getting the playlist', expected=True)
79 data = data_json['media']
84 for a in data['assets']:
88 astatus = a.get('status')
90 if (astatus is not None and astatus != 2) or atype in ('preview', 'storyboard'):
92 elif atype in ('still', 'still_image'):
95 'width': int_or_none(a.get('width')),
96 'height': int_or_none(a.get('height')),
97 'filesize': int_or_none(a.get('size')),
101 display_name = a.get('display_name')
103 if atype and atype.endswith('_video') and display_name:
104 format_id = '%s-%s' % (atype[:-6], display_name)
106 'format_id': format_id,
108 'tbr': int_or_none(a.get('bitrate')) or None,
109 'preference': 1 if atype == 'original' else None,
111 if display_name == 'Audio':
117 'width': int_or_none(a.get('width')),
118 'height': int_or_none(a.get('height')),
119 'vcodec': a.get('codec'),
121 if a.get('container') == 'm3u8' or aext == 'm3u8':
125 'format_id': f['format_id'].replace('hls-', 'ts-'),
126 'url': f['url'].replace('.bin', '.ts'),
131 'protocol': 'm3u8_native',
135 'container': a.get('container'),
137 'filesize': int_or_none(a.get('size')),
141 self._sort_formats(formats)
144 for caption in data.get('captions', []):
145 language = caption.get('language')
148 subtitles[language] = [{
149 'url': self._EMBED_BASE_URL + 'captions/' + video_id + '.vtt?language=' + language,
155 'description': data.get('seoDescription'),
157 'thumbnails': thumbnails,
158 'duration': float_or_none(data.get('duration')),
159 'timestamp': int_or_none(data.get('createdAt')),
160 'subtitles': subtitles,