From a40a6abaf76dea228c2aba8f9d2909b8910e6d9a Mon Sep 17 00:00:00 2001 From: voldemort <5692900+yell0wsuit@users.noreply.github.com> Date: Tue, 22 Jul 2025 09:56:05 +0700 Subject: [PATCH] extract DRM PSSH detection and storage into a separate function --- src/inject.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/inject.js b/src/inject.js index 0dbedd9..652b2a9 100644 --- a/src/inject.js +++ b/src/inject.js @@ -556,23 +556,32 @@ function ensureRemoteCDM(type, deviceInfo, pssh) { } } +function detectAndStorePssh(initData) { + const detections = [ + { + type: "PlayReady", + getter: getPlayReadyPssh, + store: (pssh) => (foundPlayreadyPssh = pssh), + }, + { type: "Widevine", getter: getWidevinePssh, store: (pssh) => (foundWidevinePssh = pssh) }, + ]; + + detections.forEach(({ type, getter, store }) => { + const pssh = getter(initData); + if (pssh) { + logWithPrefix(`[DRM Detected] ${type}`); + store(pssh); + logWithPrefix(`[${type} PSSH found] ${pssh}`); + } + }); +} + // Challenge generator interceptor const originalGenerateRequest = MediaKeySession.prototype.generateRequest; MediaKeySession.prototype.generateRequest = function (initDataType, initData) { const session = this; - let playReadyPssh = getPlayReadyPssh(initData); - if (playReadyPssh) { - logWithPrefix("[DRM Detected] PlayReady"); - foundPlayreadyPssh = playReadyPssh; - logWithPrefix("[PlayReady PSSH found] " + playReadyPssh); - } - let wideVinePssh = getWidevinePssh(initData); - if (wideVinePssh) { - // Widevine code - logWithPrefix("[DRM Detected] Widevine"); - foundWidevinePssh = wideVinePssh; - logWithPrefix("[Widevine PSSH found] " + wideVinePssh); - } + detectAndStorePssh(initData); + // Challenge message interceptor if (!remoteListenerMounted) { remoteListenerMounted = true;