| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 11:44:44 +01:00
										 |  |  | import re | 
					
						
							|  |  |  | import base64 | 
					
						
							|  |  |  | import json | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2014-02-07 12:03:19 +01:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     clean_html, | 
					
						
							|  |  |  |     ExtractorError | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2014-02-06 11:44:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ChilloutzoneIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?chilloutzone\.net/video/(?P<id>[\w|-]+)\.html' | 
					
						
							| 
									
										
										
										
											2014-02-07 15:42:31 +01:00
										 |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  |         'url': 'http://www.chilloutzone.net/video/enemene-meck-alle-katzen-weg.html', | 
					
						
							|  |  |  |         'md5': 'a76f3457e813ea0037e5244f509e66d1', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': 'enemene-meck-alle-katzen-weg', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Enemene Meck - Alle Katzen weg', | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |             'description': 'Ist das der Umkehrschluss des Niesenden Panda-Babys?', | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2014-02-07 15:42:31 +01:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'note': 'Video hosted at YouTube', | 
					
						
							|  |  |  |         'url': 'http://www.chilloutzone.net/video/eine-sekunde-bevor.html', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '1YVQaAgHyRU', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': '16 Photos Taken 1 Second Before Disaster', | 
					
						
							|  |  |  |             'description': 'md5:58a8fcf6a459fe0a08f54140f0ad1814', | 
					
						
							|  |  |  |             'uploader': 'BuzzFeedVideo', | 
					
						
							|  |  |  |             'uploader_id': 'BuzzFeedVideo', | 
					
						
							|  |  |  |             'upload_date': '20131105', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'note': 'Video hosted at Vimeo', | 
					
						
							|  |  |  |         'url': 'http://www.chilloutzone.net/video/icon-blending.html', | 
					
						
							|  |  |  |         'md5': '2645c678b8dc4fefcc0e1b60db18dac1', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '85523671', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'The Sunday Times - Icons', | 
					
						
							| 
									
										
										
										
											2014-09-13 09:04:03 +02:00
										 |  |  |             'description': 're:(?s)^Watch the making of - makingoficons.com.{300,}', | 
					
						
							| 
									
										
										
										
											2014-02-07 15:42:31 +01:00
										 |  |  |             'uploader': 'Us', | 
					
						
							|  |  |  |             'uploader_id': 'usfilms', | 
					
						
							|  |  |  |             'upload_date': '20140131' | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }] | 
					
						
							| 
									
										
										
										
											2014-02-06 11:44:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         mobj = re.match(self._VALID_URL, url) | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  |         video_id = mobj.group('id') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |         base64_video_info = self._html_search_regex( | 
					
						
							|  |  |  |             r'var cozVidData = "(.+?)";', webpage, 'video data') | 
					
						
							| 
									
										
										
										
											2015-05-22 00:03:47 +06:00
										 |  |  |         decoded_video_info = base64.b64decode(base64_video_info.encode('utf-8')).decode('utf-8') | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  |         video_info_dict = json.loads(decoded_video_info) | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  |         # get video information from dict | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |         video_url = video_info_dict['mediaUrl'] | 
					
						
							|  |  |  |         description = clean_html(video_info_dict.get('description')) | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  |         title = video_info_dict['title'] | 
					
						
							|  |  |  |         native_platform = video_info_dict['nativePlatform'] | 
					
						
							|  |  |  |         native_video_id = video_info_dict['nativeVideoId'] | 
					
						
							|  |  |  |         source_priority = video_info_dict['sourcePriority'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # If nativePlatform is None a fallback mechanism is used (i.e. youtube embed) | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |         if native_platform is None: | 
					
						
							|  |  |  |             youtube_url = self._html_search_regex( | 
					
						
							|  |  |  |                 r'<iframe.* src="((?:https?:)?//(?:[^.]+\.)?youtube\.com/.+?)"', | 
					
						
							|  |  |  |                 webpage, 'fallback video URL', default=None) | 
					
						
							|  |  |  |             if youtube_url is not None: | 
					
						
							|  |  |  |                 return self.url_result(youtube_url, ie='Youtube') | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Non Fallback: Decide to use native source (e.g. youtube or vimeo) or | 
					
						
							|  |  |  |         # the own CDN | 
					
						
							|  |  |  |         if source_priority == 'native': | 
					
						
							|  |  |  |             if native_platform == 'youtube': | 
					
						
							| 
									
										
										
										
											2014-02-07 12:29:58 +01:00
										 |  |  |                 return self.url_result(native_video_id, ie='Youtube') | 
					
						
							| 
									
										
										
										
											2014-02-06 11:44:44 +01:00
										 |  |  |             if native_platform == 'vimeo': | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |                 return self.url_result( | 
					
						
							|  |  |  |                     'http://vimeo.com/' + native_video_id, ie='Vimeo') | 
					
						
							| 
									
										
										
										
											2014-02-06 11:44:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |         if not video_url: | 
					
						
							|  |  |  |             raise ExtractorError('No video found') | 
					
						
							| 
									
										
										
										
											2014-02-06 11:44:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'url': video_url, | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2014-02-06 21:31:04 +01:00
										 |  |  |             'description': description, | 
					
						
							| 
									
										
										
										
											2014-02-07 12:00:25 +01:00
										 |  |  |         } |