Skip to content

Commit

Permalink
Merge pull request #40 from Eyevinn/fix/reject-loading-non-master-m3u8
Browse files Browse the repository at this point in the history
add rejection on loading a non master manifest
  • Loading branch information
Nfrederiksen authored Mar 16, 2023
2 parents 1cfe30c + 97a1ad2 commit 65b3bd0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const findNearestBw = (bw, array) => {
return sorted[sorted.length - 1];
};
*/

const NOT_MULTIVARIANT_ERROR_MSG = "Error: Source is Not a Multivariant Manifest";

const findNearestGroupAndLang = (_group, _language, _playlist) => {
const groups = Object.keys(_playlist);
let group = groups[0]; // default
Expand Down Expand Up @@ -103,6 +106,11 @@ class HLSSpliceVod {
if (m) {
baseUrl = m[1] + "/";
}

if(m3u.items.StreamItem.length === 0 && m3u.items.PlaylistItem.length > 0) {
return reject(NOT_MULTIVARIANT_ERROR_MSG);
}

for (let i = 0; i < m3u.items.StreamItem.length; i++) {
const streamItem = m3u.items.StreamItem[i];
const mediaManifestUrl = url.resolve(baseUrl, streamItem.get("uri"));
Expand All @@ -124,7 +132,7 @@ class HLSSpliceVod {
if (streamItem.get("resolution") === undefined) {
return true;
}
let streamGroupId = streamItem.attributes.attributes["audio"];
let streamGroupId = streamItem.get("audio");
if (streamGroupId === aItemGroup) {
return false;
} else {
Expand Down Expand Up @@ -199,7 +207,7 @@ class HLSSpliceVod {

while (pos < offset && i < this.playlists[bw].items.PlaylistItem.length) {
const plItem = this.playlists[bw].items.PlaylistItem[i];
if (plItem.attributes.attributes["map-uri"]) {
if (plItem.get("map-uri")) {
closestCmafMapUri = this._getCmafMapUri(this.playlists[bw], this.masterManifestUri, this.baseUrl, i);
}
pos += plItem.get("duration") * 1000;
Expand Down Expand Up @@ -652,7 +660,7 @@ class HLSSpliceVod {
if (!plUri.match("^http")) {
plItem.set("uri", url.resolve(baseUrl, plUri));
}
const plMapUri = plItem.attributes.attributes["map-uri"];
const plMapUri = plItem.get("map-uri");
if (plMapUri && !plMapUri.match(/^http/)) {
plItem.set("map-uri", url.resolve(baseUrl, plMapUri));
}
Expand Down Expand Up @@ -708,7 +716,7 @@ class HLSSpliceVod {
if (!plUri.match("^http")) {
plItem.set("uri", url.resolve(baseUrl, plUri));
}
const plMapUri = plItem.attributes.attributes["map-uri"];
const plMapUri = plItem.get("map-uri");
if (plMapUri && !plMapUri.match(/^http/)) {
plItem.set("map-uri", url.resolve(baseUrl, plMapUri));
}
Expand Down Expand Up @@ -770,8 +778,8 @@ class HLSSpliceVod {

_getCmafMapUri(m3u, manifestUri, useAbsUrl, index = 0) {
let initSegment = undefined;
if (m3u.items.PlaylistItem[index].attributes.attributes["map-uri"]) {
initSegment = m3u.items.PlaylistItem[index].attributes.attributes["map-uri"];
if (m3u.items.PlaylistItem[index].get("map-uri")) {
initSegment = m3u.items.PlaylistItem[index].get("map-uri");
if (!initSegment.match("^http") && useAbsUrl) {
const n = manifestUri.match("^(.*)/.*?$");
if (n) {
Expand Down

0 comments on commit 65b3bd0

Please sign in to comment.