]>
Commit | Line | Data |
---|---|---|
63f41d38 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
81d989c2 RA |
4 | import re |
5 | ||
fb009b7f RA |
6 | from .adobepass import AdobePassIE |
7 | from ..utils import ( | |
8 | smuggle_url, | |
9 | update_url_query, | |
10 | int_or_none, | |
c5370857 KC |
11 | float_or_none, |
12 | try_get, | |
13 | dict_get, | |
fb009b7f | 14 | ) |
63f41d38 | 15 | |
16 | ||
fb009b7f | 17 | class BravoTVIE(AdobePassIE): |
2181983a | 18 | _VALID_URL = r'https?://(?:www\.)?(?P<req_id>bravotv|oxygen)\.com/(?:[^/]+/)+(?P<id>[^/?#]+)' |
fb009b7f | 19 | _TESTS = [{ |
81d989c2 RA |
20 | 'url': 'https://www.bravotv.com/top-chef/season-16/episode-15/videos/the-top-chef-season-16-winner-is', |
21 | 'md5': 'e34684cfea2a96cd2ee1ef3a60909de9', | |
63f41d38 | 22 | 'info_dict': { |
81d989c2 | 23 | 'id': 'epL0pmK1kQlT', |
63f41d38 | 24 | 'ext': 'mp4', |
81d989c2 RA |
25 | 'title': 'The Top Chef Season 16 Winner Is...', |
26 | 'description': 'Find out who takes the title of Top Chef!', | |
79ba9140 | 27 | 'uploader': 'NBCU-BRAV', |
81d989c2 RA |
28 | 'upload_date': '20190314', |
29 | 'timestamp': 1552591860, | |
c5370857 KC |
30 | 'season_number': 16, |
31 | 'episode_number': 15, | |
32 | 'series': 'Top Chef', | |
33 | 'episode': 'The Top Chef Season 16 Winner Is...', | |
34 | 'duration': 190.0, | |
63f41d38 | 35 | } |
fb009b7f RA |
36 | }, { |
37 | 'url': 'http://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1', | |
38 | 'only_matching': True, | |
2181983a | 39 | }, { |
40 | 'url': 'https://www.oxygen.com/in-ice-cold-blood/season-2/episode-16/videos/handling-the-horwitz-house-after-the-murder-season-2', | |
41 | 'only_matching': True, | |
fb009b7f | 42 | }] |
63f41d38 | 43 | |
44 | def _real_extract(self, url): | |
5ad28e7f | 45 | site, display_id = self._match_valid_url(url).groups() |
fb009b7f RA |
46 | webpage = self._download_webpage(url, display_id) |
47 | settings = self._parse_json(self._search_regex( | |
81d989c2 | 48 | r'<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>({.+?})</script>', webpage, 'drupal settings'), |
fb009b7f RA |
49 | display_id) |
50 | info = {} | |
51 | query = { | |
52 | 'mbr': 'true', | |
53 | } | |
54 | account_pid, release_pid = [None] * 2 | |
81d989c2 | 55 | tve = settings.get('ls_tve') |
fb009b7f RA |
56 | if tve: |
57 | query['manifest'] = 'm3u' | |
81d989c2 RA |
58 | mobj = re.search(r'<[^>]+id="pdk-player"[^>]+data-url=["\']?(?:https?:)?//player\.theplatform\.com/p/([^/]+)/(?:[^/]+/)*select/([^?#&"\']+)', webpage) |
59 | if mobj: | |
60 | account_pid, tp_path = mobj.groups() | |
61 | release_pid = tp_path.strip('/').split('/')[-1] | |
62 | else: | |
63 | account_pid = 'HNK2IC' | |
64 | tp_path = release_pid = tve['release_pid'] | |
fb009b7f | 65 | if tve.get('entitlement') == 'auth': |
81d989c2 | 66 | adobe_pass = settings.get('tve_adobe_auth', {}) |
2181983a | 67 | if site == 'bravotv': |
68 | site = 'bravo' | |
fb009b7f | 69 | resource = self._get_mvpd_resource( |
2181983a | 70 | adobe_pass.get('adobePassResourceId') or site, |
fb009b7f RA |
71 | tve['title'], release_pid, tve.get('rating')) |
72 | query['auth'] = self._extract_mvpd_auth( | |
2181983a | 73 | url, release_pid, |
74 | adobe_pass.get('adobePassRequestorId') or site, resource) | |
fb009b7f | 75 | else: |
81d989c2 | 76 | shared_playlist = settings['ls_playlist'] |
fb009b7f RA |
77 | account_pid = shared_playlist['account_pid'] |
78 | metadata = shared_playlist['video_metadata'][shared_playlist['default_clip']] | |
81d989c2 RA |
79 | tp_path = release_pid = metadata.get('release_pid') |
80 | if not release_pid: | |
81 | release_pid = metadata['guid'] | |
82 | tp_path = 'media/guid/2140479951/' + release_pid | |
fb009b7f RA |
83 | info.update({ |
84 | 'title': metadata['title'], | |
85 | 'description': metadata.get('description'), | |
86 | 'season_number': int_or_none(metadata.get('season_num')), | |
87 | 'episode_number': int_or_none(metadata.get('episode_num')), | |
88 | }) | |
89 | query['switch'] = 'progressive' | |
c5370857 KC |
90 | |
91 | tp_url = 'http://link.theplatform.com/s/%s/%s' % (account_pid, tp_path) | |
92 | ||
93 | tp_metadata = self._download_json( | |
94 | update_url_query(tp_url, {'format': 'preview'}), | |
95 | display_id, fatal=False) | |
96 | if tp_metadata: | |
97 | info.update({ | |
98 | 'title': tp_metadata.get('title'), | |
99 | 'description': tp_metadata.get('description'), | |
100 | 'duration': float_or_none(tp_metadata.get('duration'), 1000), | |
101 | 'season_number': int_or_none( | |
102 | dict_get(tp_metadata, ('pl1$seasonNumber', 'nbcu$seasonNumber'))), | |
103 | 'episode_number': int_or_none( | |
104 | dict_get(tp_metadata, ('pl1$episodeNumber', 'nbcu$episodeNumber'))), | |
105 | # For some reason the series is sometimes wrapped into a single element array. | |
106 | 'series': try_get( | |
107 | dict_get(tp_metadata, ('pl1$show', 'nbcu$show')), | |
108 | lambda x: x[0] if isinstance(x, list) else x, | |
109 | expected_type=str), | |
110 | 'episode': dict_get( | |
111 | tp_metadata, ('pl1$episodeName', 'nbcu$episodeName', 'title')), | |
112 | }) | |
113 | ||
fb009b7f RA |
114 | info.update({ |
115 | '_type': 'url_transparent', | |
116 | 'id': release_pid, | |
c5370857 | 117 | 'url': smuggle_url(update_url_query(tp_url, query), {'force_smil_url': True}), |
fb009b7f RA |
118 | 'ie_key': 'ThePlatform', |
119 | }) | |
120 | return info |