| 
									
										
										
										
											2016-02-15 17:07:13 -08:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-15 17:07:13 -08:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							|  |  |  |     unified_strdate, | 
					
						
							| 
									
										
										
										
											2016-05-13 05:21:45 +01:00
										 |  |  |     unescapeHTML, | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-02-15 17:07:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class UstudioIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-05-13 05:21:45 +01:00
										 |  |  |     IE_NAME = 'ustudio' | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  |     _VALID_URL = r'https?://(?:(?:www|v1)\.)?ustudio\.com/video/(?P<id>[^/]+)/(?P<display_id>[^/?#&]+)' | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							|  |  |  |         'url': 'http://ustudio.com/video/Uxu2my9bgSph/san_francisco_golden_gate_bridge', | 
					
						
							|  |  |  |         'md5': '58bbfca62125378742df01fc2abbdef6', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': 'Uxu2my9bgSph', | 
					
						
							|  |  |  |             'display_id': 'san_francisco_golden_gate_bridge', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'San Francisco: Golden Gate Bridge', | 
					
						
							|  |  |  |             'description': 'md5:23925500697f2c6d4830e387ba51a9be', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg$', | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  |             'upload_date': '20111107', | 
					
						
							|  |  |  |             'uploader': 'Tony Farley', | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-15 17:07:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2016-05-13 05:21:45 +01:00
										 |  |  |         video_id, display_id = re.match(self._VALID_URL, url).groups() | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         config = self._download_xml( | 
					
						
							|  |  |  |             'http://v1.ustudio.com/embed/%s/ustudio/config.xml' % video_id, | 
					
						
							|  |  |  |             display_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def extract(kind): | 
					
						
							|  |  |  |             return [{ | 
					
						
							| 
									
										
										
										
											2016-05-13 05:21:45 +01:00
										 |  |  |                 'url': unescapeHTML(item.attrib['url']), | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  |                 'width': int_or_none(item.get('width')), | 
					
						
							|  |  |  |                 'height': int_or_none(item.get('height')), | 
					
						
							|  |  |  |             } for item in config.findall('./qualities/quality/%s' % kind) if item.get('url')] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = extract('video') | 
					
						
							| 
									
										
										
										
											2016-02-15 17:07:13 -08:00
										 |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  |         webpage = self._download_webpage(url, display_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         title = self._og_search_title(webpage) | 
					
						
							|  |  |  |         upload_date = unified_strdate(self._search_regex( | 
					
						
							|  |  |  |             r'(?s)Uploaded by\s*.+?\s*on\s*<span>([^<]+)</span>', | 
					
						
							|  |  |  |             webpage, 'upload date', fatal=False)) | 
					
						
							|  |  |  |         uploader = self._search_regex( | 
					
						
							|  |  |  |             r'Uploaded by\s*<a[^>]*>([^<]+)<', | 
					
						
							|  |  |  |             webpage, 'uploader', fatal=False) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-15 17:07:13 -08:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  |             'display_id': display_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2016-02-15 17:07:13 -08:00
										 |  |  |             'description': self._og_search_description(webpage), | 
					
						
							| 
									
										
										
										
											2016-02-25 21:30:19 +06:00
										 |  |  |             'thumbnails': extract('image'), | 
					
						
							|  |  |  |             'upload_date': upload_date, | 
					
						
							|  |  |  |             'uploader': uploader, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2016-02-15 17:07:13 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-13 05:21:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class UstudioEmbedIE(InfoExtractor): | 
					
						
							|  |  |  |     IE_NAME = 'ustudio:embed' | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:(?:app|embed)\.)?ustudio\.com/embed/(?P<uid>[^/]+)/(?P<id>[^/]+)' | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							|  |  |  |         'url': 'http://app.ustudio.com/embed/DeN7VdYRDKhP/Uw7G1kMCe65T', | 
					
						
							|  |  |  |         'md5': '47c0be52a09b23a7f40de9469cec58f4', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': 'Uw7G1kMCe65T', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': '5 Things IT Should Know About Video', | 
					
						
							|  |  |  |             'description': 'md5:93d32650884b500115e158c5677d25ad', | 
					
						
							|  |  |  |             'uploader_id': 'DeN7VdYRDKhP', | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         uploader_id, video_id = re.match(self._VALID_URL, url).groups() | 
					
						
							|  |  |  |         video_data = self._download_json( | 
					
						
							|  |  |  |             'http://app.ustudio.com/embed/%s/%s/config.json' % (uploader_id, video_id), | 
					
						
							|  |  |  |             video_id)['videos'][0] | 
					
						
							|  |  |  |         title = video_data['name'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  |         for ext, qualities in video_data.get('transcodes', {}).items(): | 
					
						
							|  |  |  |             for quality in qualities: | 
					
						
							|  |  |  |                 quality_url = quality.get('url') | 
					
						
							|  |  |  |                 if not quality_url: | 
					
						
							|  |  |  |                     continue | 
					
						
							|  |  |  |                 height = int_or_none(quality.get('height')) | 
					
						
							|  |  |  |                 formats.append({ | 
					
						
							|  |  |  |                     'format_id': '%s-%dp' % (ext, height) if height else ext, | 
					
						
							|  |  |  |                     'url': quality_url, | 
					
						
							|  |  |  |                     'width': int_or_none(quality.get('width')), | 
					
						
							|  |  |  |                     'height': height, | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         thumbnails = [] | 
					
						
							|  |  |  |         for image in video_data.get('images', []): | 
					
						
							|  |  |  |             image_url = image.get('url') | 
					
						
							|  |  |  |             if not image_url: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             thumbnails.append({ | 
					
						
							|  |  |  |                 'url': image_url, | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'description': video_data.get('description'), | 
					
						
							|  |  |  |             'duration': int_or_none(video_data.get('duration')), | 
					
						
							|  |  |  |             'uploader_id': uploader_id, | 
					
						
							|  |  |  |             'tags': video_data.get('keywords'), | 
					
						
							|  |  |  |             'thumbnails': thumbnails, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							|  |  |  |         } |