| 
									
										
										
										
											2014-06-24 19:34:39 +07:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |     int_or_none, | 
					
						
							| 
									
										
										
										
											2016-05-20 21:43:36 +06:00
										 |  |  |     float_or_none, | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WistiaIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-05-20 20:55:10 +06:00
										 |  |  |     _VALID_URL = r'(?:wistia:|https?://(?:fast\.)?wistia\.net/embed/iframe/)(?P<id>[a-z0-9]+)' | 
					
						
							|  |  |  |     _API_URL = 'http://fast.wistia.com/embed/medias/%s.json' | 
					
						
							|  |  |  |     _IFRAME_URL = 'http://fast.wistia.net/embed/iframe/%s' | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-20 20:55:10 +06:00
										 |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2014-06-24 19:34:39 +07:00
										 |  |  |         'url': 'http://fast.wistia.net/embed/iframe/sh7fpupwlt', | 
					
						
							|  |  |  |         'md5': 'cafeb56ec0c53c18c97405eecb3133df', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': 'sh7fpupwlt', | 
					
						
							|  |  |  |             'ext': 'mov', | 
					
						
							|  |  |  |             'title': 'Being Resourceful', | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |             'description': 'a Clients From Hell Video Series video from worldwidewebhosting', | 
					
						
							|  |  |  |             'upload_date': '20131204', | 
					
						
							|  |  |  |             'timestamp': 1386185018, | 
					
						
							| 
									
										
										
										
											2014-06-24 19:34:39 +07:00
										 |  |  |             'duration': 117, | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-05-20 20:55:10 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'wistia:sh7fpupwlt', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2016-05-20 21:16:08 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         # with hls video | 
					
						
							|  |  |  |         'url': 'wistia:807fafadvk', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2016-05-20 20:55:10 +06:00
										 |  |  |     }] | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-20 20:55:10 +06:00
										 |  |  |         data_json = self._download_json( | 
					
						
							|  |  |  |             self._API_URL % video_id, video_id, | 
					
						
							|  |  |  |             # Some videos require this. | 
					
						
							|  |  |  |             headers={ | 
					
						
							|  |  |  |                 'Referer': url if url.startswith('http') else self._IFRAME_URL % video_id, | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-20 03:02:11 +03:00
										 |  |  |         if data_json.get('error'): | 
					
						
							| 
									
										
										
										
											2016-05-20 20:55:10 +06:00
										 |  |  |             raise ExtractorError( | 
					
						
							|  |  |  |                 'Error while getting the playlist', expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-20 03:02:11 +03:00
										 |  |  |         data = data_json['media'] | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |         title = data['name'] | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  |         thumbnails = [] | 
					
						
							| 
									
										
										
										
											2016-03-01 23:26:53 +06:00
										 |  |  |         for a in data['assets']: | 
					
						
							| 
									
										
										
										
											2016-05-20 21:04:01 +06:00
										 |  |  |             aurl = a.get('url') | 
					
						
							|  |  |  |             if not aurl: | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |             astatus = a.get('status') | 
					
						
							| 
									
										
										
										
											2016-03-01 23:26:53 +06:00
										 |  |  |             atype = a.get('type') | 
					
						
							| 
									
										
										
										
											2016-05-20 21:04:01 +06:00
										 |  |  |             if (astatus is not None and astatus != 2) or atype in ('preview', 'storyboard'): | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |                 continue | 
					
						
							|  |  |  |             elif atype in ('still', 'still_image'): | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  |                 thumbnails.append({ | 
					
						
							| 
									
										
										
										
											2016-05-20 21:04:01 +06:00
										 |  |  |                     'url': aurl, | 
					
						
							|  |  |  |                     'width': int_or_none(a.get('width')), | 
					
						
							|  |  |  |                     'height': int_or_none(a.get('height')), | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2016-05-20 21:16:08 +06:00
										 |  |  |                 aext = a.get('ext') | 
					
						
							|  |  |  |                 is_m3u8 = a.get('container') == 'm3u8' or aext == 'm3u8' | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |                 formats.append({ | 
					
						
							|  |  |  |                     'format_id': atype, | 
					
						
							| 
									
										
										
										
											2016-05-20 21:04:01 +06:00
										 |  |  |                     'url': aurl, | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |                     'tbr': int_or_none(a.get('bitrate')), | 
					
						
							|  |  |  |                     'vbr': int_or_none(a.get('opt_vbitrate')), | 
					
						
							|  |  |  |                     'width': int_or_none(a.get('width')), | 
					
						
							|  |  |  |                     'height': int_or_none(a.get('height')), | 
					
						
							|  |  |  |                     'filesize': int_or_none(a.get('size')), | 
					
						
							|  |  |  |                     'vcodec': a.get('codec'), | 
					
						
							|  |  |  |                     'container': a.get('container'), | 
					
						
							| 
									
										
										
										
											2016-05-20 21:16:08 +06:00
										 |  |  |                     'ext': 'mp4' if is_m3u8 else aext, | 
					
						
							|  |  |  |                     'protocol': 'm3u8' if is_m3u8 else None, | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |                     'preference': 1 if atype == 'original' else None, | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2013-12-25 15:20:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |             'title': title, | 
					
						
							|  |  |  |             'description': data.get('seoDescription'), | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  |             'formats': formats, | 
					
						
							|  |  |  |             'thumbnails': thumbnails, | 
					
						
							| 
									
										
										
										
											2016-05-20 21:43:36 +06:00
										 |  |  |             'duration': float_or_none(data.get('duration')), | 
					
						
							| 
									
										
										
										
											2016-03-17 17:48:17 +01:00
										 |  |  |             'timestamp': int_or_none(data.get('createdAt')), | 
					
						
							| 
									
										
										
										
											2013-12-06 09:15:04 +01:00
										 |  |  |         } |