This repository was archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Login procedure change and bugs fixing #3
Open
Vikassm73
wants to merge
15
commits into
botallen:main
Choose a base branch
from
Vikassm73:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e12ca5c
Hotstar 1.2.1
Vikassm73 ceea0fd
Update api.py
Vikassm73 fbb4c90
Updation in Guest Login
Vikassm73 c9f7eb7
Correction in api
Vikassm73 b60a569
Correction in Login
Vikassm73 ab32c3c
Changes in Menuitem
Vikassm73 bb309df
Few corrections
Vikassm73 b0af5aa
Delete resources/__pycache__ directory
Vikassm73 cb6f73b
Delete resources/lib/__pycache__ directory
Vikassm73 9fc9c50
Bugs fixing in login
Vikassm73 b55755e
Bugs fixing
Vikassm73 8dd2f2f
Bugs Fixing
Vikassm73 9434b94
Premium login fix
Vikassm73 20d4eac
Correction in login
Vikassm73 f69c763
Correction in login
Vikassm73 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,36 +2,32 @@ | |
| from __future__ import unicode_literals | ||
|
|
||
| import urlquick | ||
| from xbmc import executebuiltin | ||
| from xbmcgui import Dialog | ||
| from functools import reduce | ||
| from resources.lib.contants import API_BASE_URL, BASE_HEADERS, url_constructor | ||
| from resources.lib.utils import deep_get, updateQueryParams, qualityFilter | ||
| from resources.lib.contants import BASE_HEADERS, url_constructor | ||
| from resources.lib.utils import deep_get, updateQueryParams, qualityFilter, getAuth, guestToken | ||
| from codequick import Script | ||
| from codequick.script import Settings | ||
| from codequick.storage import PersistentDict | ||
| from urllib.parse import quote_plus, urlparse, parse_qsl | ||
| from urllib.parse import quote_plus | ||
| from urllib.request import urlopen, Request | ||
| import time | ||
| import hashlib | ||
| import hmac | ||
| import json | ||
| import re | ||
| from uuid import uuid4 | ||
| import web_pdb | ||
| from base64 import b64decode | ||
|
|
||
|
|
||
| class HotstarAPI: | ||
| device_id = str(uuid4()) | ||
|
|
||
| def __init__(self): | ||
| self.session = urlquick.Session() | ||
| self.session.headers.update(BASE_HEADERS) | ||
|
|
||
| def getMenu(self): | ||
| url = url_constructor("/o/v2/menu") | ||
| resp = self.get( | ||
| url, headers={"x-country-code": "in", "x-platform-code": "ANDROID_TV"}) | ||
| return deep_get(resp, "body.results.menuItems") | ||
| url, headers={"x-country-code": "in", "x-platform-code": "PCTV"}) | ||
| return deep_get(resp["body"]["results"]["menuItems"][0]["subItem"][1], "subItem") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can lead to runtime error.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverse back to old code |
||
|
|
||
| def getPage(self, url): | ||
| results = deep_get(self.get(url), "body.results") | ||
|
|
@@ -49,7 +45,7 @@ def getTray(self, url, search_query=None): | |
| with PersistentDict("userdata.pickle") as db: | ||
| pid = db.get("udata", {}).get("pId") | ||
| results = self.get(url.format(pid=pid), headers={ | ||
| "hotstarauth": self._getAuth(includeST=True, persona=True)}) | ||
| "hotstarauth": getAuth(includeST=True, persona=True)}) | ||
| # ids = ",".join(map(lambda x: x.get("item_id"), | ||
| # deep_get(results, "data.items"))) | ||
| # url = url_constructor("/o/v1/multi/get/content?ids=" + ids) | ||
|
|
@@ -74,8 +70,6 @@ def getTray(self, url, search_query=None): | |
|
|
||
| totalResults = deep_get( | ||
| results, "assets.totalResults") or results.get("totalResults") | ||
| offset = deep_get( | ||
| results, "assets.offset") or results.get("offset") | ||
| allResultsPageUrl = None | ||
| if len(items) > 0 and nextPageUrl is not None and ("/season/" in nextPageUrl or items[0].get("assetType") == "EPISODE") and totalResults is not None: | ||
| allResultsPageUrl = updateQueryParams(nextPageUrl, {"size": str( | ||
|
|
@@ -88,16 +82,24 @@ def getTray(self, url, search_query=None): | |
| return [], None, None | ||
|
|
||
| def getPlay(self, contentId, subtag, drm=False, lang=None, partner=None, ask=False): | ||
| url = url_constructor("/play/v1/playback/%scontent/%s" % | ||
| ('partner/' if partner is not None else '', contentId)) | ||
| encryption = "widevine" if drm else "plain" | ||
| # 'partner/' if partner is not None else '', | ||
| url = url_constructor("/play/v4/playback/content/%s" % (contentId)) | ||
| encryption = "widevine" # if drm else "plain" | ||
|
|
||
| """ | ||
| if partner: | ||
| resp = self.post(url, headers=self._getPlayHeaders(extra={"X-HS-Platform": "android"}), params=self._getPlayParams( | ||
| subtag, encryption), max_age=-1, json={"user_id": "", "partner_data": "x", "data": {"third_party_bundle": partner}}) | ||
| else: | ||
| resp = self.get(url, headers=self._getPlayHeaders( | ||
| ), params=self._getPlayParams(subtag, encryption), max_age=-1) | ||
| playBackSets = deep_get(resp, "data.playBackSets") | ||
| """ | ||
|
|
||
| data = '{"os_name":"Windows","os_version":"10","app_name":"web","app_version":"7.41.0","platform":"Chrome","platform_version":"106.0.0.0","client_capabilities":{"ads":["non_ssai"],"audio_channel":["stereo"],"dvr":["short"],"package":["dash","hls"],"dynamic_range":["sdr"],"video_codec":["h264"],"encryption":["widevine"],"ladder":["tv"],"container":["fmp4"],"resolution":["hd"]},"drm_parameters":{"widevine_security_level":["SW_SECURE_DECODE","SW_SECURE_CRYPTO"],"hdcp_version":["HDCP_NO_DIGITAL_OUTPUT"]},"resolution":"auto"}' | ||
| resp = self.post(url, headers=self._getPlayHeaders(includeST=True), params=self._getPlayParams( | ||
| subtag, encryption), max_age=-1, data=data) | ||
| playBackSets = deep_get(resp, "data.playback_sets") | ||
| # web_pdb.set_trace() | ||
| if playBackSets is None: | ||
| return None, None, None | ||
| playbackUrl, licenceUrl, playbackProto = HotstarAPI._findPlayback( | ||
|
|
@@ -116,35 +118,55 @@ def getExtItem(self, contentId): | |
| if item.get("clipType") == "LIVE": | ||
| item["encrypted"] = True | ||
| return "com.widevine.alpha" if item.get("encrypted") else False, item.get("isSubTagged") and "subs-tag:%s|" % item.get("features")[0].get("subType"), item.get("title") | ||
|
|
||
| def doLogin(self): | ||
| url = url_constructor( | ||
| "/in/aadhar/v2/firetv/in/users/logincode/") | ||
| resp = self.post(url, headers={"Content-Length": "0"}) | ||
| code = deep_get(resp, "description.code") | ||
| yield (code, 1) | ||
| for i in range(2, 101): | ||
| resp = self.get(url+code, max_age=-1) | ||
| Script.log(resp, lvl=Script.INFO) | ||
| token = deep_get(resp, "description.userIdentity") | ||
| token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ1bV9hY2Nlc3MiLCJleHAiOjE2NjYxNTI2NjQsImlhdCI6MTY2NTU0Nzg2NCwiaXNzIjoiVFMiLCJqdGkiOiI0OGQ1MTY1YThlZTU0MDU5YTJmODc1NzU1YzMwMDcwZiIsInN1YiI6IntcImhJZFwiOlwiMDg0ZjE4NjdmODVlNGYxMDkwODdlODc2YWI4ZWIyYWVcIixcInBJZFwiOlwiZGIxYzFlN2Q2NmFhNDg1ZDg4MzdiOGRhNzAzZWUwOWFcIixcIm5hbWVcIjpcIkd1ZXN0IFVzZXJcIixcImlwXCI6XCIxMDMuMTc3LjEzLjE0NlwiLFwiY291bnRyeUNvZGVcIjpcImluXCIsXCJjdXN0b21lclR5cGVcIjpcIm51XCIsXCJ0eXBlXCI6XCJndWVzdFwiLFwiaXNFbWFpbFZlcmlmaWVkXCI6ZmFsc2UsXCJpc1Bob25lVmVyaWZpZWRcIjpmYWxzZSxcImRldmljZUlkXCI6XCI5NTE5OWEwYi1jODVhLTQwNTUtYmE4MS1hZDcyNGUwNTk5MTNcIixcInByb2ZpbGVcIjpcIkFEVUxUXCIsXCJ2ZXJzaW9uXCI6XCJ2MlwiLFwic3Vic2NyaXB0aW9uc1wiOntcImluXCI6e319LFwiaXNzdWVkQXRcIjoxNjY1NTQ3ODY0Mzg3fSIsInZlcnNpb24iOiIxXzAifQ.J0LY0YaWYIz5S_V2cTB0xaIFy0wJnHIotpktQO3Nu70' | ||
| with PersistentDict("userdata.pickle") as db: | ||
| db.clear() | ||
| db["token"] = token | ||
| db.flush() | ||
|
|
||
| mobile = Dialog().numeric(0, "Enter 10 Digit mobile number") | ||
| url = url_constructor("/um/v3/users/084f1867f85e4f109087e876ab8eb2ae/register?register-by=phone_otp") | ||
|
|
||
| data = { | ||
| "phone_number": mobile, | ||
| "country_prefix": "91", | ||
| "device_meta": {"device_name": "Chrome Browser on Windows"} | ||
| } | ||
| data = json.dumps(data) | ||
| resp = self.put(url, headers=self._getPlayHeaders(includeST=True, includeUM=True, extra={"x-hs-device-id": self.device_id, "x-request-id": self.device_id}), data=data) | ||
|
|
||
| if deep_get(resp, "message") == 'User verification initiated': | ||
| OTP = Dialog().numeric(0, "Enter 4 Digit OTP") | ||
| url = url_constructor( | ||
| "/um/v3/users/login?login-by=phone_otp") | ||
|
|
||
| data = { | ||
| "phone_number": mobile, | ||
| "verification_code": OTP, | ||
| "device_meta": {"device_name": "Chrome Browser on Windows"} | ||
| } | ||
| data = json.dumps(data) | ||
| resp = self.put(url, headers=self._getPlayHeaders( | ||
| includeST=True, includeUM=False, extra={"x-hs-device-id": self.device_id}), data=data) | ||
| token = deep_get(resp, "user_identity") | ||
| if token: | ||
| with PersistentDict("userdata.pickle") as db: | ||
| db["token"] = token | ||
| db["deviceId"] = str(uuid4()) | ||
| db["deviceId"] = self.device_id | ||
| db["udata"] = json.loads(json.loads( | ||
| b64decode(token.split(".")[1]+"========")).get("sub")) | ||
| if db.get("isGuest"): | ||
| del db["isGuest"] | ||
| b64decode(token.split(".")[1] + "========")).get("sub")) | ||
| db.flush() | ||
| yield code, 100 | ||
| break | ||
| yield code, i | ||
| Script.notify("Login Success", "You are logged in") | ||
|
|
||
| def doLogout(self): | ||
| with PersistentDict("userdata.pickle") as db: | ||
| db.clear() | ||
| db.flush() | ||
|
|
||
| Script.notify("Logout Success", "You are logged out") | ||
| return | ||
|
|
||
| def get(self, url, **kwargs): | ||
| try: | ||
|
|
@@ -160,6 +182,13 @@ def post(self, url, **kwargs): | |
| except Exception as e: | ||
| return self._handleError(e, url, "post", **kwargs) | ||
|
|
||
| def put(self, url, **kwargs): | ||
| try: | ||
| response = self.session.put(url, **kwargs) | ||
| return response.json() | ||
| except Exception as e: | ||
| return self._handleError(e, url, "put", **kwargs) | ||
|
|
||
| def _handleError(self, e, url, _rtype, **kwargs): | ||
| if e.__class__.__name__ == "ValueError": | ||
| Script.log("Can not parse response of request url %s" % | ||
|
|
@@ -170,9 +199,9 @@ def _handleError(self, e, url, _rtype, **kwargs): | |
| with PersistentDict("userdata.pickle") as db: | ||
| if db.get("isGuest"): | ||
| Script.notify( | ||
| "Login Error", "Please login to watch this content") | ||
| executebuiltin( | ||
| "RunPlugin(plugin://plugin.video.botallen.hotstar/resources/lib/main/login/)") | ||
| "Subscription Error", "Please subscribe to watch this content") | ||
| # executebuiltin( | ||
| # "RunPlugin(plugin://plugin.video.botallen.hotstar/resources/lib/main/login/)") | ||
| else: | ||
| Script.notify( | ||
| "Subscription Error", "You don't have valid subscription to watch this content", display_time=2000) | ||
|
|
@@ -211,11 +240,11 @@ def _refreshToken(self): | |
| with PersistentDict("userdata.pickle") as db: | ||
| oldToken = db.get("token") | ||
| if oldToken: | ||
| resp = self.session.get(url_constructor("/in/aadhar/v2/firetv/in/users/refresh-token"), | ||
| headers={"userIdentity": oldToken, "deviceId": db.get("deviceId", str(uuid4()))}, raise_for_status=False, max_age=-1).json() | ||
| resp = self.session.get(url_constructor("/um/v3/users/refresh"), | ||
| headers=self._getPlayHeaders(includeST=True, includeUM=False, extra={"x-hs-device-id": self.device_id, "x-request-id": self.device_id}), raise_for_status=False, max_age=-1).json() | ||
| if resp.get("errorCode"): | ||
| return resp.get("message") | ||
| new_token = deep_get(resp, "description.userIdentity") | ||
| new_token = deep_get(resp, "user_identity") | ||
| db['token'] = new_token | ||
| db.flush() | ||
| return new_token | ||
|
|
@@ -224,49 +253,40 @@ def _refreshToken(self): | |
| return e | ||
|
|
||
| @staticmethod | ||
| def _getPlayHeaders(includeST=False, playbackUrl=None, extra={}): | ||
| def _getPlayHeaders(includeST=False, includeUM=False, playbackUrl=None, extra={}): | ||
| with PersistentDict("userdata.pickle") as db: | ||
| token = db.get("token") | ||
| auth = HotstarAPI._getAuth(includeST) | ||
| if not token: | ||
| token = guestToken() | ||
|
|
||
| auth = getAuth(includeST, False, includeUM) | ||
| headers = { | ||
| "hotstarauth": auth, | ||
| "X-Country-Code": "in", | ||
| "X-HS-AppVersion": "3.3.0", | ||
| "X-HS-Platform": "firetv", | ||
| "X-HS-UserToken": token, | ||
| "User-Agent": "Hotstar;in.startv.hotstar/3.3.0 (Android/8.1.0)", | ||
| "x-hs-platform": "web", | ||
| "x-hs-appversion": "7.41.0", | ||
| "content-type": "application/json", | ||
| "x-country-code": "IN", | ||
| "x-platform-code": "PCTV", | ||
| "x-hs-usertoken": token, | ||
| "x-hs-request-id": HotstarAPI.device_id, | ||
| "user-agent": "Hotstar;in.startv.hotstar/3.3.0 (Android/8.1.0)", | ||
| **extra, | ||
| } | ||
| if playbackUrl: | ||
| r = Request(playbackUrl) | ||
| r.add_header("User-Agent", headers.get("User-Agent")) | ||
| r.add_header("user-agent", headers.get("user-agent")) | ||
| cookie = urlopen(r).headers.get("Set-Cookie", "").split(";")[0] | ||
| if cookie: | ||
| headers["Cookie"] = cookie | ||
| return headers | ||
|
|
||
| @staticmethod | ||
| def _getAuth(includeST=False, persona=False): | ||
| _AKAMAI_ENCRYPTION_KEY = b'\x05\xfc\x1a\x01\xca\xc9\x4b\xc4\x12\xfc\x53\x12\x07\x75\xf9\xee' | ||
| if persona: | ||
| _AKAMAI_ENCRYPTION_KEY = b"\xa0\xaa\x8b\xcf\x9d\xd5\x8e\xc6\xe3\xb5\x7d\x9b\x4e\x5a\x00\x80\xb1\x45\x0d\xf7\x43\x6c\xfa\x22\xdd\x5c\xff\xdf\xea\x8e\x12\x52" | ||
| st = int(time.time()) | ||
| exp = st + 6000 | ||
| auth = 'st=%d~exp=%d~acl=/*' % (st, | ||
| exp) if includeST else 'exp=%d~acl=/*' % exp | ||
| auth += '~hmac=' + hmac.new(_AKAMAI_ENCRYPTION_KEY, | ||
| auth.encode(), hashlib.sha256).hexdigest() | ||
| return auth | ||
|
|
||
| @staticmethod | ||
| def _getPlayParams(subTag="", encryption="widevine"): | ||
| with PersistentDict("userdata.pickle") as db: | ||
| deviceId = db.get("deviceId", str(uuid4())) | ||
| deviceId = db.get("deviceId", HotstarAPI.device_id) | ||
| return { | ||
| "os-name": "firetv", | ||
| "desired-config": "audio_channel:stereo|encryption:%s|ladder:tv|package:dash|%svideo_codec:h264" % (encryption, subTag or ""), | ||
| "device-id": deviceId, | ||
| "os-version": "8.1.0" | ||
| "desired-config": "audio_channel:stereo|container:fmp4|dynamic_range:sdr|encryption:%s|ladder:tv|package:dash|resolution:fhd|%svideo_codec:h264" % (encryption, subTag or ""), | ||
| "device-id": deviceId | ||
| } | ||
|
|
||
| @staticmethod | ||
|
|
@@ -277,14 +297,14 @@ def _findPlayback(playBackSets, lang=None, ask=False): | |
| quality = {"4k": 0, "hd": 1, "sd": 2} | ||
| for each in playBackSets: | ||
| config = {k: v for d in map(lambda x: dict([x.split(":")]), each.get( | ||
| "tagsCombination", "a:b").split(";")) for k, v in d.items()} | ||
| "tags_combination", "a:b").split(";")) for k, v in d.items()} | ||
| Script.log( | ||
| f"Checking combination {config} with language {lang}", lvl=Script.DEBUG) | ||
| if config.get("encryption", "") in ["plain", "widevine"] and config.get("package", "") in ["hls", "dash"]: | ||
| if lang and config.get("language") and config.get("language", "") != lang: | ||
| continue | ||
| config["playback"] = (each.get("playbackUrl"), each.get( | ||
| "licenceUrl"), "mpd" if config.get("package") == "dash" else "hls") | ||
| config["playback"] = (each.get("playback_url"), each.get( | ||
| "licence_url"), "mpd" if config.get("package") == "dash" else "hls") | ||
| if selected is None: | ||
| selected = config["playback"] | ||
| if config.get("ladder"): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,14 +6,14 @@ | |
| import resources.lib.utils as U | ||
| from xbmcgui import DialogProgress | ||
| from xbmc import executebuiltin | ||
| import xbmc | ||
| from xbmcplugin import SORT_METHOD_EPISODE, SORT_METHOD_DATE | ||
| import time | ||
| import urlquick | ||
| from .api import HotstarAPI | ||
| from .builder import Builder | ||
| from .contants import BASE_HEADERS, CONTENT_TYPE | ||
|
|
||
|
|
||
| @Route.register | ||
| def root(plugin): | ||
| yield builder.buildSearch(Route.ref("/resources/lib/main:tray_list")) | ||
|
|
@@ -69,16 +69,7 @@ def play_ext(plugin, contentId, partner=None): | |
|
|
||
| @Script.register | ||
| def login(plugin): | ||
| msg = "1. Go to [B]https://tv.hotstar.com[/B]\n2. Login with your hotstar account[CR]3. Enter the 4 digit code : " | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this dialog is necessary for login.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous method of login using login code is no longer working. That's why I have removed this. Now, I have used OTP based method. |
||
| pdialog = DialogProgress() | ||
| pdialog.create("Login", msg+"Loading...") | ||
| for code, i in api.doLogin(): | ||
| if pdialog.iscanceled() or i == 100: | ||
| break | ||
| else: | ||
| time.sleep(1) | ||
| pdialog.update(i, msg+"[B][UPPERCASE]%s[/UPPERCASE][/B]" % code) | ||
| pdialog.close() | ||
| api.doLogin() | ||
|
|
||
|
|
||
| @Script.register | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is use of this dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required, just for debug purpose. I will remove it