| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							|  |  |  |     clean_html, | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |     extract_attributes, | 
					
						
							|  |  |  |     float_or_none, | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |     int_or_none, | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |     try_get, | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  | class EllenTubeBaseIE(InfoExtractor): | 
					
						
							|  |  |  |     def _extract_data_config(self, webpage, video_id): | 
					
						
							|  |  |  |         details = self._search_regex( | 
					
						
							|  |  |  |             r'(<[^>]+\bdata-component=(["\'])[Dd]etails.+?></div>)', webpage, | 
					
						
							|  |  |  |             'details') | 
					
						
							|  |  |  |         return self._parse_json( | 
					
						
							|  |  |  |             extract_attributes(details)['data-config'], video_id) | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |     def _extract_video(self, data, video_id): | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |         title = data['title'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  |         duration = None | 
					
						
							|  |  |  |         for entry in data.get('media'): | 
					
						
							|  |  |  |             if entry.get('id') == 'm3u8': | 
					
						
							|  |  |  |                 formats = self._extract_m3u8_formats( | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |                     entry['url'], video_id, 'mp4', | 
					
						
							|  |  |  |                     entry_protocol='m3u8_native', m3u8_id='hls') | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |                 duration = int_or_none(entry.get('duration')) | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         def get_insight(kind): | 
					
						
							|  |  |  |             return int_or_none(try_get( | 
					
						
							|  |  |  |                 data, lambda x: x['insight']['%ss' % kind])) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |         return { | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |             'extractor_key': EllenTubeIE.ie_key(), | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |             'description': data.get('description'), | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |             'duration': duration, | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |             'thumbnail': data.get('thumbnail'), | 
					
						
							|  |  |  |             'timestamp': float_or_none(data.get('publishTime'), scale=1000), | 
					
						
							|  |  |  |             'view_count': get_insight('view'), | 
					
						
							|  |  |  |             'like_count': get_insight('like'), | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |             'formats': formats, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  | class EllenTubeIE(EllenTubeBaseIE): | 
					
						
							|  |  |  |     _VALID_URL = r'''(?x)
 | 
					
						
							|  |  |  |                         (?: | 
					
						
							|  |  |  |                             ellentube:| | 
					
						
							|  |  |  |                             https://api-prod\.ellentube\.com/ellenapi/api/item/ | 
					
						
							|  |  |  |                         ) | 
					
						
							|  |  |  |                         (?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}) | 
					
						
							|  |  |  |                     '''
 | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'https://api-prod.ellentube.com/ellenapi/api/item/0822171c-3829-43bf-b99f-d77358ae75e3', | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |         'md5': '2fabc277131bddafdd120e0fc0f974c9', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '0822171c-3829-43bf-b99f-d77358ae75e3', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Ellen Meets Las Vegas Survivors Jesus Campos and Stephen Schuck', | 
					
						
							|  |  |  |             'description': 'md5:76e3355e2242a78ad9e3858e5616923f', | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |             'thumbnail': r're:^https?://.+?', | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |             'duration': 514, | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |             'timestamp': 1508505120, | 
					
						
							|  |  |  |             'upload_date': '20171020', | 
					
						
							|  |  |  |             'view_count': int, | 
					
						
							|  |  |  |             'like_count': int, | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'ellentube:734a3353-f697-4e79-9ca9-bfc3002dc1e0', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }] | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							|  |  |  |         data = self._download_json( | 
					
						
							|  |  |  |             'https://api-prod.ellentube.com/ellenapi/api/item/%s' % video_id, | 
					
						
							|  |  |  |             video_id) | 
					
						
							|  |  |  |         return self._extract_video(data, video_id) | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  | class EllenTubeVideoIE(EllenTubeBaseIE): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:www\.)?ellentube\.com/video/(?P<id>.+?)\.html' | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							|  |  |  |         'url': 'https://www.ellentube.com/video/ellen-meets-las-vegas-survivors-jesus-campos-and-stephen-schuck.html', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         display_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |         webpage = self._download_webpage(url, display_id) | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |         video_id = self._extract_data_config(webpage, display_id)['id'] | 
					
						
							|  |  |  |         return self.url_result( | 
					
						
							|  |  |  |             'ellentube:%s' % video_id, ie=EllenTubeIE.ie_key(), | 
					
						
							|  |  |  |             video_id=video_id) | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  | class EllenTubePlaylistIE(EllenTubeBaseIE): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:www\.)?ellentube\.com/(?:episode|studios)/(?P<id>.+?)\.html' | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |         'url': 'https://www.ellentube.com/episode/dax-shepard-jordan-fisher-haim.html', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': 'dax-shepard-jordan-fisher-haim', | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |             'title': "Dax Shepard, 'DWTS' Team Jordan Fisher & Lindsay Arnold, HAIM", | 
					
						
							|  |  |  |             'description': 'md5:bfc982194dabb3f4e325e43aa6b2e21c', | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |         'playlist_count': 6, | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |     }, { | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  |         'url': 'https://www.ellentube.com/studios/macey-goes-rving0.html', | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }] | 
					
						
							| 
									
										
										
										
											2017-10-23 21:15:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         display_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2017-12-09 02:16:23 +07:00
										 |  |  |         webpage = self._download_webpage(url, display_id) | 
					
						
							|  |  |  |         data = self._extract_data_config(webpage, display_id)['data'] | 
					
						
							|  |  |  |         feed = self._download_json( | 
					
						
							|  |  |  |             'https://api-prod.ellentube.com/ellenapi/api/feed/?%s' | 
					
						
							|  |  |  |             % data['filter'], display_id) | 
					
						
							|  |  |  |         entries = [ | 
					
						
							|  |  |  |             self._extract_video(elem, elem['id']) | 
					
						
							|  |  |  |             for elem in feed if elem.get('type') == 'VIDEO' and elem.get('id')] | 
					
						
							|  |  |  |         return self.playlist_result( | 
					
						
							|  |  |  |             entries, display_id, data.get('title'), | 
					
						
							|  |  |  |             clean_html(data.get('description'))) |