Skip to content

Commit

Permalink
fix: revert special placement for interstitial tag with cues
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfrederiksen committed Nov 28, 2024
1 parent 15de600 commit 603ef5f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 82 deletions.
69 changes: 17 additions & 52 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,10 @@ class HLSSpliceVod {

_insertInterstitialAtExtraMedia(offset, id, uri, isAssetList, extraAttrs, startDate, playlists, opts) {

let HAS_CUE_ATTR = false;
if (opts && opts.cue) {
const cueValue = _parseValidCueValues(opts.cue);
if (cueValue) {
extraAttrs += `,CUE="${cueValue}"`;
HAS_CUE_ATTR = true;
}
}

Expand All @@ -508,37 +506,22 @@ class HLSSpliceVod {
idx++;
}
}
if (HAS_CUE_ATTR) {
pos = playlist.items.PlaylistItem.length - 1;
}

let durationTag = "";
if (opts && opts.plannedDuration) {
durationTag = `,DURATION=${opts.plannedDuration / 1000}`;
}

if (HAS_CUE_ATTR) {
if (isAssetList) {
playlist.addPlaylistItem({
daterange: `ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},X-ASSET-LIST="${uri}"${extraAttrs}`,
});
} else {
playlist.addPlaylistItem({
daterange: `ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},X-ASSET-URI="${uri}"${extraAttrs}`,
});
}
let xAssetAttributeKey;
if (isAssetList) {
xAssetAttributeKey = "X-ASSET-LIST";
} else {
if (isAssetList) {
playlist.items.PlaylistItem[idx].set(
"daterange",
`ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},X-ASSET-LIST="${uri}"${extraAttrs}`
);
} else {
playlist.items.PlaylistItem[idx].set(
"daterange",
`ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},X-ASSET-URI="${uri}"${extraAttrs}`
);
}
xAssetAttributeKey = "X-ASSET-URI";
}
playlist.items.PlaylistItem[idx].set(
"daterange",
`ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},${xAssetAttributeKey}="${uri}"${extraAttrs}`
);
}
}
}
Expand All @@ -554,7 +537,6 @@ class HLSSpliceVod {
custombeacon: undefined,
cue: undefined,
}) {
let HAS_CUE_ATTR = false;

return new Promise((resolve, reject) => {
if (this.bumperDuration) {
Expand All @@ -568,7 +550,6 @@ class HLSSpliceVod {
const cueValue = _parseValidCueValues(opts.cue);
if (cueValue) {
extraAttrs += `,CUE="${cueValue}"`;
HAS_CUE_ATTR = true;
}
}

Expand Down Expand Up @@ -623,38 +604,22 @@ class HLSSpliceVod {
}
}

if (HAS_CUE_ATTR) {
pos = playlistSize - 1;
}

startDate = new Date(1 + Number(offset)).toISOString();
let durationTag = "";
if (opts && opts.plannedDuration) {
durationTag = `,DURATION=${opts.plannedDuration / 1000}`;
}

let xAssetAttributeKey;
if (isAssetList) {
if (HAS_CUE_ATTR) {
this.playlists[bw].addPlaylistItem({
daterange: `ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},X-ASSET-LIST="${uri}"${extraAttrs}`,
});
} else {
this.playlists[bw].items.PlaylistItem[i].set(
"daterange",
`ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},X-ASSET-LIST="${uri}"${extraAttrs}`
);
}
xAssetAttributeKey = "X-ASSET-LIST";
} else {
if (HAS_CUE_ATTR) {
this.playlists[bw].addPlaylistItem({
daterange: `ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},X-ASSET-URI="${uri}"${extraAttrs}`,
});
} else {
this.playlists[bw].items.PlaylistItem[i].set(
"daterange",
`ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},X-ASSET-URI="${uri}"${extraAttrs}`
);
}
xAssetAttributeKey = "X-ASSET-URI";
}
this.playlists[bw].items.PlaylistItem[i].set(
"daterange",
`ID=${id},CLASS="com.apple.hls.interstitial",START-DATE="${startDate}"${durationTag},${xAssetAttributeKey}="${uri}"${extraAttrs}`
);
}

this._insertInterstitialAtExtraMedia(offset, id, uri, isAssetList, extraAttrs, startDate, this.playlistsAudio, opts);
Expand Down
60 changes: 30 additions & 30 deletions spec/hls_splice_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,16 @@ describe("HLSSpliceVod", () => {
mockVod
.load(mockMasterManifest, mockMediaManifest)
.then(() => {
return mockVod.insertInterstitialAt(18000, "001", "http://mock.com/asseturi", false, {
return mockVod.insertInterstitialAt(0, "001", "http://mock.com/asseturi", false, {
resumeOffset: 10500,
cue: "PRE,ONCE",
});
})
.then(() => {
const m3u8 = mockVod.getMediaManifest(4497000);
const lines = m3u8.split("\n");
expect(lines[29]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="PRE,ONCE",X-RESUME-OFFSET=10.5'
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="PRE,ONCE",X-RESUME-OFFSET=10.5'
);
done();
});
Expand All @@ -528,16 +528,16 @@ describe("HLSSpliceVod", () => {
mockVod
.load(mockMasterManifest, mockMediaManifest)
.then(() => {
return mockVod.insertInterstitialAt(18000, "001", "http://mock.com/asseturi", false, {
return mockVod.insertInterstitialAt(0, "001", "http://mock.com/asseturi", false, {
resumeOffset: 10500,
cue: "pre-once",
});
})
.then(() => {
const m3u8 = mockVod.getMediaManifest(4497000);
const lines = m3u8.split("\n");
expect(lines[12]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",X-RESUME-OFFSET=10.5'
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",X-RESUME-OFFSET=10.5'
);
done();
});
Expand All @@ -548,16 +548,16 @@ describe("HLSSpliceVod", () => {
mockVod
.load(mockMasterManifest, mockMediaManifest)
.then(() => {
return mockVod.insertInterstitialAt(18000, "001", "http://mock.com/asseturi", false, {
return mockVod.insertInterstitialAt(0, "001", "http://mock.com/asseturi", false, {
resumeOffset: 10500,
cue: "POST",
});
})
.then(() => {
const m3u8 = mockVod.getMediaManifest(4497000);
const lines = m3u8.split("\n");
expect(lines[29]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST",X-RESUME-OFFSET=10.5'
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST",X-RESUME-OFFSET=10.5'
);
done();
});
Expand Down Expand Up @@ -1528,21 +1528,21 @@ describe("HLSSpliceVod with Demuxed Audio Tracks,", () => {
mockVod
.load(mockMasterManifest, mockMediaManifest, mockAudioManifest)
.then(() => {
return mockVod.insertInterstitialAt(18000, "001", "http://mock.com/asseturi", false, {
return mockVod.insertInterstitialAt(0, "001", "http://mock.com/asseturi", false, {
resumeOffset: 10500,
cue: "PRE,ONCE",
});
})
.then(() => {
const m3u8 = mockVod.getMediaManifest(4497000);
let lines = m3u8.split("\n");
expect(lines[29]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="PRE,ONCE",X-RESUME-OFFSET=10.5'
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="PRE,ONCE",X-RESUME-OFFSET=10.5'
);
const m3u8Audio = mockVod.getAudioManifest("stereo", "sv");
lines = m3u8Audio.split("\n");
expect(lines[29]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="PRE,ONCE",X-RESUME-OFFSET=10.5'
lines = m3u8Audio.split("\n");
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="PRE,ONCE",X-RESUME-OFFSET=10.5'
);
done();
});
Expand All @@ -1553,21 +1553,21 @@ describe("HLSSpliceVod with Demuxed Audio Tracks,", () => {
mockVod
.load(mockMasterManifest, mockMediaManifest, mockAudioManifest)
.then(() => {
return mockVod.insertInterstitialAt(18000, "001", "http://mock.com/asseturi", false, {
return mockVod.insertInterstitialAt(0, "001", "http://mock.com/asseturi", false, {
resumeOffset: 10500,
cue: "ROST,TWICE",
});
})
.then(() => {
const m3u8 = mockVod.getMediaManifest(4497000);
let lines = m3u8.split("\n");
expect(lines[12]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",X-RESUME-OFFSET=10.5'
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",X-RESUME-OFFSET=10.5'
);
const m3u8Audio = mockVod.getAudioManifest("stereo", "sv");
lines = m3u8Audio.split("\n");
expect(lines[12]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",X-RESUME-OFFSET=10.5'
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",X-RESUME-OFFSET=10.5'
);
done();
});
Expand All @@ -1578,21 +1578,21 @@ describe("HLSSpliceVod with Demuxed Audio Tracks,", () => {
mockVod
.load(mockMasterManifest, mockMediaManifest, mockAudioManifest)
.then(() => {
return mockVod.insertInterstitialAt(18000, "001", "http://mock.com/asseturi", false, {
return mockVod.insertInterstitialAt(0, "001", "http://mock.com/asseturi", false, {
resumeOffset: 10500,
cue: "POST,THRICE",
});
})
.then(() => {
const m3u8 = mockVod.getMediaManifest(4497000);
let lines = m3u8.split("\n");
expect(lines[29]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST",X-RESUME-OFFSET=10.5'
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST",X-RESUME-OFFSET=10.5'
);
const m3u8Audio = mockVod.getAudioManifest("stereo", "sv");
lines = m3u8Audio.split("\n");
expect(lines[29]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST",X-RESUME-OFFSET=10.5'
expect(lines[8]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST",X-RESUME-OFFSET=10.5'
);
done();
});
Expand Down Expand Up @@ -2165,21 +2165,21 @@ test-audio=256000-6.m4s`;
mockVod
.load(mockCmafMasterManifest, mockCmafMediaManifest, mockCmafAudioManifest)
.then(() => {
return mockVod.insertInterstitialAt(18000, "001", "http://mock.com/asseturi", false, {
return mockVod.insertInterstitialAt(0, "001", "http://mock.com/asseturi", false, {
resumeOffset: 10500,
cue: "POST,ONCE",
});
})
.then(() => {
const m3u8 = mockVod.getMediaManifest(4497000);
let lines = m3u8.split("\n");
expect(lines[129]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST,ONCE",X-RESUME-OFFSET=10.5'
expect(lines[10]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST,ONCE",X-RESUME-OFFSET=10.5'
);
const m3u8Audio = mockVod.getAudioManifest("stereo", "sv");
lines = m3u8Audio.split("\n");
expect(lines[195]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:18.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST,ONCE",X-RESUME-OFFSET=10.5'
expect(lines[10]).toEqual(
'#EXT-X-DATERANGE:ID="001",CLASS="com.apple.hls.interstitial",START-DATE="1970-01-01T00:00:00.001Z",X-ASSET-URI="http://mock.com/asseturi",CUE="POST,ONCE",X-RESUME-OFFSET=10.5'
);
done();
});
Expand Down

0 comments on commit 603ef5f

Please sign in to comment.