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.
Track warnings
Section titled “Track warnings”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"); // truetrack.warnings.length === 0; // falseIn TypeScript the element type is the union Warning, so a misspelled code doesn't compile.
from trackparse import parse
track = parse("Blink-182-All The Small Things", mode="youtube")
track.warnings # ('unspacedDashSplit',)"unspacedDashSplit" in track.warnings # Truenot track.warnings # FalseThe element type is the Literal alias Warning, so mypy catches a misspelled code.
use trackparse::{parse_with, ModeOption, ParseOptions, Warning};
let track = parse_with("Blink-182-All The Small Things", &ParseOptions::new().mode(ModeOption::Youtube));
&track.warnings; // [UnspacedDashSplit]track.warnings.contains(&Warning::UnspacedDashSplit); // truetrack.warnings.is_empty(); // false
for warning in &track.warnings { match warning { Warning::NoSeparator => println!("no artist"), Warning::UnspacedDashSplit | Warning::AsymmetricDashSplit => println!("check the dash"), other => println!("{other}"), // Display prints the code, such as bySplit }}// check the dashWarning is #[non_exhaustive], so a match needs a catch-all arm: a later spec version can add
a warning. Warning::ALL lists the variants, and Warning::from_name("bySplit") reads a code back.
import ( "fmt" "slices" "strings"
"github.com/4matic/trackparse/go")
track := trackparse.ParseWith("Blink-182-All The Small Things", trackparse.ParseOptions{Mode: trackparse.ModeYouTube})
fmt.Println(track.Warnings) // [unspacedDashSplit]fmt.Println(slices.Contains(track.Warnings, trackparse.WarningUnspacedDashSplit)) // truefmt.Println(len(track.Warnings) == 0) // false
for _, warning := range track.Warnings { switch warning { case trackparse.WarningNoSeparator: fmt.Println("no artist") case trackparse.WarningUnspacedDashSplit, trackparse.WarningAsymmetricDashSplit: fmt.Println("check the dash") default: fmt.Println(warning) // the code itself, such as bySplit }}// check the dashWarning is a string type, so a warning prints as its code and compares with the constants
(trackparse.WarningBySplit). Keep a default case: a later spec version can add a warning.
trackparse.AllWarnings() lists the codes.
#include <trackparse.h>
trackparse_parse_options *o = trackparse_parse_options_new();trackparse_parse_options_set_mode(o, TRACKPARSE_MODE_YOUTUBE);trackparse_track *track = trackparse_parse_with("Blink-182-All The Small Things", TRACKPARSE_NUL_TERMINATED, o);trackparse_parse_options_free(o);
printf("%zu\n", track->warnings_count); // 1printf("%s\n", trackparse_warning_name(track->warnings[0])); // unspacedDashSplit
for (size_t i = 0; i < track->warnings_count; i++) { switch (track->warnings[i]) { case TRACKPARSE_WARNING_NO_SEPARATOR: printf("no artist\n"); break; case TRACKPARSE_WARNING_UNSPACED_DASH_SPLIT: case TRACKPARSE_WARNING_ASYMMETRIC_DASH_SPLIT: printf("check the dash\n"); break; default: printf("%s\n", trackparse_warning_name(track->warnings[i])); /* the code, such as bySplit */ }}// check the dashtrackparse_track_free(track);trackparse_warning is an enum, and trackparse_warning_name() gives its code. Keep a default
case: a later spec version can add a warning.
Tracklist warnings
Section titled “Tracklist warnings”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' ]from trackparse.tracklist import parse_tracklist
text = "00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless\n03:55 Phace - Psycho\n09:30 Imanu"tl = parse_tracklist(text)
tl.warnings# (TracklistWarning(code='time-out-of-order', line=3, severity='warning', suggestion=None),# TracklistWarning(code='line-unparsed', line=4, severity='warning', suggestion=None))
[f"line {w.line}: {w.code}" for w in tl.warnings if w.severity == "warning"]# ['line 3: time-out-of-order', 'line 4: line-unparsed']use trackparse::tracklist::{parse_tracklist, Severity, WarningCode};
let text = "00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless\n03:55 Phace - Psycho\n09:30 Imanu";let list = parse_tracklist(text);
&list.warnings;// [TracklistWarning { code: TimeOutOfOrder, line: 3, severity: Warning, suggestion: None },// TracklistWarning { code: LineUnparsed, line: 4, severity: Warning, suggestion: None }]
list.warnings.iter() .filter(|w| w.severity == Severity::Warning) .map(|w| format!("line {}: {}", w.line, w.code)) .collect::<Vec<_>>();// ["line 3: time-out-of-order", "line 4: line-unparsed"]
list.warnings.iter().any(|w| w.code == WarningCode::TimeOutOfOrder); // trueWarningCode is #[non_exhaustive] too, so keep a _ arm when you match on it.
text := "00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless\n03:55 Phace - Psycho\n09:30 Imanu"list := trackparse.ParseTracklist(text)
for _, w := range list.Warnings { fmt.Println(w.Code, w.Line, w.Severity, w.Suggestion == nil)}// time-out-of-order 3 warning true// line-unparsed 4 warning true
for _, w := range list.Warnings { if w.Severity == trackparse.SeverityWarning { fmt.Printf("line %d: %s\n", w.Line, w.Code) }}// line 3: time-out-of-order// line 4: line-unparsed
fmt.Println(slices.ContainsFunc(list.Warnings, func(w trackparse.TracklistWarning) bool { return w.Code == trackparse.WarningCodeTimeOutOfOrder})) // trueWarningCode is a string type too; keep a default case when you switch on it.
const char *text = "00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless\n03:55 Phace - Psycho\n09:30 Imanu";trackparse_tracklist *list = trackparse_parse_tracklist(text, TRACKPARSE_NUL_TERMINATED);
for (size_t i = 0; i < list->warnings_count; i++) { const trackparse_tracklist_warning *w = &list->warnings[i]; printf("%s %d %s %d\n", trackparse_tracklist_warning_code_name(w->code), w->line, trackparse_severity_name(w->severity), w->suggestion == NULL);}// time-out-of-order 3 warning 1// line-unparsed 4 warning 1
for (size_t i = 0; i < list->warnings_count; i++) { const trackparse_tracklist_warning *w = &list->warnings[i]; if (w->severity == TRACKPARSE_SEVERITY_WARNING) { printf("line %d: %s\n", w->line, trackparse_tracklist_warning_code_name(w->code)); }}// line 3: time-out-of-order// line 4: line-unparsedtrackparse_tracklist_free(list);trackparse_tracklist_warning_code is an enum too; keep a default case when you switch on it.
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.
Suggestions
Section titled “Suggestions”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.
Edit warnings
Section titled “Edit warnings”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'from trackparse.tracklist import apply_edits
result = apply_edits(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# (EditWarning(code='edit-invalid', edit=0, line=9), EditWarning(code='time-clamped', edit=1, line=2))result.changed # (2,)result.text.split("\n")[1] # '00:00 Mefjus - Sleepless'use trackparse::tracklist::{apply_edits, Edit, EditWarningCode};
let result = apply_edits(text, &[ Edit::set_time(9, 60.0), // there is no line 9 Edit::shift_lines(-300.0, [2]), // 04:10 minus five minutes]);
&result.warnings;// [EditWarning { code: EditInvalid, edit: 0, line: Some(9) }, EditWarning { code: TimeClamped, edit: 1, line: Some(2) }]&result.changed; // [2]result.text.split('\n').nth(1); // Some("00:00 Mefjus - Sleepless")
result.warnings.iter().any(|w| w.code == EditWarningCode::EditInvalid); // trueresult := trackparse.ApplyEdits(text, []trackparse.Edit{ trackparse.SetTime(9, 60), // there is no line 9 trackparse.ShiftLines(-300, 2), // 04:10 minus five minutes})
for _, w := range result.Warnings { fmt.Println(w.Code, w.Edit, *w.Line)}// edit-invalid 0 9// time-clamped 1 2fmt.Println(result.Changed) // [2]fmt.Printf("%q\n", strings.Split(result.Text, "\n")[1]) // "00:00 Mefjus - Sleepless"
fmt.Println(slices.ContainsFunc(result.Warnings, func(w trackparse.EditWarning) bool { return w.Code == trackparse.EditWarningCodeEditInvalid})) // trueLine is an *int, nil when the edit names no line, so check it before you read it.
trackparse_edits *edits = trackparse_edits_new();trackparse_edits_set_time(edits, 9, 60); /* there is no line 9 */long long lines[] = {2};trackparse_edits_shift_lines(edits, -300, lines, 1); /* 04:10 minus five minutes */trackparse_edit_result *result = trackparse_apply_edits(text, TRACKPARSE_NUL_TERMINATED, edits);trackparse_edits_free(edits);
for (size_t i = 0; i < result->warnings_count; i++) { const trackparse_edit_warning *w = &result->warnings[i]; printf("%s %zu %lld\n", trackparse_edit_warning_code_name(w->code), w->edit, *w->line);}// edit-invalid 0 9// time-clamped 1 2printf("%zu %lld\n", result->changed_count, result->changed[0]); // 1 2
const char *second = strchr(result->text.ptr, '\n') + 1;printf("%.*s\n", (int)(strchr(second, '\n') - second), second); // 00:00 Mefjus - Sleeplesstrackparse_edit_result_free(result);line is a const long long *, NULL when the edit names no line, so check it before you read
it.
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.
See also
Section titled “See also”parseandParsedTrackand the Tracklist API for the types that carry the warnings.- Modes for the guesses behind the track warnings.
- Tracklists for the list checks, and Editing tracklists for the edit warnings.