From de796eaae99b9c7fe9836f83a686dd479112e678 Mon Sep 17 00:00:00 2001 From: Dev Bali Date: Tue, 22 Jun 2021 18:41:47 -0700 Subject: [PATCH 1/3] Added Cookie Functionality to Hotstar --- youtube_dl/extractor/hotstar.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/hotstar.py b/youtube_dl/extractor/hotstar.py index 1620822b6..c45de6428 100644 --- a/youtube_dl/extractor/hotstar.py +++ b/youtube_dl/extractor/hotstar.py @@ -20,22 +20,27 @@ from ..utils import ( str_or_none, try_get, url_or_none, + urlencode_postdata, + sanitized_Request ) 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, headers, query, data=None): + def _call_api_impl(self, path, video_id, headers, query, data=None,method=None): st = 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() h = {'hotstarauth': auth} h.update(headers) + + req = sanitized_Request('https://api.hotstar.com/' + path, data=data) + if method is not None: req.get_method = lambda: method + return self._download_json( - 'https://api.hotstar.com/' + path, - video_id, headers=h, query=query, data=data) + req,video_id, headers=h, query=query, data=data) def _call_api(self, path, video_id, query_name='contentId'): response = self._call_api_impl(path, video_id, { @@ -53,13 +58,15 @@ class HotStarBaseIE(InfoExtractor): def _call_api_v2(self, path, video_id, headers, query=None, data=None): h = {'X-Request-Id': compat_str(uuid.uuid4())} h.update(headers) + try: return self._call_api_impl( path, video_id, h, query, data) except ExtractorError as e: if isinstance(e.cause, compat_HTTPError): if e.cause.code == 402: - self.raise_login_required() + raise ExtractorError('This video is only available for registered users. You may want to use --cookies.', expected=True) + message = self._parse_json(e.cause.read().decode(), video_id)['message'] if message in ('Content not available in region', 'Country is not supported'): raise self.raise_geo_restricted(message) @@ -135,6 +142,13 @@ class HotStarIE(HotStarBaseIE): formats = [] geo_restricted = False + for cookie in self._downloader.cookiejar: + if "hotstar" in cookie.domain: + if cookie.name == "userUP": + self._USER_TOKEN = cookie.value + elif cookie.name == "device-id": + self._DEVICE_ID = cookie.value + if not self._USER_TOKEN: self._DEVICE_ID = compat_str(uuid.uuid4()) self._USER_TOKEN = self._call_api_v2('um/v3/users', video_id, { From ab174d33b87a9915973bc4d7bf41e07dcb217717 Mon Sep 17 00:00:00 2001 From: Dev Bali Date: Tue, 22 Jun 2021 18:50:20 -0700 Subject: [PATCH 2/3] Added Cookie Functionality to Hotstar --- youtube_dl/extractor/hotstar.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/youtube_dl/extractor/hotstar.py b/youtube_dl/extractor/hotstar.py index c45de6428..6af049609 100644 --- a/youtube_dl/extractor/hotstar.py +++ b/youtube_dl/extractor/hotstar.py @@ -19,16 +19,14 @@ from ..utils import ( int_or_none, str_or_none, try_get, - url_or_none, - urlencode_postdata, - sanitized_Request + url_or_none ) 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, headers, query, data=None,method=None): + def _call_api_impl(self, path, video_id, headers, query, data=None): st = int(time.time()) exp = st + 6000 auth = 'st=%d~exp=%d~acl=/*' % (st, exp) @@ -36,11 +34,8 @@ class HotStarBaseIE(InfoExtractor): h = {'hotstarauth': auth} h.update(headers) - req = sanitized_Request('https://api.hotstar.com/' + path, data=data) - if method is not None: req.get_method = lambda: method - return self._download_json( - req,video_id, headers=h, query=query, data=data) + 'https://api.hotstar.com/' + path,video_id, headers=h, query=query, data=data) def _call_api(self, path, video_id, query_name='contentId'): response = self._call_api_impl(path, video_id, { @@ -58,7 +53,6 @@ class HotStarBaseIE(InfoExtractor): def _call_api_v2(self, path, video_id, headers, query=None, data=None): h = {'X-Request-Id': compat_str(uuid.uuid4())} h.update(headers) - try: return self._call_api_impl( path, video_id, h, query, data) From 133430479392f1f427cf95d11dfd5b489299ba15 Mon Sep 17 00:00:00 2001 From: Dev Bali Date: Tue, 22 Jun 2021 19:08:41 -0700 Subject: [PATCH 3/3] Added Cookie Functionality to Hotstar --- youtube_dl/extractor/hotstar.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/hotstar.py b/youtube_dl/extractor/hotstar.py index 6af049609..b31e1eb03 100644 --- a/youtube_dl/extractor/hotstar.py +++ b/youtube_dl/extractor/hotstar.py @@ -19,7 +19,7 @@ from ..utils import ( int_or_none, str_or_none, try_get, - url_or_none + url_or_none, ) @@ -35,7 +35,8 @@ class HotStarBaseIE(InfoExtractor): h.update(headers) return self._download_json( - 'https://api.hotstar.com/' + path,video_id, headers=h, query=query, data=data) + 'https://api.hotstar.com/' + path, + video_id, headers=h, query=query, data=data) def _call_api(self, path, video_id, query_name='contentId'): response = self._call_api_impl(path, video_id, {