From cc8a7a95e9017c900843ba01ae8f5e2ca8a4a3ad Mon Sep 17 00:00:00 2001 From: Apocalypse Date: Tue, 4 Jul 2023 16:58:55 +0300 Subject: [PATCH] Add 'tools/get_pssh_from_init.py' --- tools/get_pssh_from_init.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tools/get_pssh_from_init.py diff --git a/tools/get_pssh_from_init.py b/tools/get_pssh_from_init.py new file mode 100644 index 0000000..8c6ff36 --- /dev/null +++ b/tools/get_pssh_from_init.py @@ -0,0 +1,29 @@ +import base64 + +import requests +import xmltodict + + +def read_pssh_from_bytes(bytes: bytes): + pssh_offset = bytes.rfind(b"pssh") + _start = pssh_offset - 4 + _end = pssh_offset - 4 + bytes[pssh_offset - 1] + pssh = bytes[_start:_end] + return pssh + + +url = input("Enter Init segment url: ") +headers = { + # "Range": "bytes=0-962", +} +print("Downloading...") + +res = requests.get(url, headers=headers) +if not res.ok: + print(f"Could not download init segment: {res.text}") + +pssh = read_pssh_from_bytes(res.content) +if pssh is not None: + print(f"PSSH: {base64.b64encode(pssh).decode('utf8')}") +else: + print("Failed to extract PSSH!") \ No newline at end of file