2 from __future__
import unicode_literals
12 from .common
import InfoExtractor
13 from ..compat
import (
27 class HotStarBaseIE(InfoExtractor
):
28 _AKAMAI_ENCRYPTION_KEY
= b
'\x05\xfc\x1a\x01\xca\xc9\x4b\xc4\x12\xfc\x53\x12\x07\x75\xf9\xee'
30 def _call_api_impl(self
, path
, video_id
, query
):
33 auth
= 'st=%d~exp=%d~acl=/*' % (st
, exp
)
34 auth
+= '~hmac=' + hmac
.new(self
._AKAMAI
_ENCRYPTION
_KEY
, auth
.encode(), hashlib
.sha256
).hexdigest()
36 def _generate_device_id():
38 Reversed from javascript library.
39 JS function is generateUUID
41 t
= int(round(time
.time() * 1000))
42 e
= "xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx" # 4 seems to be interchangeable
45 n
= int((t
+ 16 * random
.random())) % 16 |
0
46 return hex(n
if "x" == e
else 3 & n |
8)[2:]
47 return "".join([_
.replace('x', _replacer()) for _
in e
])
49 token
= self
._download
_json
(
50 'https://api.hotstar.com/um/v3/users',
51 video_id
, note
='Downloading token',
52 data
=json
.dumps({"device_ids": [{"id": compat_str(uuid.uuid4()), "type": "device_id"}
]}).encode('utf-8'),
55 'x-hs-platform': 'PCTV', # or 'web'
56 'Content-Type': 'application/json',
59 response
= self
._download
_json
(
60 'https://api.hotstar.com/' + path
, video_id
, headers
={
62 'x-hs-appversion': '6.72.2',
63 'x-hs-platform': 'web',
64 'x-hs-usertoken': token
,
67 if response
['message'] != "Playback URL's fetched successfully":
69 response
['message'], expected
=True)
70 return response
['data']
72 def _call_api(self
, path
, video_id
, query_name
='contentId'):
73 return self
._call
_api
_impl
(path
, video_id
, {
78 def _call_api_v2(self
, path
, video_id
):
79 return self
._call
_api
_impl
(
80 '%s/content/%s' % (path
, video_id
), video_id
, {
81 'desired-config': 'audio_channel:stereo|dynamic_range:sdr|encryption:plain|ladder:tv|package:dash|resolution:hd|subs-tag:HotstarVIP|video_codec:vp9',
82 'device-id': compat_str(uuid
.uuid4()),
88 class HotStarIE(HotStarBaseIE
):
90 _VALID_URL
= r
'https?://(?:www\.)?hotstar\.com/.*(?P<id>\d{10})'
93 'url': 'https://www.hotstar.com/can-you-not-spread-rumours/1000076273',
97 'title': 'Can You Not Spread Rumours?',
98 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
99 'timestamp': 1447248600,
100 'upload_date': '20151111',
105 'skip_download': True,
109 'url': 'https://www.hotstar.com/movies/radha-gopalam/1000057157',
110 'only_matching': True,
112 'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583',
113 'only_matching': True,
115 'url': 'http://www.hotstar.com/1000000515',
116 'only_matching': True,
118 # only available via api v2
119 'url': 'https://www.hotstar.com/tv/ek-bhram-sarvagun-sampanna/s-2116/janhvi-targets-suman/1000234847',
120 'only_matching': True,
124 def _real_extract(self
, url
):
125 video_id
= self
._match
_id
(url
)
127 webpage
= self
._download
_webpage
(url
, video_id
)
128 app_state
= self
._parse
_json
(self
._search
_regex
(
129 r
'<script>window\.APP_STATE\s*=\s*({.+?})</script>',
130 webpage
, 'app state'), video_id
)
133 lambda x
, k
=k
: x
['initialState']['content%s' % k
]['content']
134 for k
in ('Data', 'Detail')
136 for v
in app_state
.values():
137 content
= try_get(v
, getters
, dict)
138 if content
and content
.get('contentId') == video_id
:
142 title
= video_data
['title']
144 if video_data
.get('drmProtected'):
145 raise ExtractorError('This video is DRM protected.', expected
=True)
147 headers
= {'Referer': url}
149 geo_restricted
= False
150 # change to v2 in the future
151 playback_sets
= self
._call
_api
_v
2('play/v1/playback', video_id
)['playBackSets']
152 for playback_set
in playback_sets
:
153 if not isinstance(playback_set
, dict):
155 format_url
= url_or_none(playback_set
.get('playbackUrl'))
159 r
'(?<=//staragvod)(\d)', r
'web\1', format_url
)
160 tags
= str_or_none(playback_set
.get('tagsCombination')) or ''
161 if tags
and 'encryption:plain' not in tags
:
163 ext
= determine_ext(format_url
)
165 if 'package:hls' in tags
or ext
== 'm3u8':
166 formats
.extend(self
._extract
_m
3u8_formats
(
167 format_url
, video_id
, 'mp4',
168 entry_protocol
='m3u8_native',
169 m3u8_id
='hls', headers
=headers
))
170 elif 'package:dash' in tags
or ext
== 'mpd':
171 formats
.extend(self
._extract
_mpd
_formats
(
172 format_url
, video_id
, mpd_id
='dash', headers
=headers
))
174 # produce broken files
179 'width': int_or_none(playback_set
.get('width')),
180 'height': int_or_none(playback_set
.get('height')),
182 except ExtractorError
as e
:
183 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
184 geo_restricted
= True
186 if not formats
and geo_restricted
:
187 self
.raise_geo_restricted(countries
=['IN'])
188 self
._sort
_formats
(formats
)
191 f
.setdefault('http_headers', {}).update(headers
)
196 'description': video_data
.get('description'),
197 'duration': int_or_none(video_data
.get('duration')),
198 'timestamp': int_or_none(video_data
.get('broadcastDate') or video_data
.get('startDate')),
200 'channel': video_data
.get('channelName'),
201 'channel_id': video_data
.get('channelId'),
202 'series': video_data
.get('showName'),
203 'season': video_data
.get('seasonName'),
204 'season_number': int_or_none(video_data
.get('seasonNo')),
205 'season_id': video_data
.get('seasonId'),
207 'episode_number': int_or_none(video_data
.get('episodeNo')),
211 class HotStarPlaylistIE(HotStarBaseIE
):
212 IE_NAME
= 'hotstar:playlist'
213 _VALID_URL
= r
'https?://(?:www\.)?hotstar\.com/tv/[^/]+/s-\w+/list/[^/]+/t-(?P<id>\w+)'
215 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/popular-clips/t-3_2_26',
219 'playlist_mincount': 20,
221 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/extras/t-2480',
222 'only_matching': True,
225 def _real_extract(self
, url
):
226 playlist_id
= self
._match
_id
(url
)
228 collection
= self
._call
_api
('o/v1/tray/find', playlist_id
, 'uqId')
232 'https://www.hotstar.com/%s' % video
['contentId'],
233 ie
=HotStarIE
.ie_key(), video_id
=video
['contentId'])
234 for video
in collection
['assets']['items']
235 if video
.get('contentId')]
237 return self
.playlist_result(entries
, playlist_id
)