2 from __future__
import unicode_literals
11 from .common
import InfoExtractor
12 from ..compat
import (
26 class HotStarBaseIE(InfoExtractor
):
27 _AKAMAI_ENCRYPTION_KEY
= b
'\x05\xfc\x1a\x01\xca\xc9\x4b\xc4\x12\xfc\x53\x12\x07\x75\xf9\xee'
29 def _call_api_impl(self
, path
, video_id
, query
, st
=None, cookies
=None):
30 st
= int_or_none(st
) or int(time
.time())
32 auth
= 'st=%d~exp=%d~acl=/*' % (st
, exp
)
33 auth
+= '~hmac=' + hmac
.new(self
._AKAMAI
_ENCRYPTION
_KEY
, auth
.encode(), hashlib
.sha256
).hexdigest()
35 if cookies
and cookies
.get('userUP'):
36 token
= cookies
.get('userUP').value
38 token
= self
._download
_json
(
39 'https://api.hotstar.com/um/v3/users',
40 video_id
, note
='Downloading token',
41 data
=json
.dumps({"device_ids": [{"id": compat_str(uuid.uuid4()), "type": "device_id"}
]}).encode('utf-8'),
44 'x-hs-platform': 'PCTV', # or 'web'
45 'Content-Type': 'application/json',
48 response
= self
._download
_json
(
49 'https://api.hotstar.com/' + path
, video_id
, headers
={
51 'x-hs-appversion': '6.72.2',
52 'x-hs-platform': 'web',
53 'x-hs-usertoken': token
,
56 if response
['message'] != "Playback URL's fetched successfully":
58 response
['message'], expected
=True)
59 return response
['data']
61 def _call_api(self
, path
, video_id
, query_name
='contentId'):
62 return self
._download
_json
('https://api.hotstar.com/' + path
, video_id
=video_id
, query
={
66 'x-country-code': 'IN',
67 'x-platform-code': 'PCTV',
70 def _call_api_v2(self
, path
, video_id
, st
=None, cookies
=None):
71 return self
._call
_api
_impl
(
72 '%s/content/%s' % (path
, video_id
), video_id
, st
=st
, cookies
=cookies
, query
={
73 'desired-config': 'audio_channel:stereo|container:fmp4|dynamic_range:hdr|encryption:plain|ladder:tv|package:dash|resolution:fhd|subs-tag:HotstarVIP|video_codec:h265',
74 'device-id': cookies
.get('device_id').value
if cookies
.get('device_id') else compat_str(uuid
.uuid4()),
80 class HotStarIE(HotStarBaseIE
):
85 https?://(?:www\.)?hotstar\.com(?:/in)?/(?!in/)
88 (?P<type>movies|sports|episode|(?P<tv>tv))
102 'url': 'https://www.hotstar.com/can-you-not-spread-rumours/1000076273',
106 'title': 'Can You Not Spread Rumours?',
107 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
108 'timestamp': 1447248600,
109 'upload_date': '20151111',
113 'url': 'hotstar:1000076273',
114 'only_matching': True,
116 'url': 'https://www.hotstar.com/movies/radha-gopalam/1000057157',
120 'title': 'Radha Gopalam',
121 'description': 'md5:be3bc342cc120bbc95b3b0960e2b0d22',
122 'timestamp': 1140805800,
123 'upload_date': '20060224',
127 'url': 'hotstar:movies:1000057157',
128 'only_matching': True,
130 'url': 'https://www.hotstar.com/in/sports/cricket/follow-the-blues-2021/recap-eng-fight-back-on-day-2/1260066104',
131 'only_matching': True,
133 'url': 'https://www.hotstar.com/in/sports/football/most-costly-pl-transfers-ft-grealish/1260065956',
134 'only_matching': True,
137 'url': 'hotstar:sports:1260065956',
138 'only_matching': True,
141 'url': 'hotstar:sports:1260066104',
142 'only_matching': True,
144 'url': 'https://www.hotstar.com/tv/ek-bhram-sarvagun-sampanna/s-2116/janhvi-targets-suman/1000234847',
148 'title': 'Janhvi Targets Suman',
149 'description': 'md5:78a85509348910bd1ca31be898c5796b',
150 'timestamp': 1556670600,
151 'upload_date': '20190501',
153 'channel': 'StarPlus',
155 'series': 'Ek Bhram - Sarvagun Sampanna',
156 'season': 'Chapter 1',
159 'episode': 'Janhvi Targets Suman',
163 'url': 'hotstar:episode:1000234847',
164 'only_matching': True,
170 'episode': 'episode',
175 def _real_extract(self
, url
):
176 mobj
= self
._match
_valid
_url
(url
)
177 video_id
= mobj
.group('id')
178 video_type
= mobj
.group('type')
179 cookies
= self
._get
_cookies
(url
)
180 video_type
= self
._TYPE
.get(video_type
, video_type
)
181 video_data
= self
._call
_api
(f
'o/v1/{video_type}/detail', video_id
)['body']['results']['item']
182 title
= video_data
['title']
184 if not self
.get_param('allow_unplayable_formats') and video_data
.get('drmProtected'):
185 self
.report_drm(video_id
)
187 headers
= {'Referer': 'https://www.hotstar.com/in'}
190 geo_restricted
= False
191 _
, urlh
= self
._download
_webpage
_handle
('https://www.hotstar.com/in', video_id
)
192 # Required to fix https://github.com/yt-dlp/yt-dlp/issues/396
193 st
= urlh
.headers
.get('x-origin-date')
194 # change to v2 in the future
195 playback_sets
= self
._call
_api
_v
2('play/v1/playback', video_id
, st
=st
, cookies
=cookies
)['playBackSets']
196 for playback_set
in playback_sets
:
197 if not isinstance(playback_set
, dict):
199 dr
= re
.search(r
'dynamic_range:(?P<dr>[a-z]+)', playback_set
.get('tagsCombination')).group('dr')
200 format_url
= url_or_none(playback_set
.get('playbackUrl'))
204 r
'(?<=//staragvod)(\d)', r
'web\1', format_url
)
205 tags
= str_or_none(playback_set
.get('tagsCombination')) or ''
206 ingored_res
, ignored_vcodec
, ignored_dr
= self
._configuration
_arg
('res'), self
._configuration
_arg
('vcodec'), self
._configuration
_arg
('dr')
207 if any(f
'resolution:{ig_res}' in tags
for ig_res
in ingored_res
) or any(f
'video_codec:{ig_vc}' in tags
for ig_vc
in ignored_vcodec
) or any(f
'dynamic_range:{ig_dr}' in tags
for ig_dr
in ignored_dr
):
209 ext
= determine_ext(format_url
)
210 current_formats
, current_subs
= [], {}
212 if 'package:hls' in tags
or ext
== 'm3u8':
213 current_formats
, current_subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
214 format_url
, video_id
, 'mp4',
215 entry_protocol
='m3u8_native',
216 m3u8_id
=f
'{dr}-hls', headers
=headers
)
217 elif 'package:dash' in tags
or ext
== 'mpd':
218 current_formats
, current_subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
219 format_url
, video_id
, mpd_id
=f
'{dr}-dash', headers
=headers
)
221 # produce broken files
226 'width': int_or_none(playback_set
.get('width')),
227 'height': int_or_none(playback_set
.get('height')),
229 except ExtractorError
as e
:
230 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
231 geo_restricted
= True
233 if tags
and 'encryption:plain' not in tags
:
234 for f
in current_formats
:
236 if tags
and 'language' in tags
:
237 lang
= re
.search(r
'language:(?P<lang>[a-z]+)', tags
).group('lang')
238 for f
in current_formats
:
239 if not f
.get('langauge'):
241 formats
.extend(current_formats
)
242 subs
= self
._merge
_subtitles
(subs
, current_subs
)
243 if not formats
and geo_restricted
:
244 self
.raise_geo_restricted(countries
=['IN'], metadata_available
=True)
245 self
._sort
_formats
(formats
)
248 f
.setdefault('http_headers', {}).update(headers
)
253 'description': video_data
.get('description'),
254 'duration': int_or_none(video_data
.get('duration')),
255 'timestamp': int_or_none(video_data
.get('broadcastDate') or video_data
.get('startDate')),
258 'channel': video_data
.get('channelName'),
259 'channel_id': video_data
.get('channelId'),
260 'series': video_data
.get('showName'),
261 'season': video_data
.get('seasonName'),
262 'season_number': int_or_none(video_data
.get('seasonNo')),
263 'season_id': video_data
.get('seasonId'),
265 'episode_number': int_or_none(video_data
.get('episodeNo')),
267 'Referer': 'https://www.hotstar.com/in',
272 class HotStarPlaylistIE(HotStarBaseIE
):
273 IE_NAME
= 'hotstar:playlist'
274 _VALID_URL
= r
'https?://(?:www\.)?hotstar\.com/tv/[^/]+/s-\w+/list/[^/]+/t-(?P<id>\w+)'
276 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/popular-clips/t-3_2_26',
280 'playlist_mincount': 20,
282 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/extras/t-2480',
283 'only_matching': True,
286 def _real_extract(self
, url
):
287 playlist_id
= self
._match
_id
(url
)
289 collection
= self
._call
_api
('o/v1/tray/find', playlist_id
, 'uqId')['body']['results']
292 'https://www.hotstar.com/%s' % video
['contentId'],
293 ie
=HotStarIE
.ie_key(), video_id
=video
['contentId'])
294 for video
in collection
['assets']['items']
295 if video
.get('contentId')]
297 return self
.playlist_result(entries
, playlist_id
)
300 class HotStarSeriesIE(HotStarBaseIE
):
301 IE_NAME
= 'hotstar:series'
302 _VALID_URL
= r
'(?P<url>https?://(?:www\.)?hotstar\.com(?:/in)?/tv/[^/]+/(?P<id>\d+))'
304 'url': 'https://www.hotstar.com/in/tv/radhakrishn/1260000646',
308 'playlist_mincount': 690,
310 'url': 'https://www.hotstar.com/tv/dancee-/1260050431',
314 'playlist_mincount': 43,
316 'url': 'https://www.hotstar.com/in/tv/mahabharat/435/',
320 'playlist_mincount': 269,
323 def _real_extract(self
, url
):
324 url
, series_id
= self
._match
_valid
_url
(url
).groups()
326 'x-country-code': 'IN',
327 'x-platform-code': 'PCTV',
329 detail_json
= self
._download
_json
('https://api.hotstar.com/o/v1/show/detail?contentId=' + series_id
,
330 video_id
=series_id
, headers
=headers
)
331 id = compat_str(try_get(detail_json
, lambda x
: x
['body']['results']['item']['id'], int))
332 item_json
= self
._download
_json
('https://api.hotstar.com/o/v1/tray/g/1/items?etid=0&tao=0&tas=10000&eid=' + id,
333 video_id
=series_id
, headers
=headers
)
336 '%s/ignoreme/%d' % (url
, video
['contentId']),
337 ie
=HotStarIE
.ie_key(), video_id
=video
['contentId'])
338 for video
in item_json
['body']['results']['items']
339 if video
.get('contentId')]
341 return self
.playlist_result(entries
, series_id
)