50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
|
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: ")))
|