From 5c56da872a4ca887e74b766ba03b3de0645f4492 Mon Sep 17 00:00:00 2001 From: FoxRefire <155989196+FoxRefire@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:02:48 +0900 Subject: [PATCH] Refactor: Use corsFetch for all schemes Currently corsFetch is very stable and does not need to be used differently from pyfetch depending on whether the license server values the Origin header. Nested await is no longer necessary and the code is more concise. It is expected to be less confusing for debugging and for people creating new schemes. --- python/schemes/DRMToday.py | 7 ++----- python/schemes/GlobalTV.py | 7 ++----- python/schemes/NosTV.py | 7 ++----- python/schemes/Polsat.py | 9 +++------ python/schemes/thePlatform.py | 7 ++----- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/python/schemes/DRMToday.py b/python/schemes/DRMToday.py index e99d6cb..3cf5675 100644 --- a/python/schemes/DRMToday.py +++ b/python/schemes/DRMToday.py @@ -1,7 +1,4 @@ -res = await (await pyfetch(licUrl, - method="POST", - headers=licHeaders, - body=challenge -)).json() +res = await corsFetch(licUrl, "POST", licHeaders, challenge, "json") + licence = res['license'] diff --git a/python/schemes/GlobalTV.py b/python/schemes/GlobalTV.py index 116382d..4497794 100644 --- a/python/schemes/GlobalTV.py +++ b/python/schemes/GlobalTV.py @@ -1,8 +1,5 @@ payload = loadBody("json") challengeArr = list(challenge) payload['license_request_data']=challengeArr -licence = await (await pyfetch(licUrl, - method="POST", - headers=licHeaders, - body=json.dumps(payload) -)).bytes() + +licence = await corsFetch(licUrl, "POST", licHeaders, payload, "blob") diff --git a/python/schemes/NosTV.py b/python/schemes/NosTV.py index 1ef2b5b..7a354d6 100644 --- a/python/schemes/NosTV.py +++ b/python/schemes/NosTV.py @@ -1,7 +1,4 @@ b64challenge = base64.b64encode(challenge).decode() -res = await (await pyfetch(licUrl, - method="POST", - headers=licHeaders, - body=json.dumps({"challenge": b64challenge}) -)).json() +res = await corsFetch(licUrl, "POST", licHeaders, {"challenge": b64challenge}, "json") + licence = res["license"][0] diff --git a/python/schemes/Polsat.py b/python/schemes/Polsat.py index ecf02b9..cdadc05 100644 --- a/python/schemes/Polsat.py +++ b/python/schemes/Polsat.py @@ -1,9 +1,6 @@ payload = loadBody("json") challengeB64 = base64.b64encode(challenge).decode() payload['params']['object'] = challengeB64 -licence = await (await pyfetch(licUrl, - method="POST", - headers=licHeaders, - body=json.dumps(payload) -)).json() -licence = licence['result']['object']['license'] +res = await corsFetch(licUrl, "POST", licHeaders, payload, "json") + +licence = res['result']['object']['license'] diff --git a/python/schemes/thePlatform.py b/python/schemes/thePlatform.py index 8b45ab5..1c6a8cf 100644 --- a/python/schemes/thePlatform.py +++ b/python/schemes/thePlatform.py @@ -1,9 +1,6 @@ payload = loadBody("json") b64challenge = base64.b64encode(challenge).decode() payload["getWidevineLicense"]["widevineChallenge"]=b64challenge -res = await (await pyfetch(licUrl, - method="POST", - headers=licHeaders, - body=json.dumps(payload) -)).json() +res = await corsFetch(licUrl, "POST", licHeaders, payload, "json") + licence = res["getWidevineLicenseResponse"]["license"]