mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 20:45:11 +00:00
fix(drm): read the init segment tenc KID when FFprobe is not installed
This commit is contained in:
@@ -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_hls_kid_from_init import KEY_LINE, key_of, no_kid_pssh
|
||||||
from tests.core.test_kid_windows import box, encv
|
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 import PlayReady, Widevine, cenc
|
||||||
from unshackle.core.drm.verify import PIFF_TENC
|
from unshackle.core.drm.verify import PIFF_TENC
|
||||||
from unshackle.core.tracks import Video
|
from unshackle.core.tracks import Video
|
||||||
|
from unshackle.core.utils import subprocess as subprocess_utils
|
||||||
|
|
||||||
TRACK_KID = UUID(int=0xA)
|
TRACK_KID = UUID(int=0xA)
|
||||||
OTHER_KID = UUID(int=0xB)
|
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
|
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:
|
def test_init_kid_skips_a_clear_piff_tenc() -> None:
|
||||||
clear = box(b"uuid", PIFF_TENC, bytes(8) + TRACK_KID.bytes)
|
clear = box(b"uuid", PIFF_TENC, bytes(8) + TRACK_KID.bytes)
|
||||||
assert cenc.init_kid(init(clear, encv(OTHER_KID, piff=True))) == OTHER_KID
|
assert cenc.init_kid(init(clear, encv(OTHER_KID, piff=True))) == OTHER_KID
|
||||||
|
|||||||
@@ -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
|
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
|
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 []:
|
for stream in (probe or {}).get("streams") or []:
|
||||||
enc_key_id = stream.get("tags", {}).get("enc_key_id")
|
enc_key_id = stream.get("tags", {}).get("enc_key_id")
|
||||||
if enc_key_id:
|
if enc_key_id:
|
||||||
|
|||||||
Reference in New Issue
Block a user