diff --git a/tests/core/test_cenc.py b/tests/core/test_cenc.py index 6e75afc1..54b5c5c0 100644 --- a/tests/core/test_cenc.py +++ b/tests/core/test_cenc.py @@ -15,9 +15,11 @@ from pywidevine.pssh import PSSH from tests.core.test_hls_kid_from_init import KEY_LINE, key_of, no_kid_pssh from tests.core.test_kid_windows import box, encv +from unshackle.core import binaries from unshackle.core.drm import PlayReady, Widevine, cenc from unshackle.core.drm.verify import PIFF_TENC from unshackle.core.tracks import Video +from unshackle.core.utils import subprocess as subprocess_utils TRACK_KID = UUID(int=0xA) OTHER_KID = UUID(int=0xB) @@ -59,6 +61,12 @@ def test_init_kid_prefers_the_ffprobe_kid(monkeypatch: pytest.MonkeyPatch) -> No assert cenc.init_kid(init(encv(TRACK_KID))) == OTHER_KID +def test_init_kid_reads_the_tenc_without_ffprobe(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(cenc, "ffprobe", subprocess_utils.ffprobe) + monkeypatch.setattr(binaries, "FFProbe", None) + assert cenc.init_kid(init(encv(TRACK_KID))) == TRACK_KID + + def test_init_kid_skips_a_clear_piff_tenc() -> None: clear = box(b"uuid", PIFF_TENC, bytes(8) + TRACK_KID.bytes) assert cenc.init_kid(init(clear, encv(OTHER_KID, piff=True))) == OTHER_KID diff --git a/unshackle/core/drm/cenc.py b/unshackle/core/drm/cenc.py index a3bc25ee..113cc850 100644 --- a/unshackle/core/drm/cenc.py +++ b/unshackle/core/drm/cenc.py @@ -78,9 +78,12 @@ def init_kid(init_data: bytes) -> UUID | None: A pssh box is no source, because it can name the KIDs of other renditions too. The PIFF box is read by offset, and only when its AlgorithmID is not 0 (clear): pymp4 parses it but cannot build it again, so - ``get_boxes`` raises on it. + ``get_boxes`` raises on it. Without FFprobe it starts at the tenc KID. """ - probe = ffprobe(init_data) + try: + probe = ffprobe(init_data) + except OSError: + probe = {} for stream in (probe or {}).get("streams") or []: enc_key_id = stream.get("tags", {}).get("enc_key_id") if enc_key_id: