]>
Commit | Line | Data |
---|---|---|
e423e0ba S |
1 | from __future__ import unicode_literals |
2 | ||
58bb4402 S |
3 | import re |
4 | ||
ef4fd848 | 5 | from .common import InfoExtractor |
5c2266df S |
6 | from ..utils import ( |
7 | ExtractorError, | |
cf45ed78 | 8 | int_or_none, |
7ded6545 | 9 | float_or_none, |
58bb4402 | 10 | unescapeHTML, |
5c2266df | 11 | ) |
ef4fd848 PH |
12 | |
13 | ||
14 | class WistiaIE(InfoExtractor): | |
152f2292 | 15 | _VALID_URL = r'(?:wistia:|https?://(?:fast\.)?wistia\.(?:net|com)/embed/(?:iframe|medias)/)(?P<id>[a-z0-9]{10})' |
233826f6 | 16 | _EMBED_BASE_URL = 'http://fast.wistia.com/embed/' |
ef4fd848 | 17 | |
f0c96af9 | 18 | _TESTS = [{ |
e423e0ba S |
19 | 'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt', |
20 | 'md5': 'cafeb56ec0c53c18c97405eecb3133df', | |
21 | 'info_dict': { | |
22 | 'id': 'sh7fpupwlt', | |
23 | 'ext': 'mov', | |
24 | 'title': 'Being Resourceful', | |
cf45ed78 | 25 | 'description': 'a Clients From Hell Video Series video from worldwidewebhosting', |
26 | 'upload_date': '20131204', | |
27 | 'timestamp': 1386185018, | |
e423e0ba | 28 | 'duration': 117, |
ef4fd848 | 29 | }, |
f0c96af9 S |
30 | }, { |
31 | 'url': 'wistia:sh7fpupwlt', | |
32 | 'only_matching': True, | |
45f160a4 S |
33 | }, { |
34 | # with hls video | |
35 | 'url': 'wistia:807fafadvk', | |
36 | 'only_matching': True, | |
641e86e3 S |
37 | }, { |
38 | 'url': 'http://fast.wistia.com/embed/iframe/sh7fpupwlt', | |
39 | 'only_matching': True, | |
ed8db0a2 S |
40 | }, { |
41 | 'url': 'http://fast.wistia.net/embed/medias/sh7fpupwlt.json', | |
42 | 'only_matching': True, | |
f0c96af9 | 43 | }] |
ef4fd848 | 44 | |
152f2292 | 45 | # https://wistia.com/support/embed-and-share/video-on-your-website |
58bb4402 S |
46 | @staticmethod |
47 | def _extract_url(webpage): | |
fda6d237 S |
48 | urls = WistiaIE._extract_urls(webpage) |
49 | return urls[0] if urls else None | |
58bb4402 | 50 | |
fda6d237 S |
51 | @staticmethod |
52 | def _extract_urls(webpage): | |
53 | urls = [] | |
54 | for match in re.finditer( | |
55 | r'<(?:meta[^>]+?content|(?:iframe|script)[^>]+?src)=["\'](?P<url>(?:https?:)?//(?:fast\.)?wistia\.(?:net|com)/embed/(?:iframe|medias)/[a-z0-9]{10})', webpage): | |
56 | urls.append(unescapeHTML(match.group('url'))) | |
57 | for match in re.finditer( | |
58 | r'''(?sx) | |
718393c6 | 59 | <div[^>]+class=(["'])(?:(?!\1).)*?\bwistia_async_(?P<id>[a-z0-9]{10})\b(?:(?!\1).)*?\1 |
fda6d237 S |
60 | ''', webpage): |
61 | urls.append('wistia:%s' % match.group('id')) | |
62 | for match in re.finditer(r'(?:data-wistia-?id=["\']|Wistia\.embed\(["\']|id=["\']wistia_)(?P<id>[a-z0-9]{10})', webpage): | |
63 | urls.append('wistia:%s' % match.group('id')) | |
64 | return urls | |
152f2292 | 65 | |
ef4fd848 | 66 | def _real_extract(self, url): |
1cc79574 | 67 | video_id = self._match_id(url) |
ef4fd848 | 68 | |
f0c96af9 | 69 | data_json = self._download_json( |
233826f6 | 70 | self._EMBED_BASE_URL + 'medias/%s.json' % video_id, video_id, |
f0c96af9 S |
71 | # Some videos require this. |
72 | headers={ | |
233826f6 | 73 | 'Referer': url if url.startswith('http') else self._EMBED_BASE_URL + 'iframe/' + video_id, |
f0c96af9 S |
74 | }) |
75 | ||
746c67d7 | 76 | if data_json.get('error'): |
f0c96af9 S |
77 | raise ExtractorError( |
78 | 'Error while getting the playlist', expected=True) | |
79 | ||
746c67d7 | 80 | data = data_json['media'] |
cf45ed78 | 81 | title = data['name'] |
ef4fd848 PH |
82 | |
83 | formats = [] | |
84 | thumbnails = [] | |
66ca2cfd | 85 | for a in data['assets']: |
36ca2c55 S |
86 | aurl = a.get('url') |
87 | if not aurl: | |
88 | continue | |
cf45ed78 | 89 | astatus = a.get('status') |
66ca2cfd | 90 | atype = a.get('type') |
36ca2c55 | 91 | if (astatus is not None and astatus != 2) or atype in ('preview', 'storyboard'): |
cf45ed78 | 92 | continue |
93 | elif atype in ('still', 'still_image'): | |
ef4fd848 | 94 | thumbnails.append({ |
36ca2c55 S |
95 | 'url': aurl, |
96 | 'width': int_or_none(a.get('width')), | |
97 | 'height': int_or_none(a.get('height')), | |
233826f6 | 98 | 'filesize': int_or_none(a.get('size')), |
ef4fd848 | 99 | }) |
cf45ed78 | 100 | else: |
45f160a4 | 101 | aext = a.get('ext') |
233826f6 RA |
102 | display_name = a.get('display_name') |
103 | format_id = atype | |
104 | if atype and atype.endswith('_video') and display_name: | |
105 | format_id = '%s-%s' % (atype[:-6], display_name) | |
106 | f = { | |
107 | 'format_id': format_id, | |
36ca2c55 | 108 | 'url': aurl, |
233826f6 | 109 | 'tbr': int_or_none(a.get('bitrate')) or None, |
cf45ed78 | 110 | 'preference': 1 if atype == 'original' else None, |
233826f6 RA |
111 | } |
112 | if display_name == 'Audio': | |
113 | f.update({ | |
114 | 'vcodec': 'none', | |
115 | }) | |
116 | else: | |
117 | f.update({ | |
118 | 'width': int_or_none(a.get('width')), | |
119 | 'height': int_or_none(a.get('height')), | |
120 | 'vcodec': a.get('codec'), | |
121 | }) | |
122 | if a.get('container') == 'm3u8' or aext == 'm3u8': | |
123 | ts_f = f.copy() | |
124 | ts_f.update({ | |
125 | 'ext': 'ts', | |
126 | 'format_id': f['format_id'].replace('hls-', 'ts-'), | |
127 | 'url': f['url'].replace('.bin', '.ts'), | |
128 | }) | |
129 | formats.append(ts_f) | |
130 | f.update({ | |
131 | 'ext': 'mp4', | |
132 | 'protocol': 'm3u8_native', | |
133 | }) | |
134 | else: | |
135 | f.update({ | |
136 | 'container': a.get('container'), | |
137 | 'ext': aext, | |
138 | 'filesize': int_or_none(a.get('size')), | |
139 | }) | |
140 | formats.append(f) | |
539179f4 PH |
141 | |
142 | self._sort_formats(formats) | |
ef4fd848 | 143 | |
233826f6 RA |
144 | subtitles = {} |
145 | for caption in data.get('captions', []): | |
146 | language = caption.get('language') | |
147 | if not language: | |
148 | continue | |
149 | subtitles[language] = [{ | |
150 | 'url': self._EMBED_BASE_URL + 'captions/' + video_id + '.vtt?language=' + language, | |
151 | }] | |
152 | ||
ef4fd848 PH |
153 | return { |
154 | 'id': video_id, | |
cf45ed78 | 155 | 'title': title, |
156 | 'description': data.get('seoDescription'), | |
ef4fd848 PH |
157 | 'formats': formats, |
158 | 'thumbnails': thumbnails, | |
7ded6545 | 159 | 'duration': float_or_none(data.get('duration')), |
cf45ed78 | 160 | 'timestamp': int_or_none(data.get('createdAt')), |
233826f6 | 161 | 'subtitles': subtitles, |
ef4fd848 | 162 | } |