| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 17:00:39 +02:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2018-09-11 02:41:05 +07:00
										 |  |  | from ..compat import compat_str | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							|  |  |  |     float_or_none, | 
					
						
							| 
									
										
										
										
											2018-09-11 02:41:05 +07:00
										 |  |  |     unified_timestamp, | 
					
						
							|  |  |  |     url_or_none, | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class VzaarIE(InfoExtractor): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:(?:www|view)\.)?vzaar\.com/(?:videos/)?(?P<id>\d+)' | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2018-09-11 02:41:05 +07:00
										 |  |  |         # HTTP and HLS | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  |         'url': 'https://vzaar.com/videos/1152805', | 
					
						
							|  |  |  |         'md5': 'bde5ddfeb104a6c56a93a06b04901dbf', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '1152805', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'sample video (public)', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'https://view.vzaar.com/27272/player', | 
					
						
							|  |  |  |         'md5': '3b50012ac9bbce7f445550d54e0508f2', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '27272', | 
					
						
							|  |  |  |             'ext': 'mp3', | 
					
						
							|  |  |  |             'title': 'MP3', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 17:00:39 +02:00
										 |  |  |     @staticmethod | 
					
						
							|  |  |  |     def _extract_urls(webpage): | 
					
						
							|  |  |  |         return re.findall( | 
					
						
							|  |  |  |             r'<iframe[^>]+src=["\']((?:https?:)?//(?:view\.vzaar\.com)/[0-9]+)', | 
					
						
							|  |  |  |             webpage) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         video_id = self._match_id(url) | 
					
						
							|  |  |  |         video_data = self._download_json( | 
					
						
							|  |  |  |             'http://view.vzaar.com/v2/%s/video' % video_id, video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 02:41:05 +07:00
										 |  |  |         title = video_data['videoTitle'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         source_url = url_or_none(video_data.get('sourceUrl')) | 
					
						
							|  |  |  |         if source_url: | 
					
						
							|  |  |  |             f = { | 
					
						
							|  |  |  |                 'url': source_url, | 
					
						
							|  |  |  |                 'format_id': 'http', | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if 'audio' in source_url: | 
					
						
							|  |  |  |                 f.update({ | 
					
						
							|  |  |  |                     'vcodec': 'none', | 
					
						
							|  |  |  |                     'ext': 'mp3', | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 f.update({ | 
					
						
							|  |  |  |                     'width': int_or_none(video_data.get('width')), | 
					
						
							|  |  |  |                     'height': int_or_none(video_data.get('height')), | 
					
						
							|  |  |  |                     'ext': 'mp4', | 
					
						
							|  |  |  |                     'fps': float_or_none(video_data.get('fps')), | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |             formats.append(f) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         video_guid = video_data.get('guid') | 
					
						
							|  |  |  |         usp = video_data.get('usp') | 
					
						
							|  |  |  |         if isinstance(video_guid, compat_str) and isinstance(usp, dict): | 
					
						
							|  |  |  |             m3u8_url = ('http://fable.vzaar.com/v4/usp/%s/%s.ism/.m3u8?' | 
					
						
							|  |  |  |                         % (video_guid, video_id)) + '&'.join( | 
					
						
							|  |  |  |                 '%s=%s' % (k, v) for k, v in usp.items()) | 
					
						
							|  |  |  |             formats.extend(self._extract_m3u8_formats( | 
					
						
							|  |  |  |                 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native', | 
					
						
							|  |  |  |                 m3u8_id='hls', fatal=False)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2018-09-11 02:41:05 +07:00
										 |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  |             'thumbnail': self._proto_relative_url(video_data.get('poster')), | 
					
						
							|  |  |  |             'duration': float_or_none(video_data.get('videoDuration')), | 
					
						
							| 
									
										
										
										
											2018-09-11 02:41:05 +07:00
										 |  |  |             'timestamp': unified_timestamp(video_data.get('ts')), | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:25 +01:00
										 |  |  |         } |