From 927083d04d5cecd87b26cb0558507f1b03398de5 Mon Sep 17 00:00:00 2001 From: CDM-Project Date: Sun, 8 Sep 2024 20:33:04 -0400 Subject: [PATCH] Create from_init.py --- from_init.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 from_init.py diff --git a/from_init.py b/from_init.py new file mode 100644 index 0000000..d468cf7 --- /dev/null +++ b/from_init.py @@ -0,0 +1,50 @@ +import base64 +import subprocess +from pathlib import Path +import os + +def find_wv_pssh_offsets(raw: bytes) -> list: + offsets = [] + offset = 0 + while True: + offset = raw.find(b'pssh', offset) + if offset == -1: + break + size = int.from_bytes(raw[offset-4:offset], byteorder='big') + pssh_offset = offset - 4 + offsets.append(raw[pssh_offset:pssh_offset+size]) + offset += size + return offsets + +def to_pssh(content: bytes) -> list: + wv_offsets = find_wv_pssh_offsets(content) + return [base64.b64encode(wv_offset).decode() for wv_offset in wv_offsets] + +def from_file(file_path: str) -> list: + return to_pssh(Path(file_path).read_bytes()) + +def get_pssh(mpd_link): + + # Define yt-dlp download parameters + yt_dlp_download = [ + f'{os.getcwd()}/yt-dlp.exe', + '-f', + 'bv', + '--allow-u', + '-o', + f'{os.getcwd()}/init.mp4', + '--test', + f'{mpd_link}' + ] + + subprocess.run(yt_dlp_download, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + pssh_list = from_file(f'{os.getcwd()}/init.mp4') + target_pssh = None + for pssh in pssh_list: + if 70 < len(pssh) < 190: + target_pssh = pssh + os.remove(path=f'{os.getcwd()}/init.mp4') + return target_pssh + +print(get_pssh(input("MPD LINK: "))) \ No newline at end of file