From 64b86a17111e622e84445a2d5e0c0bb6f4c9c029 Mon Sep 17 00:00:00 2001 From: FoxRefire <155989196+FoxRefire@users.noreply.github.com> Date: Fri, 7 Jun 2024 04:03:37 +0900 Subject: [PATCH] Refactor: Define loadBody API for make scheme file more concise The loadBody() function allows more concise and intuitive loading of request bodies encoded in the scheme. --- python/pre.py | 12 ++++++++++++ python/schemes/Comcast.py | 2 +- python/schemes/GlobalTV.py | 2 +- python/schemes/Polsat.py | 2 +- python/schemes/RedBee.py | 2 +- python/schemes/VdoCipher.py | 2 +- python/schemes/Youku.py | 2 +- python/schemes/thePlatform.py | 2 +- 8 files changed, 19 insertions(+), 7 deletions(-) diff --git a/python/pre.py b/python/pre.py index b9ff9d2..e1848a9 100644 --- a/python/pre.py +++ b/python/pre.py @@ -63,6 +63,18 @@ async def corsFetch(url: str, method: str, headers: [dict, str], body: [dict, by return res +# Define loadBody API for loading requestBody to scheme concisely +def loadBody(loadAs: str): + global licBody + licBody = base64.b64decode(licBody.encode()) + + match loadAs: + case "blob": pass + case "str": licBody = licBody.decode() + case "json": licBody = json.loads(licBody.decode()) + + return licBody + # prepare pssh pssh = PSSH(pssh) diff --git a/python/schemes/Comcast.py b/python/schemes/Comcast.py index 547aff5..96d00a2 100644 --- a/python/schemes/Comcast.py +++ b/python/schemes/Comcast.py @@ -1,4 +1,4 @@ -req = json.loads(base64.b64decode(licBody.encode()).decode()) +req = loadBody("json") b64challenge = base64.b64encode(challenge).decode() req['licenseRequest'] = b64challenge res = await corsFetch(licUrl, "POST", licHeaders, req, "json") diff --git a/python/schemes/GlobalTV.py b/python/schemes/GlobalTV.py index ac12e55..116382d 100644 --- a/python/schemes/GlobalTV.py +++ b/python/schemes/GlobalTV.py @@ -1,4 +1,4 @@ -payload = json.loads(base64.b64decode(licBody.encode()).decode()) +payload = loadBody("json") challengeArr = list(challenge) payload['license_request_data']=challengeArr licence = await (await pyfetch(licUrl, diff --git a/python/schemes/Polsat.py b/python/schemes/Polsat.py index b98f8e4..ecf02b9 100644 --- a/python/schemes/Polsat.py +++ b/python/schemes/Polsat.py @@ -1,4 +1,4 @@ -payload = json.loads(base64.b64decode(licBody.encode()).decode()) +payload = loadBody("json") challengeB64 = base64.b64encode(challenge).decode() payload['params']['object'] = challengeB64 licence = await (await pyfetch(licUrl, diff --git a/python/schemes/RedBee.py b/python/schemes/RedBee.py index 9acdec9..46421e2 100644 --- a/python/schemes/RedBee.py +++ b/python/schemes/RedBee.py @@ -1,4 +1,4 @@ -req = json.loads(base64.b64decode(licBody.encode()).decode()) +req = loadBody("json") b64challenge = base64.b64encode(challenge).decode() req['message'] = b64challenge diff --git a/python/schemes/VdoCipher.py b/python/schemes/VdoCipher.py index e4bf989..49a61cf 100644 --- a/python/schemes/VdoCipher.py +++ b/python/schemes/VdoCipher.py @@ -1,6 +1,6 @@ b64challenge = base64.b64encode(challenge).decode() -payload = json.loads(base64.b64decode(licBody.encode()).decode()) +payload = loadBody("json") decoded_token = json.loads(base64.b64decode(payload['token']).decode()) decoded_token['licenseRequest'] = b64challenge payload = {"token": base64.b64encode(json.dumps(decoded_token).encode()).decode()} diff --git a/python/schemes/Youku.py b/python/schemes/Youku.py index 90e494d..e91bb96 100644 --- a/python/schemes/Youku.py +++ b/python/schemes/Youku.py @@ -1,5 +1,5 @@ import urllib.parse -payload = urllib.parse.parse_qs(base64.b64decode(licBody.encode()).decode()) +payload = urllib.parse.parse_qs(loadBody("str")) challengeB64 = base64.b64encode(challenge).decode() payload['licenseRequest'] = challengeB64 payload = urllib.parse.urlencode(payload) diff --git a/python/schemes/thePlatform.py b/python/schemes/thePlatform.py index 855ca1b..8b45ab5 100644 --- a/python/schemes/thePlatform.py +++ b/python/schemes/thePlatform.py @@ -1,4 +1,4 @@ -payload = json.loads(base64.b64decode(licBody.encode()).decode()) +payload = loadBody("json") b64challenge = base64.b64encode(challenge).decode() payload["getWidevineLicense"]["widevineChallenge"]=b64challenge res = await (await pyfetch(licUrl,