UNPKG

mpls

Version:

Blu-ray movie playlist file (.mpls) parser

106 lines (98 loc) 2.45 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function parse(it) { let positions, items, itemFormat, itemCount, markFormat, markCount; positions = it.read({ type: ["skip", 8], items: "uint32", marks: "uint32" }); it.seek(positions.items + 6); itemFormat = { blockSize: "uint16", name: ["string", 5], padding: ["skip", 7], in: "uint32", out: "uint32", padding1: ["skip", it => it.blockSize - 20] }; itemCount = it.read("uint16"); it.skip(2); items = Array.from({ length: itemCount }).map(function (_) { let that; return { name: (that = it.read(itemFormat)).name, "in": that["in"], out: that.out }; }); it.seek(positions.marks + 4); markFormat = { padding: ["skip", 2], index: "uint16", time: "uint32", padding1: ["skip", 6] }; markCount = it.read("uint16"); Array.from({ length: markCount }).map((arg0$, i) => { let index, time, ref$; ({ index, time } = it.read(markFormat)); return ((ref$ = items[index]).times || (ref$.times = [])).push(time); }); return items; } function convert24p(it) { return Math.round(it * 24000 / 1001 / 45000); } function last(it) { return it[it.length - 1]; } function fixTimes(lists, base = convert24p) { let start; start = {}; lists.forEach(function (it) { return it.forEach(function ({ name, in: t }) { return start[name] <= t || (start[name] = t); }); }); return lists.map(function (list) { let next; next = list.filter(it => it.times).map(function (it) { return Object.assign({}, it); }); next.reduce(function (a, b) { if (a.name !== b.name && last(a.times) <= b.in && b.in <= a.out) { a.out = b.in, a; } return b; }); return next.map(function (item) { let name, times, ref$, cascade$, ext; ({ name, times } = item); ref$ = [cascade$, cascade$ = ext = item.times.slice(), (item.in < times[0] ? cascade$.unshift(item.in) : void 0, ext.length < 2 || item.out > last(times) + 90090 ? cascade$.push(item.out) : void 0)], cascade$ = ref$[0], ref$[1]; times = ext.map(function (it) { return base(it - start[name]); }); return { name, times }; }); }); } exports.parse = parse; exports.fixTimes = fixTimes; //# sourceMappingURL=index.js.map