|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { either, oneOrMore, EndOfInput } = require("./operations");
|
|
|
|
const Newline = require("./simple/lines/newline").LF;
|
|
|
|
const RestOfLine = require("./simple/lines/rest-of-line").LF;
|
|
|
|
const Integer = require("./simple/numeric/integer");
|
|
|
|
const Decimal = require("./simple/numeric/decimal");
|
|
|
|
|
|
|
|
function lastItem(array) {
|
|
|
|
return array[array.length - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function line(strings, ... parsers) {
|
|
|
|
return function* () {
|
|
|
|
let parserResults = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < strings.length - 1; i++) {
|
|
|
|
yield strings[i];
|
|
|
|
parserResults.push(yield parsers[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
yield lastItem(strings);
|
|
|
|
yield Newline;
|
|
|
|
|
|
|
|
return parserResults;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function* Playlist() {
|
|
|
|
return yield either([ MediaPlaylist ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function* MediaPlaylist() {
|
|
|
|
yield line`#EXTM3U`;
|
|
|
|
let [ targetDuration] = yield line`#EXT-X-TARGETDURATION:${Integer}`;
|
|
|
|
yield Newline;
|
|
|
|
|
|
|
|
let items = yield oneOrMore(function* () {
|
|
|
|
let [ duration ] = yield line`#EXTINF:${Decimal},`;
|
|
|
|
let url = yield RestOfLine;
|
|
|
|
|
|
|
|
return { url, duration };
|
|
|
|
});
|
|
|
|
|
|
|
|
return { targetDuration, items };
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { Playlist };
|