| 
									
										
										
										
											2016-03-16 21:26:25 +01:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  | from .adobepass import AdobePassIE | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							|  |  |  |     smuggle_url, | 
					
						
							|  |  |  |     update_url_query, | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-03-16 21:26:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  | class BravoTVIE(AdobePassIE): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:www\.)?bravotv\.com/(?:[^/]+/)+(?P<id>[^/?#]+)' | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |         'url': 'https://www.bravotv.com/top-chef/season-16/episode-15/videos/the-top-chef-season-16-winner-is', | 
					
						
							|  |  |  |         'md5': 'e34684cfea2a96cd2ee1ef3a60909de9', | 
					
						
							| 
									
										
										
										
											2016-03-16 21:26:25 +01:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |             'id': 'epL0pmK1kQlT', | 
					
						
							| 
									
										
										
										
											2016-03-16 21:26:25 +01:00
										 |  |  |             'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |             'title': 'The Top Chef Season 16 Winner Is...', | 
					
						
							|  |  |  |             'description': 'Find out who takes the title of Top Chef!', | 
					
						
							| 
									
										
										
										
											2016-04-01 18:06:11 +01:00
										 |  |  |             'uploader': 'NBCU-BRAV', | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |             'upload_date': '20190314', | 
					
						
							|  |  |  |             'timestamp': 1552591860, | 
					
						
							| 
									
										
										
										
											2016-03-16 21:26:25 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }] | 
					
						
							| 
									
										
										
										
											2016-03-16 21:26:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |         display_id = self._match_id(url) | 
					
						
							|  |  |  |         webpage = self._download_webpage(url, display_id) | 
					
						
							|  |  |  |         settings = self._parse_json(self._search_regex( | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |             r'<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>({.+?})</script>', webpage, 'drupal settings'), | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |             display_id) | 
					
						
							|  |  |  |         info = {} | 
					
						
							|  |  |  |         query = { | 
					
						
							|  |  |  |             'mbr': 'true', | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         account_pid, release_pid = [None] * 2 | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |         tve = settings.get('ls_tve') | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |         if tve: | 
					
						
							|  |  |  |             query['manifest'] = 'm3u' | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |             mobj = re.search(r'<[^>]+id="pdk-player"[^>]+data-url=["\']?(?:https?:)?//player\.theplatform\.com/p/([^/]+)/(?:[^/]+/)*select/([^?#&"\']+)', webpage) | 
					
						
							|  |  |  |             if mobj: | 
					
						
							|  |  |  |                 account_pid, tp_path = mobj.groups() | 
					
						
							|  |  |  |                 release_pid = tp_path.strip('/').split('/')[-1] | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 account_pid = 'HNK2IC' | 
					
						
							|  |  |  |                 tp_path = release_pid = tve['release_pid'] | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |             if tve.get('entitlement') == 'auth': | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |                 adobe_pass = settings.get('tve_adobe_auth', {}) | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |                 resource = self._get_mvpd_resource( | 
					
						
							|  |  |  |                     adobe_pass.get('adobePassResourceId', 'bravo'), | 
					
						
							|  |  |  |                     tve['title'], release_pid, tve.get('rating')) | 
					
						
							|  |  |  |                 query['auth'] = self._extract_mvpd_auth( | 
					
						
							|  |  |  |                     url, release_pid, adobe_pass.get('adobePassRequestorId', 'bravo'), resource) | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |             shared_playlist = settings['ls_playlist'] | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |             account_pid = shared_playlist['account_pid'] | 
					
						
							|  |  |  |             metadata = shared_playlist['video_metadata'][shared_playlist['default_clip']] | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |             tp_path = release_pid = metadata.get('release_pid') | 
					
						
							|  |  |  |             if not release_pid: | 
					
						
							|  |  |  |                 release_pid = metadata['guid'] | 
					
						
							|  |  |  |                 tp_path = 'media/guid/2140479951/' + release_pid | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |             info.update({ | 
					
						
							|  |  |  |                 'title': metadata['title'], | 
					
						
							|  |  |  |                 'description': metadata.get('description'), | 
					
						
							|  |  |  |                 'season_number': int_or_none(metadata.get('season_num')), | 
					
						
							|  |  |  |                 'episode_number': int_or_none(metadata.get('episode_num')), | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             query['switch'] = 'progressive' | 
					
						
							|  |  |  |         info.update({ | 
					
						
							|  |  |  |             '_type': 'url_transparent', | 
					
						
							|  |  |  |             'id': release_pid, | 
					
						
							|  |  |  |             'url': smuggle_url(update_url_query( | 
					
						
							| 
									
										
										
										
											2019-04-16 19:06:18 +01:00
										 |  |  |                 'http://link.theplatform.com/s/%s/%s' % (account_pid, tp_path), | 
					
						
							| 
									
										
										
										
											2016-08-23 10:28:28 +01:00
										 |  |  |                 query), {'force_smil_url': True}), | 
					
						
							|  |  |  |             'ie_key': 'ThePlatform', | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |         return info |