From 4e11f69a58634780564dca8a101690a74dda894f Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 17 Jan 2026 13:36:57 +0000 Subject: [PATCH] fix(drm): filter Widevine PSSH by system ID instead of sorting The previous sorting approach crashed with KeyError when unsupported DRM systems were present in the init segment. Now uses direct filtering --- unshackle/core/drm/widevine.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/unshackle/core/drm/widevine.py b/unshackle/core/drm/widevine.py index f4de4bc..6ca4fb5 100644 --- a/unshackle/core/drm/widevine.py +++ b/unshackle/core/drm/widevine.py @@ -100,9 +100,7 @@ class Widevine: pssh_boxes.extend(list(get_boxes(init_data, b"pssh"))) tenc_boxes.extend(list(get_boxes(init_data, b"tenc"))) - pssh_boxes.sort(key=lambda b: {PSSH.SystemId.Widevine: 0, PSSH.SystemId.PlayReady: 1}[b.system_ID]) - - pssh = next(iter(pssh_boxes), None) + pssh = next((b for b in pssh_boxes if b.system_ID == PSSH.SystemId.Widevine), None) if not pssh: raise Widevine.Exceptions.PSSHNotFound("PSSH was not found in track data.") @@ -141,9 +139,7 @@ class Widevine: if enc_key_id: kid = UUID(bytes=base64.b64decode(enc_key_id)) - pssh_boxes.sort(key=lambda b: {PSSH.SystemId.Widevine: 0, PSSH.SystemId.PlayReady: 1}[b.system_ID]) - - pssh = next(iter(pssh_boxes), None) + pssh = next((b for b in pssh_boxes if b.system_ID == PSSH.SystemId.Widevine), None) if not pssh: raise Widevine.Exceptions.PSSHNotFound("PSSH was not found in track data.")