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
.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
._call
_api
_impl
(path
, video_id
, {
67 def _call_api_v2(self
, path
, video_id
, st
=None, cookies
=None):
68 return self
._call
_api
_impl
(
69 '%s/content/%s' % (path
, video_id
), video_id
, st
=st
, cookies
=cookies
, query
={
70 'desired-config': 'audio_channel:stereo|dynamic_range:sdr|encryption:plain|ladder:tv|package:dash|resolution:hd|subs-tag:HotstarVIP|video_codec:vp9',
71 'device-id': cookies
.get('device_id').value
if cookies
.get('device_id') else compat_str(uuid
.uuid4()),
77 class HotStarIE(HotStarBaseIE
):
80 https?://(?:www\.)?hotstar\.com(?:/in)?/(?!in/)
89 'url': 'https://www.hotstar.com/can-you-not-spread-rumours/1000076273',
93 'title': 'Can You Not Spread Rumours?',
94 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
95 'timestamp': 1447248600,
96 'upload_date': '20151111',
101 'skip_download': True,
105 'url': 'https://www.hotstar.com/movies/radha-gopalam/1000057157',
106 'only_matching': True,
108 'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583',
109 'only_matching': True,
111 'url': 'http://www.hotstar.com/1000000515',
112 'only_matching': True,
114 # only available via api v2
115 'url': 'https://www.hotstar.com/tv/ek-bhram-sarvagun-sampanna/s-2116/janhvi-targets-suman/1000234847',
116 'only_matching': True,
120 def _real_extract(self
, url
):
121 video_id
= self
._match
_id
(url
)
122 cookies
= self
._get
_cookies
(url
)
123 webpage
, urlh
= self
._download
_webpage
_handle
(url
, video_id
)
124 st
= urlh
.headers
.get('x-origin-date')
125 app_state
= self
._parse
_json
(self
._search
_regex
(
126 r
'<script>window\.APP_STATE\s*=\s*({.+?})</script>',
127 webpage
, 'app state'), video_id
)
130 lambda x
, k
=k
: x
['initialState']['content%s' % k
]['content']
131 for k
in ('Data', 'Detail')
133 for v
in app_state
.values():
134 content
= try_get(v
, getters
, dict)
135 if content
and content
.get('contentId') == video_id
:
139 title
= video_data
['title']
141 if not self
.get_param('allow_unplayable_formats') and video_data
.get('drmProtected'):
142 raise ExtractorError('This video is DRM protected.', expected
=True)
144 headers
= {'Referer': url}
146 geo_restricted
= False
147 # change to v2 in the future
148 playback_sets
= self
._call
_api
_v
2('play/v1/playback', video_id
, st
=st
, cookies
=cookies
)['playBackSets']
149 for playback_set
in playback_sets
:
150 if not isinstance(playback_set
, dict):
152 format_url
= url_or_none(playback_set
.get('playbackUrl'))
156 r
'(?<=//staragvod)(\d)', r
'web\1', format_url
)
157 tags
= str_or_none(playback_set
.get('tagsCombination')) or ''
158 if tags
and 'encryption:plain' not in tags
:
160 ext
= determine_ext(format_url
)
162 if 'package:hls' in tags
or ext
== 'm3u8':
163 formats
.extend(self
._extract
_m
3u8_formats
(
164 format_url
, video_id
, 'mp4',
165 entry_protocol
='m3u8_native',
166 m3u8_id
='hls', headers
=headers
))
167 elif 'package:dash' in tags
or ext
== 'mpd':
168 formats
.extend(self
._extract
_mpd
_formats
(
169 format_url
, video_id
, mpd_id
='dash', headers
=headers
))
171 # produce broken files
176 'width': int_or_none(playback_set
.get('width')),
177 'height': int_or_none(playback_set
.get('height')),
179 except ExtractorError
as e
:
180 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
181 geo_restricted
= True
183 if not formats
and geo_restricted
:
184 self
.raise_geo_restricted(countries
=['IN'], metadata_available
=True)
185 self
._sort
_formats
(formats
)
188 f
.setdefault('http_headers', {}).update(headers
)
193 'description': video_data
.get('description'),
194 'duration': int_or_none(video_data
.get('duration')),
195 'timestamp': int_or_none(video_data
.get('broadcastDate') or video_data
.get('startDate')),
197 'channel': video_data
.get('channelName'),
198 'channel_id': video_data
.get('channelId'),
199 'series': video_data
.get('showName'),
200 'season': video_data
.get('seasonName'),
201 'season_number': int_or_none(video_data
.get('seasonNo')),
202 'season_id': video_data
.get('seasonId'),
204 'episode_number': int_or_none(video_data
.get('episodeNo')),
208 class HotStarPlaylistIE(HotStarBaseIE
):
209 IE_NAME
= 'hotstar:playlist'
210 _VALID_URL
= r
'https?://(?:www\.)?hotstar\.com/tv/[^/]+/s-\w+/list/[^/]+/t-(?P<id>\w+)'
212 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/popular-clips/t-3_2_26',
216 'playlist_mincount': 20,
218 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/extras/t-2480',
219 'only_matching': True,
222 def _real_extract(self
, url
):
223 playlist_id
= self
._match
_id
(url
)
225 collection
= self
._call
_api
('o/v1/tray/find', playlist_id
, 'uqId')
229 'https://www.hotstar.com/%s' % video
['contentId'],
230 ie
=HotStarIE
.ie_key(), video_id
=video
['contentId'])
231 for video
in collection
['assets']['items']
232 if video
.get('contentId')]
234 return self
.playlist_result(entries
, playlist_id
)
237 class HotStarSeriesIE(HotStarBaseIE
):
238 IE_NAME
= 'hotstar:series'
239 _VALID_URL
= r
'(?:https?://)(?:www\.)?hotstar\.com(?:/in)?/tv/[^/]+/(?P<id>\d+)'
241 'url': 'https://www.hotstar.com/in/tv/radhakrishn/1260000646',
245 'playlist_mincount': 690,
247 'url': 'https://www.hotstar.com/tv/dancee-/1260050431',
251 'playlist_mincount': 43,
253 'url': 'https://www.hotstar.com/in/tv/mahabharat/435/',
257 'playlist_mincount': 269,
260 def _real_extract(self
, url
):
261 series_id
= self
._match
_id
(url
)
263 'x-country-code': 'IN',
264 'x-platform-code': 'PCTV',
266 detail_json
= self
._download
_json
('https://api.hotstar.com/o/v1/show/detail?contentId=' + series_id
,
267 video_id
=series_id
, headers
=headers
)
268 id = compat_str(try_get(detail_json
, lambda x
: x
['body']['results']['item']['id'], int))
269 item_json
= self
._download
_json
('https://api.hotstar.com/o/v1/tray/g/1/items?etid=0&tao=0&tas=10000&eid=' + id,
270 video_id
=series_id
, headers
=headers
)
273 'https://www.hotstar.com/%d' % video
['contentId'],
274 ie
=HotStarIE
.ie_key(), video_id
=video
['contentId'])
275 for video
in item_json
['body']['results']['items']
276 if video
.get('contentId')]
278 return self
.playlist_result(entries
, series_id
)