diff --git a/parse.ts b/parse.ts index 0b909b8..70a7177 100644 --- a/parse.ts +++ b/parse.ts @@ -403,7 +403,8 @@ function sameKey(key1: Key, key2: Key): boolean { function parseMasterPlaylist(lines: Line[], params: Record): MasterPlaylist { const playlist = new MasterPlaylist(); let variantIsScored = false; - for (const [index, {name, value, attributes}] of (lines as Tag[]).entries()) { + for (const [index, line] of lines.entries()) { + const {name, value, attributes} = mapTo(line); if (name === 'EXT-X-VERSION') { playlist.version = value; } else if (name === 'EXT-X-STREAM-INF') { @@ -490,7 +491,7 @@ function parseSegment(lines: Line[], uri: string, start: number, end: number, me let mapHint = false; let partHint = false; for (let i = start; i <= end; i++) { - const {name, value, attributes} = lines[i] as Tag; + const {name, value, attributes} = mapTo(lines[i]); if (name === 'EXTINF') { if (!Number.isInteger(value.duration) && params.compatibleVersion < 3) { params.compatibleVersion = 3; @@ -658,7 +659,7 @@ function parseMediaPlaylist(lines: Line[], params: Record): MediaPl let currentMap: MediaInitializationSection | null = null; let containsParts = false; for (const [index, line] of lines.entries()) { - const {name, value, attributes, category} = line as Tag; + const {name, value, attributes, category} = mapTo(line); if (category === 'Segment') { if (segmentStart === -1) { segmentStart = index; @@ -1038,4 +1039,8 @@ function parse(text: string): MasterPlaylist | MediaPlaylist { return playlist; } +function mapTo(value: T | string): Partial { + return typeof value === 'string' ? {} : value; +} + export default parse;