Remove pssh.py and add PSSH generation to stream utils

This commit is contained in:
√(noham)²
2025-11-16 21:05:03 +01:00
parent aef746f4b9
commit 52e0d24d18
2 changed files with 23 additions and 9 deletions

View File

@@ -1,8 +0,0 @@
from uuid import UUID
from pywidevine.pssh import PSSH
data = "AAAAiHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAGgIARIQrKzUjhLvvbqkebbW2/EQtBIQWxKIsxtqP3iaIFYUu9f6xxIQXn4atxoopds39jbUXbiFVBIQUUJpv9uuzWKv4ccKTtooMRIQocf9FUFCoGm775zPIBr3HRoAKgAyADgASABQAA=="
pssh = PSSH(data)
pssh.set_key_ids([UUID("540103d1e13713f8ebdc90e468e6f97e"), UUID("acacd48e12efbdbaa479b6d6dbf110b4"), UUID("5b1288b31b6a3f789a205614bbd7fac7"), UUID("514269bfdbaecd62afe1c70a4eda2831"), UUID("a1c7fd154142a069bbef9ccf201af71d")])
print(pssh)

View File

@@ -5,10 +5,12 @@ import os
import asyncio
import time
from typing import Dict, Any
from uuid import UUID
import requests
from dotenv import load_dotenv
import aiohttp
from pywidevine.pssh import PSSH
load_dotenv()
@@ -33,6 +35,25 @@ def fetch_drm_keys(kid: str) -> str:
return response.json()["key"]
def generate_pssh(kid: str) -> str:
"""Generate a PSSH box for a given KID.
Args:
kid: The key identifier string.
Returns:
The PSSH box as a base64-encoded string.
"""
default_pssh = (
"AAAAiHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAGgIARIQrKzUjhLvvbqkebbW2/EQtBIQ"
"WxKIsxtqP3iaIFYUu9f6xxIQXn4atxoopds39jbUXbiFVBIQUUJpv9uuzWKv4ccKTtooMRIQ"
"ocf9FUFCoGm775zPIBr3HRoAKgAyADgASABQAA=="
)
pssh = PSSH(default_pssh)
pssh.set_key_ids([UUID(kid.replace("-", "").lower())])
return pssh.dumps()
def parse_mpd_manifest(mpd_content: str) -> Dict[str, Any]:
"""Parse an MPD manifest and extract metadata.
@@ -194,6 +215,7 @@ def parse_representation(
return rep_info
# pylint: disable=too-many-locals,too-many-branches
def organize_by_content_type(manifest_info: Dict[str, Any]) -> Dict[str, Any]:
"""Organize manifest information by content type.
@@ -232,7 +254,7 @@ def organize_by_content_type(manifest_info: Dict[str, Any]) -> Dict[str, Any]:
'drm_info': adaptation_set.get('drm_info', []),
'segments': rep.get('segments', {}),
}
if content_type == 'video':
width = rep.get('width')
height = rep.get('height')