]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hotstar.py
79d5bbb2e8bb297e099efb44b2d5451eb06562ca
2 from __future__
import unicode_literals
9 from .common
import InfoExtractor
10 from ..compat
import (
24 class HotStarBaseIE(InfoExtractor
):
25 _AKAMAI_ENCRYPTION_KEY
= b
'\x05\xfc\x1a\x01\xca\xc9\x4b\xc4\x12\xfc\x53\x12\x07\x75\xf9\xee'
27 def _call_api_impl(self
, path
, video_id
, query
):
30 auth
= 'st=%d~exp=%d~acl=/*' % (st
, exp
)
31 auth
+= '~hmac=' + hmac
.new(self
._AKAMAI
_ENCRYPTION
_KEY
, auth
.encode(), hashlib
.sha256
).hexdigest()
32 response
= self
._download
_json
(
33 'https://api.hotstar.com/' + path
, video_id
, headers
={
35 'x-country-code': 'IN',
36 'x-platform-code': 'JIO',
38 if response
['statusCode'] != 'OK':
40 response
['body']['message'], expected
=True)
41 return response
['body']['results']
43 def _call_api(self
, path
, video_id
, query_name
='contentId'):
44 return self
._call
_api
_impl
(path
, video_id
, {
49 def _call_api_v2(self
, path
, video_id
):
50 return self
._call
_api
_impl
(
51 '%s/in/contents/%s' % (path
, video_id
), video_id
, {
52 'desiredConfig': 'encryption:plain;ladder:phone,tv;package:hls,dash',
54 'clientVersion': '6.18.0',
55 'deviceId': compat_str(uuid
.uuid4()),
61 class HotStarIE(HotStarBaseIE
):
63 _VALID_URL
= r
'https?://(?:www\.)?hotstar\.com/(?:.+?[/-])?(?P<id>\d{10})'
66 'url': 'https://www.hotstar.com/can-you-not-spread-rumours/1000076273',
70 'title': 'Can You Not Spread Rumours?',
71 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
72 'timestamp': 1447248600,
73 'upload_date': '20151111',
78 'skip_download': True,
82 'url': 'https://www.hotstar.com/movies/radha-gopalam/1000057157',
83 'only_matching': True,
85 'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583',
86 'only_matching': True,
88 'url': 'http://www.hotstar.com/1000000515',
89 'only_matching': True,
91 # only available via api v2
92 'url': 'https://www.hotstar.com/tv/ek-bhram-sarvagun-sampanna/s-2116/janhvi-targets-suman/1000234847',
93 'only_matching': True,
97 def _real_extract(self
, url
):
98 video_id
= self
._match
_id
(url
)
100 webpage
= self
._download
_webpage
(url
, video_id
)
101 app_state
= self
._parse
_json
(self
._search
_regex
(
102 r
'<script>window\.APP_STATE\s*=\s*({.+?})</script>',
103 webpage
, 'app state'), video_id
)
106 lambda x
, k
=k
: x
['initialState']['content%s' % k
]['content']
107 for k
in ('Data', 'Detail')
109 for v
in app_state
.values():
110 content
= try_get(v
, getters
, dict)
111 if content
and content
.get('contentId') == video_id
:
115 title
= video_data
['title']
117 if video_data
.get('drmProtected'):
118 raise ExtractorError('This video is DRM protected.', expected
=True)
121 geo_restricted
= False
122 playback_sets
= self
._call
_api
_v
2('h/v2/play', video_id
)['playBackSets']
123 for playback_set
in playback_sets
:
124 if not isinstance(playback_set
, dict):
126 format_url
= url_or_none(playback_set
.get('playbackUrl'))
129 tags
= str_or_none(playback_set
.get('tagsCombination')) or ''
130 if tags
and 'encryption:plain' not in tags
:
132 ext
= determine_ext(format_url
)
134 if 'package:hls' in tags
or ext
== 'm3u8':
135 formats
.extend(self
._extract
_m
3u8_formats
(
136 format_url
, video_id
, 'mp4', m3u8_id
='hls'))
137 elif 'package:dash' in tags
or ext
== 'mpd':
138 formats
.extend(self
._extract
_mpd
_formats
(
139 format_url
, video_id
, mpd_id
='dash'))
141 # produce broken files
146 'width': int_or_none(playback_set
.get('width')),
147 'height': int_or_none(playback_set
.get('height')),
149 except ExtractorError
as e
:
150 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
151 geo_restricted
= True
153 if not formats
and geo_restricted
:
154 self
.raise_geo_restricted(countries
=['IN'])
155 self
._sort
_formats
(formats
)
160 'description': video_data
.get('description'),
161 'duration': int_or_none(video_data
.get('duration')),
162 'timestamp': int_or_none(video_data
.get('broadcastDate') or video_data
.get('startDate')),
164 'channel': video_data
.get('channelName'),
165 'channel_id': video_data
.get('channelId'),
166 'series': video_data
.get('showName'),
167 'season': video_data
.get('seasonName'),
168 'season_number': int_or_none(video_data
.get('seasonNo')),
169 'season_id': video_data
.get('seasonId'),
171 'episode_number': int_or_none(video_data
.get('episodeNo')),
175 class HotStarPlaylistIE(HotStarBaseIE
):
176 IE_NAME
= 'hotstar:playlist'
177 _VALID_URL
= r
'https?://(?:www\.)?hotstar\.com/tv/[^/]+/s-\w+/list/[^/]+/t-(?P<id>\w+)'
179 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/popular-clips/t-3_2_26',
183 'playlist_mincount': 20,
185 'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/extras/t-2480',
186 'only_matching': True,
189 def _real_extract(self
, url
):
190 playlist_id
= self
._match
_id
(url
)
192 collection
= self
._call
_api
('o/v1/tray/find', playlist_id
, 'uqId')
196 'https://www.hotstar.com/%s' % video
['contentId'],
197 ie
=HotStarIE
.ie_key(), video_id
=video
['contentId'])
198 for video
in collection
['assets']['items']
199 if video
.get('contentId')]
201 return self
.playlist_result(entries
, playlist_id
)