From 9fc0de579658de0c73ea03d61a76df8b0e154e23 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Wed, 23 Jun 2021 06:04:20 +0530 Subject: [PATCH] [hotstar] Use server time for authentication instead of local time Closes #396 --- yt_dlp/extractor/hotstar.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/yt_dlp/extractor/hotstar.py b/yt_dlp/extractor/hotstar.py index 430b4e236..35825740d 100644 --- a/yt_dlp/extractor/hotstar.py +++ b/yt_dlp/extractor/hotstar.py @@ -27,8 +27,8 @@ class HotStarBaseIE(InfoExtractor): _AKAMAI_ENCRYPTION_KEY = b'\x05\xfc\x1a\x01\xca\xc9\x4b\xc4\x12\xfc\x53\x12\x07\x75\xf9\xee' - def _call_api_impl(self, path, video_id, query): - st = int(time.time()) + def _call_api_impl(self, path, video_id, query, st=None): + st = int_or_none(st) or int(time.time()) exp = st + 6000 auth = 'st=%d~exp=%d~acl=/*' % (st, exp) auth += '~hmac=' + hmac.new(self._AKAMAI_ENCRYPTION_KEY, auth.encode(), hashlib.sha256).hexdigest() @@ -75,9 +75,9 @@ def _call_api(self, path, video_id, query_name='contentId'): 'tas': 10000, }) - def _call_api_v2(self, path, video_id): + def _call_api_v2(self, path, video_id, st=None): return self._call_api_impl( - '%s/content/%s' % (path, video_id), video_id, { + '%s/content/%s' % (path, video_id), video_id, st=st, query={ 'desired-config': 'audio_channel:stereo|dynamic_range:sdr|encryption:plain|ladder:tv|package:dash|resolution:hd|subs-tag:HotstarVIP|video_codec:vp9', 'device-id': compat_str(uuid.uuid4()), 'os-name': 'Windows', @@ -131,7 +131,8 @@ class HotStarIE(HotStarBaseIE): def _real_extract(self, url): video_id = self._match_id(url) - webpage = self._download_webpage(url, video_id) + webpage, urlh = self._download_webpage_handle(url, video_id) + st = urlh.headers.get('x-origin-date') app_state = self._parse_json(self._search_regex( r'', webpage, 'app state'), video_id) @@ -155,7 +156,7 @@ def _real_extract(self, url): formats = [] geo_restricted = False # change to v2 in the future - playback_sets = self._call_api_v2('play/v1/playback', video_id)['playBackSets'] + playback_sets = self._call_api_v2('play/v1/playback', video_id, st=st)['playBackSets'] for playback_set in playback_sets: if not isinstance(playback_set, dict): continue