You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.0 KiB
JavaScript

"use strict";
const { either, wholeMatch, optional, oneOrMore, until, EndOfInput } = require("./operations");
function* Newline() {
yield "\n";
}
function* Digits() {
return yield /[0-9]+/;
}
function* Integer() {
return parseInt(yield wholeMatch(Digits));
}
function* Decimal() {
// NOTE: this gets converted to a floating point value!
let decimalString = yield wholeMatch(function* () {
yield Digits;
yield optional(function* () {
yield ".";
yield Digits;
});
});
return parseFloat(decimalString);
}
function* Playlist() {
return yield either([ MediaPlaylist ]);
}
function* MediaPlaylist() {
yield "#EXTM3U";
yield Newline;
yield "#EXT-X-TARGETDURATION:";
let targetDuration = yield Integer;
yield Newline;
yield Newline;
let items = yield oneOrMore(function* () {
yield "#EXTINF:";
let duration = yield Decimal;
yield ",";
yield Newline;
let url = yield until(Newline);
yield either([ EndOfInput, Newline ]);
return { url, duration };
});
return { targetDuration, items };
}
module.exports = { Playlist };