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