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.
This commit is contained in:
parent
03b46c65a7
commit
64b86a1711
@ -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)
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -1,4 +1,4 @@
|
||||
req = json.loads(base64.b64decode(licBody.encode()).decode())
|
||||
req = loadBody("json")
|
||||
b64challenge = base64.b64encode(challenge).decode()
|
||||
req['message'] = b64challenge
|
||||
|
||||
|
@ -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()}
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user