]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/paramountplus.py
338b84d5b8c9cb8732d4512ddf1457b37d2fb429
[yt-dlp.git] / yt_dlp / extractor / paramountplus.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from .cbs import CBSBaseIE
5 from ..utils import (
6 int_or_none,
7 url_or_none,
8 )
9
10
11 class ParamountPlusIE(CBSBaseIE):
12 _VALID_URL = r'''(?x)
13 (?:
14 paramountplus:|
15 https?://(?:www\.)?(?:
16 paramountplus\.com/(?:shows/[^/]+/video|movies/[^/]+)/
17 )(?P<id>[\w-]+))'''
18
19 # All tests are blocked outside US
20 _TESTS = [{
21 'url': 'https://www.paramountplus.com/shows/catdog/video/Oe44g5_NrlgiZE3aQVONleD6vXc8kP0k/catdog-climb-every-catdog-the-canine-mutiny/',
22 'info_dict': {
23 'id': 'Oe44g5_NrlgiZE3aQVONleD6vXc8kP0k',
24 'ext': 'mp4',
25 'title': 'CatDog - Climb Every CatDog/The Canine Mutiny',
26 'description': 'md5:7ac835000645a69933df226940e3c859',
27 'duration': 1418,
28 'timestamp': 920264400,
29 'upload_date': '19990301',
30 'uploader': 'CBSI-NEW',
31 },
32 'params': {
33 'skip_download': 'm3u8',
34 },
35 }, {
36 'url': 'https://www.paramountplus.com/shows/tooning-out-the-news/video/6hSWYWRrR9EUTz7IEe5fJKBhYvSUfexd/7-23-21-week-in-review-rep-jahana-hayes-howard-fineman-sen-michael-bennet-sheera-frenkel-cecilia-kang-/',
37 'info_dict': {
38 'id': '6hSWYWRrR9EUTz7IEe5fJKBhYvSUfexd',
39 'ext': 'mp4',
40 'title': '7/23/21 WEEK IN REVIEW (Rep. Jahana Hayes/Howard Fineman/Sen. Michael Bennet/Sheera Frenkel & Cecilia Kang)',
41 'description': 'md5:f4adcea3e8b106192022e121f1565bae',
42 'duration': 2506,
43 'timestamp': 1627063200,
44 'upload_date': '20210723',
45 'uploader': 'CBSI-NEW',
46 },
47 'params': {
48 'skip_download': 'm3u8',
49 },
50 }, {
51 'url': 'https://www.paramountplus.com/movies/daddys-home/vM2vm0kE6vsS2U41VhMRKTOVHyQAr6pC',
52 'info_dict': {
53 'id': 'vM2vm0kE6vsS2U41VhMRKTOVHyQAr6pC',
54 'ext': 'mp4',
55 'title': 'Daddy\'s Home',
56 'upload_date': '20151225',
57 'description': 'md5:a0beaf24e8d3b0e81b2ee41d47c06f33',
58 'uploader': 'CBSI-NEW',
59 'timestamp': 1451030400,
60 },
61 'params': {
62 'skip_download': 'm3u8',
63 'format': 'bestvideo',
64 },
65 'expected_warnings': ['Ignoring subtitle tracks'], # TODO: Investigate this
66 }, {
67 'url': 'https://www.paramountplus.com/movies/sonic-the-hedgehog/5EKDXPOzdVf9voUqW6oRuocyAEeJGbEc',
68 'info_dict': {
69 'id': '5EKDXPOzdVf9voUqW6oRuocyAEeJGbEc',
70 'ext': 'mp4',
71 'uploader': 'CBSI-NEW',
72 'description': 'md5:bc7b6fea84ba631ef77a9bda9f2ff911',
73 'timestamp': 1577865600,
74 'title': 'Sonic the Hedgehog',
75 'upload_date': '20200101',
76 },
77 'params': {
78 'skip_download': 'm3u8',
79 'format': 'bestvideo',
80 },
81 'expected_warnings': ['Ignoring subtitle tracks'],
82 }, {
83 'url': 'https://www.paramountplus.com/shows/all-rise/video/QmR1WhNkh1a_IrdHZrbcRklm176X_rVc/all-rise-space/',
84 'only_matching': True,
85 }, {
86 'url': 'https://www.paramountplus.com/movies/million-dollar-american-princesses-meghan-and-harry/C0LpgNwXYeB8txxycdWdR9TjxpJOsdCq',
87 'only_matching': True,
88 }]
89
90 def _extract_video_info(self, content_id, mpx_acc=2198311517):
91 items_data = self._download_json(
92 'https://www.paramountplus.com/apps-api/v2.0/androidtv/video/cid/%s.json' % content_id,
93 content_id, query={'locale': 'en-us', 'at': 'ABCqWNNSwhIqINWIIAG+DFzcFUvF8/vcN6cNyXFFfNzWAIvXuoVgX+fK4naOC7V8MLI='}, headers=self.geo_verification_headers())
94
95 asset_types = {
96 item.get('assetType'): {
97 'format': 'SMIL',
98 'formats': 'MPEG4,M3U',
99 } for item in items_data['itemList']
100 }
101 item = items_data['itemList'][-1]
102 return self._extract_common_video_info(content_id, asset_types, mpx_acc, extra_info={
103 'title': item.get('title'),
104 'series': item.get('seriesTitle'),
105 'season_number': int_or_none(item.get('seasonNum')),
106 'episode_number': int_or_none(item.get('episodeNum')),
107 'duration': int_or_none(item.get('duration')),
108 'thumbnail': url_or_none(item.get('thumbnail')),
109 })
110
111
112 class ParamountPlusSeriesIE(InfoExtractor):
113 _VALID_URL = r'https?://(?:www\.)?paramountplus\.com/shows/(?P<id>[a-zA-Z0-9-_]+)/?(?:[#?]|$)'
114 _TESTS = [{
115 'url': 'https://www.paramountplus.com/shows/drake-josh',
116 'playlist_mincount': 50,
117 'info_dict': {
118 'id': 'drake-josh',
119 }
120 }, {
121 'url': 'https://www.paramountplus.com/shows/hawaii_five_0/',
122 'playlist_mincount': 240,
123 'info_dict': {
124 'id': 'hawaii_five_0',
125 }
126 }, {
127 'url': 'https://www.paramountplus.com/shows/spongebob-squarepants/',
128 'playlist_mincount': 248,
129 'info_dict': {
130 'id': 'spongebob-squarepants',
131 }
132 }]
133 _API_URL = 'https://www.paramountplus.com/shows/{}/xhr/episodes/page/0/size/100000/xs/0/season/0/'
134
135 def _entries(self, show_name):
136 show_json = self._download_json(self._API_URL.format(show_name), video_id=show_name)
137 if show_json.get('success'):
138 for episode in show_json['result']['data']:
139 yield self.url_result(
140 'https://www.paramountplus.com%s' % episode['url'],
141 ie=ParamountPlusIE.ie_key(), video_id=episode['content_id'])
142
143 def _real_extract(self, url):
144 show_name = self._match_id(url)
145 return self.playlist_result(self._entries(show_name), playlist_id=show_name)