commit fa49768b1a54d8455896c95cad8a3cc7b9374294 Author: TPD94 <> Date: Fri Nov 17 00:35:49 2023 -0500 Obtaining PSSH diff --git a/README.md b/README.md new file mode 100644 index 0000000..68e952b --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# Obtaining PSSH + + + +## Getting started + +4 methods to find PSSH: + +1) The simplest one: PSSH is clearly indicated in MPD file. Download MPD file (browser add-on "MPD Detector" will give you MPD link or filtering for `mpd` in the `network` tab of devoloper tools (ctrl + shift + c)), open it with Notepad, search for pssh value. + +2) If there is KID, but no PSSH in MPD, calculate PSSH by using KID: + +Using [this](https://tools.axinom.com/generators/PsshBox "this") website you can get the PSSH by entering in the `urn:uuid:` into the `System ID` field and entering the `cenc:default_KID=` into the `KEY IDs` field without the quotes `""` + +Eample: +![One:](example_one.png?raw=true "One") + +## Recommended method + +3) [EME Logger Script](https://greasyfork.org/en/scripts/373903-eme-logger "EME Logger Script") (installed on [Tampermonkey](https://www.tampermonkey.net/ "Tampermonkey") add-on) will give you init data. That's your PSSH. This can be found on Developer Tools (ctrl + shift + c) > Console, in the filter bar search for `MediaKeySession::generateRequest` you will find Init Data. + +**Optional, may be rquired:** + +If that Init Data is very very long, convert it to HEX: +https://base64.guru/converter/decode/hex + +Here's what mine looked like before conversion. +![Two:](example_two.png?raw=true "Two") + + +After Base64 > HEX conversion, you will find a Widevine-PSSH box, this can be found easily by searching with ctrl + f and searching for `70737368` + +PSSH header is always in a `000000xx70737368` where the `xx` is varied and can be from 1-9 in both x spots. + You always want to copy the 6 `0`'s before the xx as well. + +Example: +![Three:](example_three.png?raw=true "Three") + +The end of the header is always then followed by 8 more `0`s, if you see this, you are in the right place. + +Once you find the header start at the beginning 0 from the header and copy until the end of the converted hex, it should look like this + +Example: +![Four:](example_four.png?raw=true "Four") + +In this case the full value was `000000577073736800000000edef8ba979d64acea3c827dcd51d21ed0000003708011210162f7d326cf24f6dbd1319bc572bbc151a0b62757964726d6b65796f732210162f7d326cf24f6dbd1319bc572bbc152a024844` + +convert the hex back into base64 using +https://base64.guru/converter/encode/hex + +Example: +![Five:](example_five.png?raw=true "Five") + +In this case we got the PSSH value of `AAAAV3Bzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAADcIARIQFi99MmzyT229Exm8Vyu8FRoLYnV5ZHJta2V5b3MiEBYvfTJs8k9tvRMZvFcrvBUqAkhE` + +Congrats, you have the PSSH! + +4) Using init files + +You can use [this tool](https://cdm-project.com/CDM-Tools/Obtaining-PSSH/src/branch/main/get_pssh_from_init.py "this tool") to obtain the PSSH from an init file \ No newline at end of file diff --git a/example_five.png b/example_five.png new file mode 100644 index 0000000..48c0700 Binary files /dev/null and b/example_five.png differ diff --git a/example_four.png b/example_four.png new file mode 100644 index 0000000..03a136d Binary files /dev/null and b/example_four.png differ diff --git a/example_one.png b/example_one.png new file mode 100644 index 0000000..4412282 Binary files /dev/null and b/example_one.png differ diff --git a/example_three.png b/example_three.png new file mode 100644 index 0000000..9b79a2a Binary files /dev/null and b/example_three.png differ diff --git a/example_two.png b/example_two.png new file mode 100644 index 0000000..179477f Binary files /dev/null and b/example_two.png differ diff --git a/get_pssh_from_init.py b/get_pssh_from_init.py new file mode 100644 index 0000000..d1dd846 --- /dev/null +++ b/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!")