Refactor: Avoid using nested try-except block
As nesting try-excepts makes readability worst.
This commit is contained in:
parent
1bcc6ca855
commit
4b60bb6432
@ -7,37 +7,40 @@ import js
|
|||||||
import base64
|
import base64
|
||||||
from pyodide.http import pyfetch
|
from pyodide.http import pyfetch
|
||||||
|
|
||||||
# prepare pssh
|
def blobsToDevice(cID, pKey):
|
||||||
pssh = PSSH(pssh)
|
return Device(client_id=cID, private_key=pKey, type_=DeviceTypes['ANDROID'], security_level=3, flags=None)
|
||||||
|
|
||||||
# load device
|
async def loadCdm():
|
||||||
|
# Looking for device.wvd
|
||||||
try:
|
try:
|
||||||
wvd = await (await pyfetch("device.wvd")).bytes()
|
wvd = await (await pyfetch("device.wvd")).bytes()
|
||||||
device = Device.loads(wvd)
|
return Cdm.from_device(Device.loads(wvd))
|
||||||
except Exception:
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Looking for device_client_id_blob + device_private_key
|
||||||
try:
|
try:
|
||||||
print("device.wvd not found! looking for device_client_id_blob and device_private_key...")
|
|
||||||
cID=await (await pyfetch("device_client_id_blob")).bytes()
|
cID=await (await pyfetch("device_client_id_blob")).bytes()
|
||||||
pKey=await (await pyfetch("device_private_key")).bytes()
|
pKey=await (await pyfetch("device_private_key")).bytes()
|
||||||
|
return Cdm.from_device(blobsToDevice(cID, pKey))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
except Exception:
|
# Looking for client_id.bin + private_key.pem
|
||||||
try:
|
try:
|
||||||
print("device_client_id_blob and device_private_key not found! looking for client_id.bin and private_key.pem...")
|
|
||||||
cID=await (await pyfetch("client_id.bin")).bytes()
|
cID=await (await pyfetch("client_id.bin")).bytes()
|
||||||
pKey=await (await pyfetch("private_key.pem")).bytes()
|
pKey=await (await pyfetch("private_key.pem")).bytes()
|
||||||
|
return Cdm.from_device(blobsToDevice(cID, pKey))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
js.document.getElementById('result').value="n0suchd3v1c3f113:r3adth3fuck1ngma2ua1\n\n[MPD?]\nhttps://github.com/FoxRefire/wvg?tab=readme-ov-file#instalation"
|
js.document.getElementById('result').value="n0suchd3v1c3f113:r3adth3fuck1ngma2ua1\n\n[MPD?]\nhttps://github.com/FoxRefire/wvg?tab=readme-ov-file#instalation"
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
device = Device(client_id=cID,
|
|
||||||
private_key=pKey,
|
# prepare pssh
|
||||||
type_=DeviceTypes['ANDROID'],
|
pssh = PSSH(pssh)
|
||||||
security_level=3,
|
|
||||||
flags=None)
|
|
||||||
|
|
||||||
# load cdm
|
# load cdm
|
||||||
cdm = Cdm.from_device(device)
|
cdm = await loadCdm()
|
||||||
|
|
||||||
# open cdm session
|
# open cdm session
|
||||||
session_id = cdm.open()
|
session_id = cdm.open()
|
||||||
|
Loading…
Reference in New Issue
Block a user