Updated
This commit is contained in:
0
pywidevine/decrypt/__init__.py
Normal file
0
pywidevine/decrypt/__init__.py
Normal file
BIN
pywidevine/decrypt/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/__init__.cpython-38.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/__init__.cpython-38.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/wvdecrypt.cpython-36.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/wvdecrypt.cpython-36.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/wvdecrypt.cpython-37.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/wvdecrypt.cpython-37.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/wvdecrypt.cpython-38.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/wvdecrypt.cpython-38.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/wvdecrypt.cpython-39.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/wvdecrypt.cpython-39.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/wvdecryptconfig.cpython-36.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/wvdecryptconfig.cpython-36.pyc
Normal file
Binary file not shown.
BIN
pywidevine/decrypt/__pycache__/wvdecryptconfig.cpython-37.pyc
Normal file
BIN
pywidevine/decrypt/__pycache__/wvdecryptconfig.cpython-37.pyc
Normal file
Binary file not shown.
46
pywidevine/decrypt/wvdecrypt.py
Normal file
46
pywidevine/decrypt/wvdecrypt.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import logging
|
||||
import subprocess
|
||||
import re
|
||||
from tqdm import tqdm
|
||||
import base64
|
||||
from pywidevine.cdm import cdm, deviceconfig
|
||||
|
||||
class WvDecrypt(object):
|
||||
|
||||
WV_SYSTEM_ID = [237, 239, 139, 169, 121, 214, 74, 206, 163, 200, 39, 220, 213, 29, 33, 237]
|
||||
|
||||
def __init__(self, PSSH):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.wvdecrypt_process = None
|
||||
self.pssh = PSSH
|
||||
self.cdm = cdm.Cdm()
|
||||
|
||||
def check_pssh(pssh_b64):
|
||||
pssh = base64.b64decode(pssh_b64)
|
||||
if not pssh[12:28] == bytes(self.WV_SYSTEM_ID):
|
||||
new_pssh = bytearray([0,0,0])
|
||||
new_pssh.append(32+len(pssh))
|
||||
new_pssh[4:] = bytearray(b'pssh')
|
||||
new_pssh[8:] = [0,0,0,0]
|
||||
new_pssh[13:] = self.WV_SYSTEM_ID
|
||||
new_pssh[29:] = [0,0,0,0]
|
||||
new_pssh[31] = len(pssh)
|
||||
new_pssh[32:] = pssh
|
||||
return base64.b64encode(new_pssh)
|
||||
else:
|
||||
return pssh_b64
|
||||
|
||||
self.session = self.cdm.open_session(check_pssh(self.pssh),
|
||||
deviceconfig.DeviceConfig(deviceconfig.device_chromecdm_1610))
|
||||
|
||||
def start_process(self):
|
||||
keysR = self.cdm.get_keys(self.session)
|
||||
return keysR
|
||||
|
||||
def get_challenge(self):
|
||||
return self.cdm.get_license_request(self.session)
|
||||
|
||||
def update_license(self, license_b64):
|
||||
self.cdm.provide_license(self.session, license_b64)
|
||||
return True
|
||||
|
||||
57
pywidevine/decrypt/wvdecryptconfig.py
Normal file
57
pywidevine/decrypt/wvdecryptconfig.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import pywidevine.downloader.wvdownloaderconfig as wvdl_cfg
|
||||
import subprocess
|
||||
|
||||
class WvDecryptConfig(object):
|
||||
def __init__(self, filename, tracktype, trackno, license, init_data_b64, cert_data_b64=None):
|
||||
self.filename = filename
|
||||
self.tracktype = tracktype
|
||||
self.trackno = trackno
|
||||
self.init_data_b64 = init_data_b64
|
||||
self.license = license
|
||||
if cert_data_b64 is not None:
|
||||
self.server_cert_required = True
|
||||
self.cert_data_b64 = cert_data_b64
|
||||
else:
|
||||
self.server_cert_required = False
|
||||
|
||||
def get_filename(self, unformatted_filename):
|
||||
return unformatted_filename.format(filename=self.filename, track_type=self.tracktype, track_no=self.trackno)
|
||||
|
||||
|
||||
def find_str(self, s, char):
|
||||
index = 0
|
||||
if char in s:
|
||||
c = char[0]
|
||||
for ch in s:
|
||||
if ch == c and s[index:index + len(char)] == char:
|
||||
return index
|
||||
index += 1
|
||||
return -1
|
||||
|
||||
def get_kid(self, filename):
|
||||
mp4dump = subprocess.Popen([wvdl_cfg.MP4DUMP_BINARY_PATH, filename], stdout=subprocess.PIPE)
|
||||
mp4dump = str(mp4dump.stdout.read())
|
||||
A = self.find_str(mp4dump, 'default_KID')
|
||||
KID = mp4dump[A:A + 63].replace('default_KID = ', '').replace('[', '').replace(']', '').replace(' ', '')
|
||||
KID = KID.upper()
|
||||
KID_video = KID[0:8] + '-' + KID[8:12] + '-' + KID[12:16] + '-' + KID[16:20] + '-' + KID[20:32]
|
||||
if KID == '':
|
||||
KID = 'nothing'
|
||||
return KID.lower()
|
||||
|
||||
def build_commandline_list(self, keys):
|
||||
|
||||
KID_file = self.get_kid(self.get_filename(wvdl_cfg.ENCRYPTED_FILENAME))
|
||||
print(KID_file)
|
||||
|
||||
commandline = [wvdl_cfg.MP4DECRYPT_BINARY_PATH]
|
||||
for key in keys:
|
||||
if key.type == 'CONTENT' and key.kid.hex() == KID_file:
|
||||
print("OK")
|
||||
commandline.append('--key')
|
||||
#key.kid.hex()
|
||||
#2 main high 1 hdr dv hevc
|
||||
commandline.append('{}:{}'.format('2', key.key.hex()))
|
||||
commandline.append(self.get_filename(wvdl_cfg.ENCRYPTED_FILENAME))
|
||||
commandline.append(self.get_filename(wvdl_cfg.DECRYPTED_FILENAME))
|
||||
return commandline
|
||||
Reference in New Issue
Block a user