]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hotstar.py
   2 from __future__ 
import unicode_literals
 
   8 from .common 
import InfoExtractor
 
   9 from ..compat 
import compat_HTTPError
 
  18 class HotStarBaseIE(InfoExtractor
): 
  19     _AKAMAI_ENCRYPTION_KEY 
= b
'\x05\xfc\x1a\x01\xca\xc9\x4b\xc4\x12\xfc\x53\x12\x07\x75\xf9\xee' 
  21     def _call_api(self
, path
, video_id
, query_name
='contentId'): 
  24         auth 
= 'st=%d~exp=%d~acl=/*' % (st
, exp
) 
  25         auth 
+= '~hmac=' + hmac
.new(self
._AKAMAI
_ENCRYPTION
_KEY
, auth
.encode(), hashlib
.sha256
).hexdigest() 
  26         response 
= self
._download
_json
( 
  27             'https://api.hotstar.com/' + path
, 
  30                 'x-country-code': 'IN', 
  31                 'x-platform-code': 'JIO', 
  36         if response
['statusCode'] != 'OK': 
  38                 response
['body']['message'], expected
=True) 
  39         return response
['body']['results'] 
  42 class HotStarIE(HotStarBaseIE
): 
  44     _VALID_URL 
= r
'https?://(?:www\.)?hotstar\.com/(?:.+?[/-])?(?P<id>\d{10})' 
  47         'url': 'https://www.hotstar.com/can-you-not-spread-rumours/1000076273', 
  51             'title': 'Can You Not Spread Rumours?', 
  52             'description': 'md5:c957d8868e9bc793ccb813691cc4c434', 
  53             'timestamp': 1447248600, 
  54             'upload_date': '20151111', 
  59             'skip_download': True, 
  63         'url': 'https://www.hotstar.com/movies/radha-gopalam/1000057157', 
  64         'only_matching': True, 
  66         'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583', 
  67         'only_matching': True, 
  69         'url': 'http://www.hotstar.com/1000000515', 
  70         'only_matching': True, 
  74     def _real_extract(self
, url
): 
  75         video_id 
= self
._match
_id
(url
) 
  77         webpage 
= self
._download
_webpage
(url
, video_id
) 
  78         app_state 
= self
._parse
_json
(self
._search
_regex
( 
  79             r
'<script>window\.APP_STATE\s*=\s*({.+?})</script>', 
  80             webpage
, 'app state'), video_id
) 
  83             lambda x
, k
=k
: x
['initialState']['content%s' % k
]['content'] 
  84             for k 
in ('Data', 'Detail') 
  86         for v 
in app_state
.values(): 
  87             content 
= try_get(v
, getters
, dict) 
  88             if content 
and content
.get('contentId') == video_id
: 
  92         title 
= video_data
['title'] 
  94         if video_data
.get('drmProtected'): 
  95             raise ExtractorError('This video is DRM protected.', expected
=True) 
  98         format_data 
= self
._call
_api
('h/v1/play', video_id
)['item'] 
  99         format_url 
= format_data
['playbackUrl'] 
 100         ext 
= determine_ext(format_url
) 
 103                 formats
.extend(self
._extract
_m
3u8_formats
( 
 104                     format_url
, video_id
, 'mp4', m3u8_id
='hls')) 
 105             except ExtractorError 
as e
: 
 106                 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code 
== 403: 
 107                     self
.raise_geo_restricted(countries
=['IN']) 
 110             # produce broken files 
 115                 'width': int_or_none(format_data
.get('width')), 
 116                 'height': int_or_none(format_data
.get('height')), 
 118         self
._sort
_formats
(formats
) 
 123             'description': video_data
.get('description'), 
 124             'duration': int_or_none(video_data
.get('duration')), 
 125             'timestamp': int_or_none(video_data
.get('broadcastDate') or video_data
.get('startDate')), 
 127             'channel': video_data
.get('channelName'), 
 128             'channel_id': video_data
.get('channelId'), 
 129             'series': video_data
.get('showName'), 
 130             'season': video_data
.get('seasonName'), 
 131             'season_number': int_or_none(video_data
.get('seasonNo')), 
 132             'season_id': video_data
.get('seasonId'), 
 134             'episode_number': int_or_none(video_data
.get('episodeNo')), 
 138 class HotStarPlaylistIE(HotStarBaseIE
): 
 139     IE_NAME 
= 'hotstar:playlist' 
 140     _VALID_URL 
= r
'https?://(?:www\.)?hotstar\.com/tv/[^/]+/s-\w+/list/[^/]+/t-(?P<id>\w+)' 
 142         'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/popular-clips/t-3_2_26', 
 146         'playlist_mincount': 20, 
 148         'url': 'https://www.hotstar.com/tv/savdhaan-india/s-26/list/extras/t-2480', 
 149         'only_matching': True, 
 152     def _real_extract(self
, url
): 
 153         playlist_id 
= self
._match
_id
(url
) 
 155         collection 
= self
._call
_api
('o/v1/tray/find', playlist_id
, 'uqId') 
 159                 'https://www.hotstar.com/%s' % video
['contentId'], 
 160                 ie
=HotStarIE
.ie_key(), video_id
=video
['contentId']) 
 161             for video 
in collection
['assets']['items'] 
 162             if video
.get('contentId')] 
 164         return self
.playlist_result(entries
, playlist_id
)