]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/bravotv.py
[extractor/youtube] Add `piped.video` (#5571)
[yt-dlp.git] / yt_dlp / extractor / bravotv.py
1 import re
2
3 from .adobepass import AdobePassIE
4 from ..utils import (
5 smuggle_url,
6 update_url_query,
7 int_or_none,
8 float_or_none,
9 try_get,
10 dict_get,
11 )
12
13
14 class BravoTVIE(AdobePassIE):
15 _VALID_URL = r'https?://(?:www\.)?(?P<req_id>bravotv|oxygen)\.com/(?:[^/]+/)+(?P<id>[^/?#]+)'
16 _TESTS = [{
17 'url': 'https://www.bravotv.com/top-chef/season-16/episode-15/videos/the-top-chef-season-16-winner-is',
18 'md5': 'e34684cfea2a96cd2ee1ef3a60909de9',
19 'info_dict': {
20 'id': 'epL0pmK1kQlT',
21 'ext': 'mp4',
22 'title': 'The Top Chef Season 16 Winner Is...',
23 'description': 'Find out who takes the title of Top Chef!',
24 'uploader': 'NBCU-BRAV',
25 'upload_date': '20190314',
26 'timestamp': 1552591860,
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,
32 }
33 }, {
34 'url': 'http://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1',
35 'only_matching': True,
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,
39 }]
40
41 def _real_extract(self, url):
42 site, display_id = self._match_valid_url(url).groups()
43 webpage = self._download_webpage(url, display_id)
44 settings = self._parse_json(self._search_regex(
45 r'<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>({.+?})</script>', webpage, 'drupal settings'),
46 display_id)
47 info = {}
48 query = {
49 'mbr': 'true',
50 }
51 account_pid, release_pid = [None] * 2
52 tve = settings.get('ls_tve')
53 if tve:
54 query['manifest'] = 'm3u'
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']
62 if tve.get('entitlement') == 'auth':
63 adobe_pass = settings.get('tve_adobe_auth', {})
64 if site == 'bravotv':
65 site = 'bravo'
66 resource = self._get_mvpd_resource(
67 adobe_pass.get('adobePassResourceId') or site,
68 tve['title'], release_pid, tve.get('rating'))
69 query['auth'] = self._extract_mvpd_auth(
70 url, release_pid,
71 adobe_pass.get('adobePassRequestorId') or site, resource)
72 else:
73 shared_playlist = settings['ls_playlist']
74 account_pid = shared_playlist['account_pid']
75 metadata = shared_playlist['video_metadata'][shared_playlist['default_clip']]
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
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'
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
111 info.update({
112 '_type': 'url_transparent',
113 'id': release_pid,
114 'url': smuggle_url(update_url_query(tp_url, query), {'force_smil_url': True}),
115 'ie_key': 'ThePlatform',
116 })
117 return info