8 from .common
import InfoExtractor
9 from ..compat
import compat_HTTPError
, compat_str
21 class HotStarBaseIE(InfoExtractor
):
22 _BASE_URL
= 'https://www.hotstar.com'
23 _API_URL
= 'https://api.hotstar.com'
24 _AKAMAI_ENCRYPTION_KEY
= b
'\x05\xfc\x1a\x01\xca\xc9\x4b\xc4\x12\xfc\x53\x12\x07\x75\xf9\xee'
26 def _call_api_v1(self
, path
, *args
, **kwargs
):
27 return self
._download
_json
(
28 f
'{self._API_URL}/o/v1/{path}', *args
, **kwargs
,
29 headers
={'x-country-code': 'IN', 'x-platform-code': 'PCTV'}
)
31 def _call_api_impl(self
, path
, video_id
, query
, st
=None, cookies
=None):
32 st
= int_or_none(st
) or int(time
.time())
34 auth
= 'st=%d~exp=%d~acl=/*' % (st
, exp
)
35 auth
+= '~hmac=' + hmac
.new(self
._AKAMAI
_ENCRYPTION
_KEY
, auth
.encode(), hashlib
.sha256
).hexdigest()
37 if cookies
and cookies
.get('userUP'):
38 token
= cookies
.get('userUP').value
40 token
= self
._download
_json
(
41 f
'{self._API_URL}/um/v3/users',
42 video_id
, note
='Downloading token',
43 data
=json
.dumps({"device_ids": [{"id": compat_str(uuid.uuid4()), "type": "device_id"}
]}).encode('utf-8'),
46 'x-hs-platform': 'PCTV', # or 'web'
47 'Content-Type': 'application/json',
50 response
= self
._download
_json
(
51 f
'{self._API_URL}/{path}', video_id
, query
=query
,
54 'x-hs-appversion': '6.72.2',
55 'x-hs-platform': 'web',
56 'x-hs-usertoken': token
,
59 if response
['message'] != "Playback URL's fetched successfully":
61 response
['message'], expected
=True)
62 return response
['data']
64 def _call_api_v2(self
, path
, video_id
, st
=None, cookies
=None):
65 return self
._call
_api
_impl
(
66 f
'{path}/content/{video_id}', video_id
, st
=st
, cookies
=cookies
, query
={
67 'desired-config': 'audio_channel:stereo|container:fmp4|dynamic_range:hdr|encryption:plain|ladder:tv|package:dash|resolution:fhd|subs-tag:HotstarVIP|video_codec:h265',
68 'device-id': cookies
.get('device_id').value
if cookies
.get('device_id') else compat_str(uuid
.uuid4()),
73 def _playlist_entries(self
, path
, item_id
, root
=None, **kwargs
):
74 results
= self
._call
_api
_v
1(path
, item_id
, **kwargs
)['body']['results']
75 for video
in traverse_obj(results
, (('assets', None), 'items', ...)):
76 if video
.get('contentId'):
77 yield self
.url_result(
78 HotStarIE
._video
_url
(video
['contentId'], root
=root
), HotStarIE
, video
['contentId'])
81 class HotStarIE(HotStarBaseIE
):
84 https?://(?:www\.)?hotstar\.com(?:/in)?/(?!in/)
86 (?P<type>movies|sports|episode|(?P<tv>tv))/
87 (?(tv)(?:[^/?#]+/){2}|[^?#]*)
94 'url': 'https://www.hotstar.com/can-you-not-spread-rumours/1000076273',
98 'title': 'Can You Not Spread Rumours?',
99 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
100 'timestamp': 1447248600,
101 'upload_date': '20151111',
103 'episode': 'Can You Not Spread Rumours?',
105 'params': {'skip_download': 'm3u8'}
,
107 'url': 'https://www.hotstar.com/tv/ek-bhram-sarvagun-sampanna/s-2116/janhvi-targets-suman/1000234847',
111 'title': 'Janhvi Targets Suman',
112 'description': 'md5:78a85509348910bd1ca31be898c5796b',
113 'timestamp': 1556670600,
114 'upload_date': '20190501',
116 'channel': 'StarPlus',
118 'series': 'Ek Bhram - Sarvagun Sampanna',
119 'season': 'Chapter 1',
122 'episode': 'Janhvi Targets Suman',
126 'url': 'https://www.hotstar.com/movies/radha-gopalam/1000057157',
127 'only_matching': True,
129 'url': 'https://www.hotstar.com/in/sports/cricket/follow-the-blues-2021/recap-eng-fight-back-on-day-2/1260066104',
130 'only_matching': True,
132 'url': 'https://www.hotstar.com/in/sports/football/most-costly-pl-transfers-ft-grealish/1260065956',
133 'only_matching': True,
140 'episode': 'episode',
147 'vcodec': 'video_codec',
148 'dr': 'dynamic_range',
152 'language': 'language',
153 'acodec': 'audio_codec',
154 'vcodec': 'video_codec',
158 def _video_url(cls
, video_id
, video_type
=None, *, slug
='ignore_me', root
=None):
159 assert None in (video_type
, root
)
161 root
= join_nonempty(cls
._BASE
_URL
, video_type
, delim
='/')
162 return f
'{root}/{slug}/{video_id}'
164 def _real_extract(self
, url
):
165 video_id
, video_type
= self
._match
_valid
_url
(url
).group('id', 'type')
166 video_type
= self
._TYPE
.get(video_type
, video_type
)
167 cookies
= self
._get
_cookies
(url
) # Cookies before any request
169 video_data
= self
._call
_api
_v
1(f
'{video_type}/detail', video_id
,
170 query
={'tas': 10000, 'contentId': video_id}
)['body']['results']['item']
171 if not self
.get_param('allow_unplayable_formats') and video_data
.get('drmProtected'):
172 self
.report_drm(video_id
)
174 # See https://github.com/yt-dlp/yt-dlp/issues/396
175 st
= self
._download
_webpage
_handle
(f
'{self._BASE_URL}/in', video_id
)[1].headers
.get('x-origin-date')
177 geo_restricted
= False
178 formats
, subs
= [], {}
179 headers
= {'Referer': f'{self._BASE_URL}
/in'}
181 # change to v2 in the future
182 playback_sets = self._call_api_v2('play
/v1
/playback
', video_id, st=st, cookies=cookies)['playBackSets
']
183 for playback_set in playback_sets:
184 if not isinstance(playback_set, dict):
186 tags = str_or_none(playback_set.get('tagsCombination
')) or ''
187 if any(f'{prefix}
:{ignore}
' in tags
188 for key, prefix in self._IGNORE_MAP.items()
189 for ignore in self._configuration_arg(key)):
191 tag_dict = dict((t.split(':', 1) + [None])[:2] for t in tags.split(';'))
193 format_url = url_or_none(playback_set.get('playbackUrl
'))
196 format_url = re.sub(r'(?
<=//staragvod
)(\d
)', r'web\
1', format_url)
197 ext = determine_ext(format_url)
199 current_formats, current_subs = [], {}
201 if 'package
:hls
' in tags or ext == 'm3u8
':
202 current_formats, current_subs = self._extract_m3u8_formats_and_subtitles(
203 format_url, video_id, ext='mp4
', headers=headers)
204 elif 'package
:dash
' in tags or ext == 'mpd
':
205 current_formats, current_subs = self._extract_mpd_formats_and_subtitles(
206 format_url, video_id, headers=headers)
208 pass # XXX: produce broken files
212 'width
': int_or_none(playback_set.get('width
')),
213 'height
': int_or_none(playback_set.get('height
')),
215 except ExtractorError as e:
216 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
217 geo_restricted = True
220 if tag_dict.get('encryption
') not in ('plain
', None):
221 for f in current_formats:
223 for f in current_formats:
224 for k, v in self._TAG_FIELDS.items():
226 f[k] = tag_dict.get(v)
227 if f.get('vcodec
') != 'none
' and not f.get('dynamic_range
'):
228 f['dynamic_range
'] = tag_dict.get('dynamic_range
')
229 if f.get('acodec
') != 'none
' and not f.get('audio_channels
'):
230 f['audio_channels
'] = {
233 }.get(tag_dict.get('audio_channel
'))
234 f['format_note
'] = join_nonempty(
235 tag_dict.get('ladder
'),
236 tag_dict.get('audio_channel
') if f.get('acodec
') != 'none
' else None,
237 f.get('format_note
'),
240 formats.extend(current_formats)
241 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._remove_duplicate_formats(formats)
247 f.setdefault('http_headers
', {}).update(headers)
251 'title
': video_data.get('title
'),
252 'description
': video_data.get('description
'),
253 'duration
': int_or_none(video_data.get('duration
')),
254 'timestamp
': int_or_none(traverse_obj(video_data, 'broadcastDate
', 'startDate
')),
257 'channel
': video_data.get('channelName
'),
258 'channel_id
': video_data.get('channelId
'),
259 'series
': video_data.get('showName
'),
260 'season
': video_data.get('seasonName
'),
261 'season_number
': int_or_none(video_data.get('seasonNo
')),
262 'season_id
': video_data.get('seasonId
'),
263 'episode
': video_data.get('title
'),
264 'episode_number
': int_or_none(video_data.get('episodeNo
')),
268 class HotStarPrefixIE(InfoExtractor):
269 """ The "hotstar:" prefix is no longer in use, but this is kept for backward compatibility """
271 _VALID_URL = r'hotstar
:(?
:(?P
<type>\w
+):)?
(?P
<id>\d
+)$
'
273 'url
': 'hotstar
:1000076273',
274 'only_matching
': True,
276 'url
': 'hotstar
:movies
:1260009879',
280 'title
': 'Nuvvu Naaku Nachav
',
281 'description
': 'md5
:d43701b1314e6f8233ce33523c043b7d
',
282 'timestamp
': 1567525674,
283 'upload_date
': '20190903',
285 'episode
': 'Nuvvu Naaku Nachav
',
288 'url
': 'hotstar
:episode
:1000234847',
289 'only_matching
': True,
292 'url
': 'hotstar
:sports
:1260065956',
293 'only_matching
': True,
296 'url
': 'hotstar
:sports
:1260066104',
297 'only_matching
': True,
300 def _real_extract(self, url):
301 video_id, video_type = self._match_valid_url(url).group('id', 'type')
302 return self.url_result(HotStarIE._video_url(video_id, video_type), HotStarIE, video_id)
305 class HotStarPlaylistIE(HotStarBaseIE):
306 IE_NAME = 'hotstar
:playlist
'
307 _VALID_URL = r'https?
://(?
:www\
.)?hotstar\
.com(?
:/in)?
/tv(?
:/[^
/]+){2}
/list/[^
/]+/t
-(?P
<id>\w
+)'
309 'url
': 'https
://www
.hotstar
.com
/tv
/savdhaan
-india
/s
-26/list/popular
-clips
/t
-3_2_26',
313 'playlist_mincount
': 20,
315 'url
': 'https
://www
.hotstar
.com
/tv
/savdhaan
-india
/s
-26/list/extras
/t
-2480',
316 'only_matching
': True,
318 'url
': 'https
://www
.hotstar
.com
/in/tv
/karthika
-deepam
/15457/list/popular
-clips
/t
-3_2_1272',
319 'only_matching
': True,
322 def _real_extract(self, url):
323 id_ = self._match_id(url)
324 return self.playlist_result(
325 self._playlist_entries('tray
/find
', id_, query={'tas': 10000, 'uqId': id_}), id_)
328 class HotStarSeasonIE(HotStarBaseIE):
329 IE_NAME = 'hotstar
:season
'
330 _VALID_URL = r'(?P
<url
>https?
://(?
:www\
.)?hotstar\
.com(?
:/in)?
/tv
/[^
/]+/\w
+)/seasons
/[^
/]+/ss
-(?P
<id>\w
+)'
332 'url
': 'https
://www
.hotstar
.com
/tv
/radhakrishn
/1260000646/seasons
/season
-2/ss
-8028',
336 'playlist_mincount
': 35,
338 'url
': 'https
://www
.hotstar
.com
/in/tv
/ishqbaaz
/9567/seasons
/season
-2/ss
-4357',
342 'playlist_mincount
': 30,
344 'url
': 'https
://www
.hotstar
.com
/in/tv
/bigg
-boss
/14714/seasons
/season
-4/ss
-8208/',
348 'playlist_mincount
': 19,
351 def _real_extract(self, url):
352 url, season_id = self._match_valid_url(url).groups()
353 return self.playlist_result(self._playlist_entries(
354 'season
/asset
', season_id, url, query={'tao': 0, 'tas': 0, 'size': 10000, 'id': season_id}), season_id)
357 class HotStarSeriesIE(HotStarBaseIE):
358 IE_NAME = 'hotstar
:series
'
359 _VALID_URL = r'(?P
<url
>https?
://(?
:www\
.)?hotstar\
.com(?
:/in)?
/tv
/[^
/]+/(?P
<id>\d
+))/?
(?
:[#?]|$)'
361 'url': 'https://www.hotstar.com/in/tv/radhakrishn/1260000646',
365 'playlist_mincount': 690,
367 'url': 'https://www.hotstar.com/tv/dancee-/1260050431',
371 'playlist_mincount': 43,
373 'url': 'https://www.hotstar.com/in/tv/mahabharat/435/',
377 'playlist_mincount': 267,
380 def _real_extract(self
, url
):
381 url
, series_id
= self
._match
_valid
_url
(url
).groups()
382 id_
= self
._call
_api
_v
1(
383 'show/detail', series_id
, query
={'contentId': series_id}
)['body']['results']['item']['id']
385 return self
.playlist_result(self
._playlist
_entries
(
386 'tray/g/1/items', series_id
, url
, query
={'tao': 0, 'tas': 10000, 'etid': 0, 'eid': id_}
), series_id
)