]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bravotv.py
Update upstream source from tag 'upstream/2020.05.08'
[youtubedl] / youtube_dl / extractor / bravotv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .adobepass import AdobePassIE
7 from ..utils import (
8 smuggle_url,
9 update_url_query,
10 int_or_none,
11 )
12
13
14 class BravoTVIE(AdobePassIE):
15 _VALID_URL = r'https?://(?:www\.)?bravotv\.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 }
28 }, {
29 'url': 'http://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1',
30 'only_matching': True,
31 }]
32
33 def _real_extract(self, url):
34 display_id = self._match_id(url)
35 webpage = self._download_webpage(url, display_id)
36 settings = self._parse_json(self._search_regex(
37 r'<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>({.+?})</script>', webpage, 'drupal settings'),
38 display_id)
39 info = {}
40 query = {
41 'mbr': 'true',
42 }
43 account_pid, release_pid = [None] * 2
44 tve = settings.get('ls_tve')
45 if tve:
46 query['manifest'] = 'm3u'
47 mobj = re.search(r'<[^>]+id="pdk-player"[^>]+data-url=["\']?(?:https?:)?//player\.theplatform\.com/p/([^/]+)/(?:[^/]+/)*select/([^?#&"\']+)', webpage)
48 if mobj:
49 account_pid, tp_path = mobj.groups()
50 release_pid = tp_path.strip('/').split('/')[-1]
51 else:
52 account_pid = 'HNK2IC'
53 tp_path = release_pid = tve['release_pid']
54 if tve.get('entitlement') == 'auth':
55 adobe_pass = settings.get('tve_adobe_auth', {})
56 resource = self._get_mvpd_resource(
57 adobe_pass.get('adobePassResourceId', 'bravo'),
58 tve['title'], release_pid, tve.get('rating'))
59 query['auth'] = self._extract_mvpd_auth(
60 url, release_pid, adobe_pass.get('adobePassRequestorId', 'bravo'), resource)
61 else:
62 shared_playlist = settings['ls_playlist']
63 account_pid = shared_playlist['account_pid']
64 metadata = shared_playlist['video_metadata'][shared_playlist['default_clip']]
65 tp_path = release_pid = metadata.get('release_pid')
66 if not release_pid:
67 release_pid = metadata['guid']
68 tp_path = 'media/guid/2140479951/' + release_pid
69 info.update({
70 'title': metadata['title'],
71 'description': metadata.get('description'),
72 'season_number': int_or_none(metadata.get('season_num')),
73 'episode_number': int_or_none(metadata.get('episode_num')),
74 })
75 query['switch'] = 'progressive'
76 info.update({
77 '_type': 'url_transparent',
78 'id': release_pid,
79 'url': smuggle_url(update_url_query(
80 'http://link.theplatform.com/s/%s/%s' % (account_pid, tp_path),
81 query), {'force_smil_url': True}),
82 'ie_key': 'ThePlatform',
83 })
84 return info