Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotstar] Move to API v1 #48

Merged
merged 1 commit into from Sep 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 21 additions & 13 deletions youtube_dlc/extractor/hotstar.py
Expand Up @@ -6,6 +6,7 @@
import re
import time
import uuid
import json

from .common import InfoExtractor
from ..compat import (
Expand All @@ -30,16 +31,25 @@ def _call_api_impl(self, path, video_id, query):
exp = st + 6000
auth = 'st=%d~exp=%d~acl=/*' % (st, exp)
auth += '~hmac=' + hmac.new(self._AKAMAI_ENCRYPTION_KEY, auth.encode(), hashlib.sha256).hexdigest()
token = self._download_json(
'https://api.hotstar.com/in/aadhar/v2/web/in/user/guest-signup',
video_id, note='Downloading token',
data=json.dumps({"idType": "device", "id": compat_str(uuid.uuid4())}).encode('utf-8'),
headers={
'hotstarauth': auth,
'Content-Type': 'application/json',
})['description']['userIdentity']
response = self._download_json(
'https://api.hotstar.com/' + path, video_id, headers={
'hotstarauth': auth,
'x-country-code': 'IN',
'x-platform-code': 'JIO',
'x-hs-appversion': '6.72.2',
'x-hs-platform': 'web',
'x-hs-usertoken': token,
}, query=query)
if response['statusCode'] != 'OK':
if response['message'] != "Playback URL's fetched successfully":
raise ExtractorError(
response['body']['message'], expected=True)
return response['body']['results']
response['message'], expected=True)
return response['data']

def _call_api(self, path, video_id, query_name='contentId'):
return self._call_api_impl(path, video_id, {
Expand All @@ -49,13 +59,11 @@ def _call_api(self, path, video_id, query_name='contentId'):

def _call_api_v2(self, path, video_id):
return self._call_api_impl(
'%s/in/contents/%s' % (path, video_id), video_id, {
'desiredConfig': 'encryption:plain;ladder:phone,tv;package:hls,dash',
'client': 'mweb',
'clientVersion': '6.18.0',
'deviceId': compat_str(uuid.uuid4()),
'osName': 'Windows',
'osVersion': '10',
'%s/content/%s' % (path, video_id), video_id, {
'desired-config': 'encryption:plain;ladder:phone,tv;package:hls,dash',
'device-id': compat_str(uuid.uuid4()),
'os-name': 'Windows',
'os-version': '10',
})


Expand Down Expand Up @@ -121,7 +129,7 @@ def _real_extract(self, url):
headers = {'Referer': url}
formats = []
geo_restricted = False
playback_sets = self._call_api_v2('h/v2/play', video_id)['playBackSets']
playback_sets = self._call_api_v2('play/v1/playback', video_id)['playBackSets']
for playback_set in playback_sets:
if not isinstance(playback_set, dict):
continue
Expand Down