mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-13 14:37:43 +01:00
[hotstar] several api changes and payloads/queries
This commit is contained in:
parent
3a379e5e83
commit
6923b5381f
@ -7,11 +7,12 @@
|
|||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
|
import random
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_HTTPError,
|
compat_HTTPError,
|
||||||
compat_str,
|
compat_str
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
determine_ext,
|
determine_ext,
|
||||||
@ -31,14 +32,30 @@ def _call_api_impl(self, path, video_id, query):
|
|||||||
exp = st + 6000
|
exp = st + 6000
|
||||||
auth = 'st=%d~exp=%d~acl=/*' % (st, exp)
|
auth = 'st=%d~exp=%d~acl=/*' % (st, exp)
|
||||||
auth += '~hmac=' + hmac.new(self._AKAMAI_ENCRYPTION_KEY, auth.encode(), hashlib.sha256).hexdigest()
|
auth += '~hmac=' + hmac.new(self._AKAMAI_ENCRYPTION_KEY, auth.encode(), hashlib.sha256).hexdigest()
|
||||||
|
|
||||||
|
def _generate_device_id():
|
||||||
|
"""
|
||||||
|
Reversed from javascript library.
|
||||||
|
JS function is generateUUID
|
||||||
|
"""
|
||||||
|
t = int(round(time.time() * 1000))
|
||||||
|
e = "xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx" # 4 seems to be interchangeable
|
||||||
|
|
||||||
|
def _replacer():
|
||||||
|
n = int((t + 16 * random.random())) % 16 | 0
|
||||||
|
return hex(n if "x" == e else 3 & n | 8)[2:]
|
||||||
|
return "".join([_.replace('x', _replacer()) for _ in e])
|
||||||
|
|
||||||
token = self._download_json(
|
token = self._download_json(
|
||||||
'https://api.hotstar.com/in/aadhar/v2/web/in/user/guest-signup',
|
'https://api.hotstar.com/um/v3/users',
|
||||||
video_id, note='Downloading token',
|
video_id, note='Downloading token',
|
||||||
data=json.dumps({"idType": "device", "id": compat_str(uuid.uuid4())}).encode('utf-8'),
|
data=json.dumps({"device_ids": [{"id": compat_str(uuid.uuid4()), "type": "device_id"}]}).encode('utf-8'),
|
||||||
headers={
|
headers={
|
||||||
'hotstarauth': auth,
|
'hotstarauth': auth,
|
||||||
|
'x-hs-platform': 'PCTV', # or 'web'
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
})['description']['userIdentity']
|
})['user_identity']
|
||||||
|
|
||||||
response = self._download_json(
|
response = self._download_json(
|
||||||
'https://api.hotstar.com/' + path, video_id, headers={
|
'https://api.hotstar.com/' + path, video_id, headers={
|
||||||
'hotstarauth': auth,
|
'hotstarauth': auth,
|
||||||
@ -46,6 +63,7 @@ def _call_api_impl(self, path, video_id, query):
|
|||||||
'x-hs-platform': 'web',
|
'x-hs-platform': 'web',
|
||||||
'x-hs-usertoken': token,
|
'x-hs-usertoken': token,
|
||||||
}, query=query)
|
}, query=query)
|
||||||
|
|
||||||
if response['message'] != "Playback URL's fetched successfully":
|
if response['message'] != "Playback URL's fetched successfully":
|
||||||
raise ExtractorError(
|
raise ExtractorError(
|
||||||
response['message'], expected=True)
|
response['message'], expected=True)
|
||||||
@ -60,7 +78,7 @@ def _call_api(self, path, video_id, query_name='contentId'):
|
|||||||
def _call_api_v2(self, path, video_id):
|
def _call_api_v2(self, path, video_id):
|
||||||
return self._call_api_impl(
|
return self._call_api_impl(
|
||||||
'%s/content/%s' % (path, video_id), video_id, {
|
'%s/content/%s' % (path, video_id), video_id, {
|
||||||
'desired-config': 'encryption:plain;ladder:phone,tv;package:hls,dash',
|
'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()),
|
'device-id': compat_str(uuid.uuid4()),
|
||||||
'os-name': 'Windows',
|
'os-name': 'Windows',
|
||||||
'os-version': '10',
|
'os-version': '10',
|
||||||
@ -129,6 +147,7 @@ def _real_extract(self, url):
|
|||||||
headers = {'Referer': url}
|
headers = {'Referer': url}
|
||||||
formats = []
|
formats = []
|
||||||
geo_restricted = False
|
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)['playBackSets']
|
||||||
for playback_set in playback_sets:
|
for playback_set in playback_sets:
|
||||||
if not isinstance(playback_set, dict):
|
if not isinstance(playback_set, dict):
|
||||||
|
Loading…
Reference in New Issue
Block a user