From 8fdef558930cb266b5ce285bac28eb0921adc88c Mon Sep 17 00:00:00 2001 From: Vitaly Gashkov Date: Tue, 26 Mar 2024 21:31:16 +0500 Subject: [PATCH] fix: parse fairplay protection correctly --- lib/hls.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/hls.js b/lib/hls.js index 3b28925..83b4dec 100644 --- a/lib/hls.js +++ b/lib/hls.js @@ -91,13 +91,16 @@ const fetchTrackSegments = (tracks) => { tracks.map(async (track) => { const playlist = await fetchPlaylist(track.url); track.segments = segmentsDto(playlist.segments); - if (playlist.contentProtection) track.protection = {}; - if (playlist.contentProtection['com.apple.fps.1_0']) - track.protection.fairplay = { - keyFormat: data.contentProtection['com.apple.fps.1_0'].attributes.KEYFORMAT, - uri: data.contentProtection['com.apple.fps.1_0'].attributes.URI, - method: data.contentProtection['com.apple.fps.1_0'].attributes.METHOD, - }; + if (playlist.contentProtection) { + track.protection = {}; + const fairplayLegacy = playlist.contentProtection['com.apple.fps.1_0']; + if (fairplayLegacy) + track.protection.fairplay = { + keyFormat: fairplayLegacy.attributes.KEYFORMAT, + uri: fairplayLegacy.attributes.URI, + method: fairplayLegacy.attributes.METHOD, + }; + } }) ); }; @@ -108,11 +111,11 @@ const parseManifest = async (manifestString, manifestUri) => { const audios = getAudioPlaylists(m3u8, manifestUri); const subtitles = getSubtitlePlaylists(m3u8, manifestUri); - await Promise.all( + await Promise.all([ fetchTrackSegments(videos), fetchTrackSegments(audios), - fetchTrackSegments(subtitles) - ); + fetchTrackSegments(subtitles), + ]); const manifest = { tracks: {