From 79542387c472eb42341337ea00d9dfed9487ed0b Mon Sep 17 00:00:00 2001 From: Nicholas Frederiksen Date: Wed, 18 Dec 2024 17:26:14 +0100 Subject: [PATCH] fix: hls-interstitial start-date not placed correctly (#126) * fix: hls-interstitial start-date not placed correctly * update specs --- index.js | 7 ++++--- spec/hlsvod_spec.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1c75d52..1e6463e 100644 --- a/index.js +++ b/index.js @@ -2824,9 +2824,10 @@ class HLSVod { if (playlistItemWithInterstitialsMetadata(playlistItem)) { const newDateRange = playlistItem.attributes.attributes["daterange"]; - const newStartDate = new Date(newDateRange["START-DATE"]); - const tempTimeOffset = new Date(this.timeOffset); - const newStartDateString = new Date(newStartDate.getTime() + tempTimeOffset.getTime()).toISOString(); + const vodsInputTimestamp = new Date(this.timeOffset); + const extraDurationSec = i == 0 && q.duration ? 0 : q.duration; + const startTimeOffsetMs = (position + extraDurationSec) * 1000; + const newStartDateString = new Date(vodsInputTimestamp.getTime() + startTimeOffsetMs).toISOString(); newDateRange["START-DATE"] = newStartDateString; q["daterange"] = newDateRange; } diff --git a/spec/hlsvod_spec.js b/spec/hlsvod_spec.js index f884fe5..6887c9c 100644 --- a/spec/hlsvod_spec.js +++ b/spec/hlsvod_spec.js @@ -3809,5 +3809,35 @@ describe("HLSVod delta time and positions", () => { }); }); }); + + it("with Program date time enabled and VODs have HLS Interstitial Tag", (done) => { + mockVod = new HLSVod("http://mock.com/mock.m3u8", null, Date.now(), 0, null, { + sequenceAlwaysContainNewSegments: 0, + forcedDemuxMode: true, + }); + mockVod2 = new HLSVod("http://mock.com/mock2.m3u8", null, Date.now() + 90000, 0, null, { + sequenceAlwaysContainNewSegments: 0, + forcedDemuxMode: true, + }); + mockVod.load(mock_vod_3.master, mock_vod_3.media, mock_vod_3.audio).then(() => { + mockVod2.loadAfter(mockVod, mock_vod_3.master, mock_vod_3.media, mock_vod_3.audio).then(() => { + let m3u8 = mockVod2.getLiveMediaAudioSequences(0, "audio-aacl-256", "sv", 4); + let lines = m3u8.split("\n"); + expect( + lines[16].includes('#EXT-X-DATERANGE:ID="ad1",CLASS="com.apple.hls.interstitial",START-DATE') && + lines[16].includes( + ',DURATION="15.0",X-ASSET-URI="http://example.com/ad1.m3u8",X-RESUME-OFFSET="0",X-RESTRICT="SKIP,JUMP",X-COM-EXAMPLE-BEACON="123"' + ) + ).toBe(true); + expect( + lines[17].includes('#EXT-X-DATERANGE:ID="ad1",CLASS="com.apple.hls.interstitial",START-DATE') && + lines[16].includes( + ',DURATION="15.0",X-ASSET-URI="http://example.com/ad1.m3u8",X-RESUME-OFFSET="0",X-RESTRICT="SKIP,JUMP",X-COM-EXAMPLE-BEACON="123"' + ) + ).toBe(false); + done(); + }); + }); + }); }); });