]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hotstar.py
f9f7c5a645793eb13c44af45914b768b1982fe2d
2 from __future__
import unicode_literals
10 from .common
import InfoExtractor
11 from ..compat
import (
25 class HotStarBaseIE(InfoExtractor
):
26 _AKAMAI_ENCRYPTION_KEY
= b
'\x05\xfc\x1a\x01\xca\xc9\x4b\xc4\x12\xfc\x53\x12\x07\x75\xf9\xee'
28 def _call_api_impl(self
, path
, video_id
, query
):
31 auth
= 'st=%d~exp=%d~acl=/*' % (st
, exp
)
32 auth
+= '~hmac=' + hmac
.new(self
._AKAMAI
_ENCRYPTION
_KEY
, auth
.encode(), hashlib
.sha256
).hexdigest()
33 response
= self
._download
_json
(
34 'https://api.hotstar.com/' + path
, video_id
, headers
={
36 'x-country-code': 'IN',
37 'x-platform-code': 'JIO',
39 if response
['statusCode'] != 'OK':
41 response
['body']['message'], expected
=True)
42 return response
['body']['results']
44 def _call_api(self
, path
, video_id
, query_name
='contentId'):
45 return self
._call
_api
_impl
(path
, video_id
, {
50 def _call_api_v2(self
, path
, video_id
):
51 return self
._call
_api
_impl
(
52 '%s/in/contents/%s' % (path
, video_id
), video_id
, {
53 'desiredConfig': 'encryption:plain;ladder:phone,tv;package:hls,dash',
55 'clientVersion': '6.18.0',
56 'deviceId': compat_str(uuid
.uuid4()),
62 class HotStarIE(HotStarBaseIE
):
64 _VALID_URL
= r
'https?://(?:www\.)?hotstar\.com/(?:.+?[/-])?(?P<id>\d{10})'
67 'url': 'https://www.hotstar.com/can-you-not-spread-rumours/1000076273',
71 'title': 'Can You Not Spread Rumours?',
72 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
73 'timestamp': 1447248600,
74 'upload_date': '20151111',
79 'skip_download': True,
83 'url': 'https://www.hotstar.com/movies/radha-gopalam/1000057157',
84 'only_matching': True,
86 'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583',
87 'only_matching': True,
89 'url': 'http://www.hotstar.com/1000000515',
90 'only_matching': True,
92 # only available via api v2
93 'url': 'https://www.hotstar.com/tv/ek-bhram-sarvagun-sampanna/s-2116/janhvi-targets-suman/1000234847',
94 'only_matching': True,
98 def _real_extract(self
, url
):
99 video_id
= self
._match
_id
(url
)
101 webpage
= self
._download
_webpage
(url
, video_id
)
102 app_state
= self
._parse
_json
(self
._search
_regex
(
103 r
'<script>window\.APP_STATE\s*=\s*({.+?})</script>',
104 webpage
, 'app state'), video_id
)
107 lambda x
, k
=k
: x
['initialState']['content%s' % k
]['content']
108 for k
in ('Data', 'Detail')
110 for v
in app_state
.values():
111 content
= try_get(v
, getters
, dict)
112 if content
and content
.get('contentId') == video_id
:
116 title
= video_data
['title']
118 if video_data
.get('drmProtected'):
119 raise ExtractorError('This video is DRM protected.', expected
=True)
122 geo_restricted
= False
123 playback_sets
= self
._call
_api
_v
2('h/v2/play', video_id
)['playBackSets']
124 for playback_set
in playback_sets
:
125 if not isinstance(playback_set
, dict):
127 format_url
= url_or_none(playback_set
.get('playbackUrl'))
131 r
'(?<=//staragvod)(\d)', r
'web\1', format_url
)
132 tags
= str_or_none(playback_set
.get('tagsCombination')) or ''
133 if tags
and 'encryption:plain' not in tags
:
135 ext
= determine_ext(format_url
)
137 if 'package:hls' in tags
or ext
== 'm3u8':
138 formats
.extend(self
._extract
_m
3u8_formats
(
139 format_url
, video_id
, 'mp4',
140 entry_protocol
='m3u8_native', m3u8_id
='hls'))
141 elif 'package:dash' in tags
or ext
== 'mpd':
142 formats
.extend(self
._extract
_mpd
_formats
(
143 format_url
, video_id
, mpd_id
='dash'))
145 # produce broken files
150 'width': int_or_none(playback_set
.get('width')),
151 'height': int_or_none(playback_set
.get('height')),
153 except ExtractorError
as e
:
154 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
155 geo_restricted
= True
157 if not formats
and geo_restricted
:
158 self
.raise_geo_restricted(countries
=['IN'])
159 self
._sort
_formats
(formats
)
164 'description': video_data
.get('description'),
165 'duration': int_or_none(video_data
.get('duration')),
166 'timestamp': int_or_none(video_data
.get('broadcastDate') or video_data
.get('startDate')),
168 'channel': video_data
.get('channelName'),
169 'channel_id': video_data
.get('channelId'),
170 'series': video_data
.get('showName'),
171 'season': video_data
.get('seasonName'),
172 'season_number': int_or_none(video_data
.get('seasonNo')),
173 'season_id': video_data
.get('seasonId'),
175 'episode_number': int_or_none(video_data
.get('episodeNo')),
179 class HotStarPlaylistIE(HotStarBaseIE
):
180 IE_NAME
= 'hotstar:playlist'
181 _VALID_URL
= r
'https?://(?:www\.)?hotstar\.com/tv/[^/]+/s-\w+/list/[^/]+/t-(?P<id>\w+)'
183 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/popular-clips/t-3_2_26',
187 'playlist_mincount': 20,
189 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/extras/t-2480',
190 'only_matching': True,
193 def _real_extract(self
, url
):
194 playlist_id
= self
._match
_id
(url
)
196 collection
= self
._call
_api
('o/v1/tray/find', playlist_id
, 'uqId')
200 'https://www.hotstar.com/%s' % video
['contentId'],
201 ie
=HotStarIE
.ie_key(), video_id
=video
['contentId'])
202 for video
in collection
['assets']['items']
203 if video
.get('contentId')]
205 return self
.playlist_result(entries
, playlist_id
)