feat: Parse as durations IFF first timestamp is >0
parent
a737d37105
commit
c4b1b42461
|
@ -167,14 +167,16 @@ export function parse(
|
|||
if (!options.forceTimestamps) {
|
||||
// If our timestamps are not in increasing order
|
||||
// Assume that we've been given a duration list instead
|
||||
result.forEach((current, index, list) => {
|
||||
if (index > 0) {
|
||||
let previous = list[index - 1];
|
||||
if (current.start.calc < previous.start.calc) {
|
||||
durations = true;
|
||||
if (result[0].start.calc!=0) {
|
||||
result.forEach((current, index, list) => {
|
||||
if (index > 0) {
|
||||
let previous = list[index - 1];
|
||||
if (current.start.calc < previous.start.calc) {
|
||||
durations = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (durations || options.forceDurations == true) {
|
||||
fixDurations(result);
|
||||
|
|
|
@ -113,6 +113,37 @@ describe("Parser", function() {
|
|||
});
|
||||
});
|
||||
|
||||
it("should parse as timestamps if first timestamp is 00:00", function() {
|
||||
let result = parse(`1. Artist - Title 00:00
|
||||
2. Another Artist - Another Title 01:00
|
||||
3. Yet Another Artist - Yet another title 02:00`);
|
||||
assert.deepEqual(result[0], {
|
||||
artist: "Artist",
|
||||
title: "Title",
|
||||
track: 1,
|
||||
start: { ts: "00:00:00", hh: 0, mm: 0, ss: 0, calc: 0 },
|
||||
end: { ts: "00:01:00", hh: 0, mm: 1, ss: 0, calc: 60 },
|
||||
_: { left_text: "Artist - Title", right_text: "" },
|
||||
});
|
||||
|
||||
assert.deepEqual(result[1], {
|
||||
artist: "Another Artist",
|
||||
title: "Another Title",
|
||||
track: 2,
|
||||
end: { ts: "00:02:00", hh: 0, mm: 2, ss: 0, calc: 120 },
|
||||
start: { ts: "00:01:00", hh: 0, mm: 1, ss: 0, calc: 60 },
|
||||
_: { left_text: "Another Artist - Another Title", right_text: "" },
|
||||
});
|
||||
assert.deepEqual(result[2], {
|
||||
artist: "Yet Another Artist",
|
||||
title: "Yet another title",
|
||||
track: 3,
|
||||
end: null,
|
||||
start: { ts: "00:02:00", hh: 0, mm: 2, ss: 0, calc: 120 },
|
||||
_: { left_text: "Yet Another Artist - Yet another title", right_text: "" },
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse durations as timestamps when forced", function() {
|
||||
let result = parse(
|
||||
`1. Artist - Title 5:00
|
||||
|
|
Loading…
Reference in New Issue