Skip to content

Warnings

trackparse never fails, but it does tell you when it had to guess. Warnings are how. There are three kinds: on a single track, on a tracklist, and on an edit.

In JavaScript and Python a warning code is a string. In Rust it is an enum variant, and as_str() or Display gives the same string. In Go it is a constant of a string type, whose value is the string. In C it is an enum value, and its _name() function gives the string. The tables below give the string and what it means, and each section says once how the Rust, Go and C names are made from it. The names follow that rule for every code, with no exceptions. Each meaning links the rule of the spec that raises it.

ParsedTrack.warnings is a list of codes: an array of strings in JavaScript, a tuple of strings in Python, a Vec<Warning> in Rust (Warning), a []Warning in Go (Warning), a const trackparse_warning * with warnings_count in C (trackparse.h). An empty list means every decision was unambiguous. Click an example to open it in the playground.

Warning Means Example
noSeparator No artist/title separator was found. The whole string is the title (R6.8) Around the World
ambiguousSeparator A pipe-separated YouTube title had two parts and no dash, so they were read as artist and title (R2.4) Noisia | Stigma
unspacedDashSplit Split at a dash without spaces around it (youtube and filename modes, and timed tracklist lines: R6.7, R6.10) Blink-182-All The Small Things
asymmetricDashSplit Split at a dash with a space on one side only (R6.4) Artist -Title
bySplit Read "Title" by Artist (youtube mode, R6.6) "Numb" by Linkin Park
quotedTitleSplit Took a quoted span as the title and what came before it as the artist (youtube mode, R6.5) Linkin Park: "Numb"
ambiguousMixCredit <Name> Mix was read as a remix, but the name is long enough that it might be a style (R5.7) (Fonetick Lee & Sonic Art Space Drums Mix)
unbalancedBrackets A bracket was opened and never closed (R3.3) Noisia - Stigma (VIP

In the other languages the name is the code with its first letter capitalized, after a prefix: Warning:: in Rust, Warning in Go (trackparse.WarningNoSeparator). In C the code is written in upper case with an underscore between its words, after TRACKPARSE_WARNING_ (TRACKPARSE_WARNING_NO_SEPARATOR).

What to do with them depends on your data. For a music library, a track with any warning is a good candidate for a human to look at. For scrobbling, most of them are fine to accept. Modes explains which mode takes which guess. The example below is in the playground too.

import { parse } from "trackparse";
const track = parse("Blink-182-All The Small Things", { mode: "youtube" });
track.warnings; // [ 'unspacedDashSplit' ]
track.warnings.includes("unspacedDashSplit"); // true
track.warnings.length === 0; // false

In TypeScript the element type is the union Warning, so a misspelled code doesn't compile.

Tracklist.warnings holds objects: { code, line, severity, suggestion } (TracklistWarning). They are sorted by line. In Rust the code is a WarningCode and the severity is Severity::Info or Severity::Warning. In Go they are a WarningCode and SeverityInfo or SeverityWarning, and Suggestion is a pointer. In C they are a trackparse_tracklist_warning_code and TRACKPARSE_SEVERITY_INFO or TRACKPARSE_SEVERITY_WARNING, and suggestion is a pointer. All of them are R13.7 in the spec.

The names drop the dashes and capitalize each word after a prefix: WarningCode:: in Rust (WarningCode::TimeOutOfOrder), WarningCode in Go (trackparse.WarningCodeTimeOutOfOrder). In C the dashes become underscores, in upper case, after TRACKPARSE_TL_ (TRACKPARSE_TL_TIME_OUT_OF_ORDER).

Code Severity When
time-missing warning A track line has no time while other lines do (not raised on a w/ line, which plays at the previous track's time)
time-out-of-order warning Earlier than the previous timed line. May carry a suggestion
time-duplicate warning Same time as the previous timed line
no-start-at-zero info The first time isn't 0:00
time-after-audio-end warning Later than audioSeconds (audio_seconds, AudioSeconds)
invalid-time warning Looks like a time but isn't one (1:75, 0:61:00). The line keeps it in rest
position-gap warning A track number isn't the previous one plus 1
position-duplicate warning Same track number as the previous one
line-unparsed warning A track line with no artist/title separator, or nothing after the time

Warnings of each line's own track stay on entries[i].track.warnings. They are the track warnings above and are not repeated in the list's warnings.

The list in this example opens in the playground, where both warnings show.

import { parseTracklist } from "trackparse/tracklist";
const text = "00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless\n03:55 Phace - Psycho\n09:30 Imanu";
const list = parseTracklist(text);
list.warnings;
// [
// { code: 'time-out-of-order', line: 3, severity: 'warning', suggestion: null },
// { code: 'line-unparsed', line: 4, severity: 'warning', suggestion: null }
// ]
list.warnings.filter((w) => w.severity === "warning").map((w) => `line ${w.line}: ${w.code}`);
// [ 'line 3: time-out-of-order', 'line 4: line-unparsed' ]

Here line 3 has no suggestion, because more than one time would fit between its neighbors. Tracklists walks through a list that does get a suggestion.

A suggestion is { line, raw, seconds }: the one time, one or two digits away from what was written, that puts the list back in order. It's written in the same style as the original.

The search runs in two steps. First it tries the flagged line itself. If no time fits there, it tries the previous timed line, since sometimes that's where the typo is: 01:22:21 followed by 01:03:55 suggests changing the first line to 01:02:21. If more than one candidate fits, or none does, suggestion is null (None in Python and Rust, nil in Go, NULL in C). A wrong suggestion would be worse than none.

To apply one, pass its line and seconds to a set-time edit. See Editing tracklists. In the playground, a warning with a suggestion has a button that applies it.

applyEdits (apply_edits in Python and Rust, ApplyEdits in Go, trackparse_apply_edits in C) returns { code, edit, line } objects (EditWarning in Rust, EditWarning in Go, trackparse_edit_warning in C). edit is the index in your list of edits, and line is null (None, nil in Go, NULL in C) when the edit names no line. The rules are R13.9.

The names follow the tracklist codes with another prefix: EditWarningCode:: in Rust (EditWarningCode::EditInvalid), EditWarningCode in Go (trackparse.EditWarningCodeEditInvalid) and TRACKPARSE_EDIT_WARNING_ in C (TRACKPARSE_EDIT_WARNING_EDIT_INVALID), of the enum trackparse_edit_warning_code.

Code When
style-upgraded a time without hours passed one hour and gained them (R13.9.2)
time-clamped a time would go below zero and was set to zero (R13.9.3)
edit-invalid the edit could not apply and changed nothing (R13.9.6)
import { applyEdits } from "trackparse/tracklist";
const result = applyEdits(text, [
{ op: "set-time", line: 9, seconds: 60 }, // there is no line 9
{ op: "shift", seconds: -300, lines: [2] }, // 04:10 minus five minutes
]);
result.warnings;
// [ { code: 'edit-invalid', edit: 0, line: 9 }, { code: 'time-clamped', edit: 1, line: 2 } ]
result.changed; // [ 2 ]
result.text.split("\n")[1]; // '00:00 Mefjus - Sleepless'

The first edit changed nothing and the second one still ran: a bad edit never stops the others. Editing tracklists lists what makes an edit invalid.