Tracklists
Mixes and podcasts come with a tracklist: a block of text, one track per line, usually with a start
time in front. parseTracklist
(parse_tracklist in Python and Rust, ParseTracklist in Go, trackparse_parse_tracklist in C) reads the whole block. Every line
gets its kind, its time and a full ParsedTrack. The list as a
whole gets checks with line numbers. The rules are R13
in the spec, and every field is listed in the Tracklist API.
import { parseTracklist } from "trackparse/tracklist";from trackparse.tracklist import parse_tracklistuse trackparse::tracklist::parse_tracklist;import ( "fmt"
"github.com/4matic/trackparse/go")#include <trackparse.h>In JavaScript it's a separate entry point, trackparse/tracklist, about 8.4 KiB gzipped, so code
that only parses single tracks never loads it. In Python it is the module trackparse.tracklist,
in Rust the module trackparse::tracklist. Go has no separate entry:
trackparse.ParseTracklist and trackparse.ApplyEdits
are in the one package. C has none either: trackparse_parse_tracklist and
trackparse_apply_edits are declared in the one header,
trackparse.h.
Two things differ in Rust. Seconds are f64, since a time can carry a fraction, so Debug prints
3167.0 where JavaScript and Python print 3167. to_json() writes 3167, as JavaScript and
Python do.
And entry.time and entry.track are Options, because a header or a blank line has neither.
Go is like Rust here. Seconds is a float64, which fmt prints as 3167, and json.Marshal
writes 3167. Time and Track are pointers, nil on a header or a blank line.
C is like Go. seconds is a double (the examples print it with %g), and
trackparse_tracklist_to_json writes 3167. time and track are pointers, NULL on a header
or a blank line. The result owns all its memory, entries and their tracks included, and
trackparse_tracklist_free releases it.
A first list
Section titled “A first list”const text = [ "Hour 2", "48:20 Noisia - Stigma", "52:47 Mefjus & Kasra - Bandwagon (Phace Remix)", "56:05 Black Sun Empire - ID", "59:31 Alix Perez - Fade Away", "01:03:10 Interview with Hybris", "01:07:44 Imanu - Sacrifice", "00:11:02 Current Value feat. Teddy Killerz - Payload", // typo: should be 01:11:02 "01:15:36 Hybris - Spinning Top",].join("\r\n");
const list = parseTracklist(text);
list.entries.map((e) => e.kind);// [ 'header', 'track', 'track', 'track', 'track', 'marker', 'track', 'track', 'track' ]
const bandwagon = list.entries[2];bandwagon.time; // { raw: '52:47', seconds: 3167 }bandwagon.parts; // { lead: '', time: '52:47', gap: ' ', rest: 'Mefjus & Kasra - Bandwagon (Phace Remix)' }bandwagon.track.artists.map((a) => a.name); // [ 'Mefjus', 'Kasra' ]bandwagon.track.versions.map((v) => `${v.type} by ${v.artists[0].name}`); // [ 'remix by Phace' ]list.entries[3].track.flags.unknownTitle; // true (the ID)
list.stats;// { lines: 9, tracks: 7, markers: 1, timed: 8, firstTime: 2900, lastTime: 4536 }text = "\r\n".join([ "Hour 2", "48:20 Noisia - Stigma", "52:47 Mefjus & Kasra - Bandwagon (Phace Remix)", "56:05 Black Sun Empire - ID", "59:31 Alix Perez - Fade Away", "01:03:10 Interview with Hybris", "01:07:44 Imanu - Sacrifice", "00:11:02 Current Value feat. Teddy Killerz - Payload", # typo: should be 01:11:02 "01:15:36 Hybris - Spinning Top",])
tl = parse_tracklist(text)
[e.kind for e in tl.entries]# ['header', 'track', 'track', 'track', 'track', 'marker', 'track', 'track', 'track']
bandwagon = tl.entries[2]bandwagon.time # TimeValue(raw='52:47', seconds=3167)bandwagon.parts # Parts(lead='', time='52:47', gap=' ', rest='Mefjus & Kasra - Bandwagon (Phace Remix)')[a.name for a in bandwagon.track.artists] # ['Mefjus', 'Kasra'][f"{v.type} by {v.artists[0].name}" for v in bandwagon.track.versions] # ['remix by Phace']tl.entries[3].track.flags.unknown_title # True (the ID)
tl.stats# Stats(lines=9, tracks=7, markers=1, timed=8, first_time=2900, last_time=4536)let text = [ "Hour 2", "48:20 Noisia - Stigma", "52:47 Mefjus & Kasra - Bandwagon (Phace Remix)", "56:05 Black Sun Empire - ID", "59:31 Alix Perez - Fade Away", "01:03:10 Interview with Hybris", "01:07:44 Imanu - Sacrifice", "00:11:02 Current Value feat. Teddy Killerz - Payload", // typo: should be 01:11:02 "01:15:36 Hybris - Spinning Top",].join("\r\n");
let list = parse_tracklist(&text);
list.entries.iter().map(|e| e.kind).collect::<Vec<_>>();// [Header, Track, Track, Track, Track, Marker, Track, Track, Track]
let bandwagon = &list.entries[2];&bandwagon.time; // Some(TimeValue { raw: "52:47", seconds: 3167.0 })&bandwagon.parts; // Parts { lead: "", time: "52:47", gap: " ", rest: "Mefjus & Kasra - Bandwagon (Phace Remix)" }let track = bandwagon.track.as_ref().unwrap();track.artists.iter().map(|a| &a.name).collect::<Vec<_>>(); // ["Mefjus", "Kasra"]track.versions.iter().map(|v| format!("{} by {}", v.version_type, v.artists[0].name)).collect::<Vec<_>>();// ["remix by Phace"]list.entries[3].track.as_ref().unwrap().flags.unknown_title; // true (the ID)
&list.stats;// Stats { lines: 9, tracks: 7, markers: 1, timed: 8, first_time: Some(2900.0), last_time: Some(4536.0) }import "strings"
text := strings.Join([]string{ "Hour 2", "48:20 Noisia - Stigma", "52:47 Mefjus & Kasra - Bandwagon (Phace Remix)", "56:05 Black Sun Empire - ID", "59:31 Alix Perez - Fade Away", "01:03:10 Interview with Hybris", "01:07:44 Imanu - Sacrifice", "00:11:02 Current Value feat. Teddy Killerz - Payload", // typo: should be 01:11:02 "01:15:36 Hybris - Spinning Top",}, "\r\n")
list := trackparse.ParseTracklist(text)
kinds := []trackparse.EntryKind{}for _, e := range list.Entries { kinds = append(kinds, e.Kind)}fmt.Println(kinds) // [header track track track track marker track track track]
bandwagon := list.Entries[2]fmt.Printf("%+v\n", *bandwagon.Time) // {Raw:52:47 Seconds:3167}fmt.Printf("%#v\n", bandwagon.Parts)// trackparse.Parts{Lead:"", Time:"52:47", Gap:" ", Rest:"Mefjus & Kasra - Bandwagon (Phace Remix)"}names := []string{}for _, a := range bandwagon.Track.Artists { names = append(names, a.Name)}fmt.Printf("%q\n", names) // ["Mefjus" "Kasra"]for _, v := range bandwagon.Track.Versions { fmt.Println(v.Type, "by", v.Artists[0].Name)}// remix by Phacefmt.Println(list.Entries[3].Track.Flags.UnknownTitle) // true
s := list.Statsfmt.Println(s.Lines, s.Tracks, s.Markers, s.Timed, *s.FirstTime, *s.LastTime) // 9 7 1 8 2900 4536const char *text = "Hour 2\r\n" "48:20 Noisia - Stigma\r\n" "52:47 Mefjus & Kasra - Bandwagon (Phace Remix)\r\n" "56:05 Black Sun Empire - ID\r\n" "59:31 Alix Perez - Fade Away\r\n" "01:03:10 Interview with Hybris\r\n" "01:07:44 Imanu - Sacrifice\r\n" "00:11:02 Current Value feat. Teddy Killerz - Payload\r\n" /* typo: should be 01:11:02 */ "01:15:36 Hybris - Spinning Top";
trackparse_tracklist *list = trackparse_parse_tracklist(text, TRACKPARSE_NUL_TERMINATED);
for (size_t i = 0; i < list->entries_count; i++) { printf("%s%s", i ? " " : "", trackparse_entry_kind_name(list->entries[i].kind));}printf("\n"); // header track track track track marker track track track
const trackparse_entry *bandwagon = &list->entries[2];printf("%s %g\n", bandwagon->time->raw.ptr, bandwagon->time->seconds); // 52:47 3167const trackparse_parts *p = &bandwagon->parts;printf("\"%s\" \"%s\" \"%s\" \"%s\"\n", p->lead.ptr, p->time.ptr, p->gap.ptr, p->rest.ptr);// "" "52:47" " " "Mefjus & Kasra - Bandwagon (Phace Remix)"const trackparse_track *track = bandwagon->track;for (size_t i = 0; i < track->artists_count; i++) { printf("%s\n", track->artists[i].name.ptr);}// Mefjus// Kasrafor (size_t i = 0; i < track->versions_count; i++) { printf("%s by %s\n", track->versions[i].type_name.ptr, track->versions[i].artists[0].name.ptr);}// remix by Phaceprintf("%d\n", list->entries[3].track->flags.unknown_title); // 1
const trackparse_stats *s = &list->stats;printf("%d %d %d %d %g %g\n", s->lines, s->tracks, s->markers, s->timed, *s->first_time, *s->last_time);// 9 7 1 8 2900 4536Paste it into the playground to see the table, the warnings and the fix button.
Nothing is lost
Section titled “Nothing is lost”Every entry keeps its line exactly as written in raw, and its own line ending in eol. Joining
raw + eol over the entries gives you back the input, byte for byte. CRLF, LF and CR all work, even
mixed in one text, and trailing spaces survive. A last line without a newline has eol: ""
(R13.1).
list.entries.map((e) => e.raw + e.eol).join("") === text; // true"".join(e.raw + e.eol for e in tl.entries) == text # Truelist.entries.iter().map(|e| format!("{}{}", e.raw, e.eol)).collect::<String>() == text; // truevar joined strings.Builderfor _, e := range list.Entries { joined.WriteString(e.Raw + string(e.Eol))}fmt.Println(joined.String() == text) // truechar joined[1024] = "";for (size_t i = 0; i < list->entries_count; i++) { strcat(joined, list->entries[i].raw.ptr); strcat(joined, trackparse_eol_name(list->entries[i].eol));}printf("%d\n", strcmp(joined, text) == 0); // 1parts cuts raw into four strings that join back into it
(R13.1.3):
| Part | Holds |
|---|---|
lead |
spaces, a list bullet (- , * , • ), Markdown emphasis or an opening bracket before the time |
time |
the time as written, 52:47 |
gap |
whatever sits between the time and the track: ] , -, |, =>, **] |
rest |
the track text, which is what gets parsed |
That split is what lets an editor rewrite a time without touching anything else on the line.
All of these are read as start times:
| Written | Seconds |
|---|---|
12:34, [12:34], (12:34) |
754 |
1:02:03, 01:02:03 |
3723 |
125:30 (a long mix with no hours) |
7530 |
00:00:07.500, 0:07,5 |
7.5 |
A list bullet in front is fine too, as in lists pasted from Discord or Reddit:
* 12:34 Artist - Title and - [12:34] Artist - Title are both read at 754 seconds, and the
bullet goes into lead.
Something that looks like a time but can't be one, like 1:75 or 0:61:00, stays in rest and
raises an invalid-time warning. The time forms are
R13.2.
Markdown
Section titled “Markdown”Lists copied from Discord, Reddit, Telegram or YouTube comments often keep their Markdown:
**bold**, __underline__, *italic* or _italic_, sometimes only around the time. trackparse
reads through it. Emphasis next to the time goes into lead and gap, so an edit keeps it.
Emphasis in the rest of the line stays in rest, but the parser reads the text without it.
Both lines below are in the playground.
const md = parseTracklist("**[**14:21**] 10. Nitepunk - ID**\n* 18:02 Noisia - _Stigma_");const [a, b] = md.entries;
a.parts; // { lead: '**[**', time: '14:21', gap: '**] ', rest: '10. Nitepunk - ID**' }a.track.artists.map((x) => x.name); // [ 'Nitepunk' ]a.track.title; // 'ID'a.track.position; // { raw: '10', number: 10 }b.track.title; // 'Stigma'md = parse_tracklist("**[**14:21**] 10. Nitepunk - ID**\n* 18:02 Noisia - _Stigma_")a, b = md.entries
a.parts # Parts(lead='**[**', time='14:21', gap='**] ', rest='10. Nitepunk - ID**')[x.name for x in a.track.artists] # ['Nitepunk']a.track.title # 'ID'a.track.position # Position(raw='10', number=10)b.track.title # 'Stigma'let md = parse_tracklist("**[**14:21**] 10. Nitepunk - ID**\n* 18:02 Noisia - _Stigma_");let (a, b) = (&md.entries[0], &md.entries[1]);
&a.parts; // Parts { lead: "**[**", time: "14:21", gap: "**] ", rest: "10. Nitepunk - ID**" }let track = a.track.as_ref().unwrap();track.artists.iter().map(|x| &x.name).collect::<Vec<_>>(); // ["Nitepunk"]&track.title; // "ID"&track.position; // Some(Position { raw: "10", number: 10 })&b.track.as_ref().unwrap().title; // "Stigma"md := trackparse.ParseTracklist("**[**14:21**] 10. Nitepunk - ID**\n* 18:02 Noisia - _Stigma_")a, b := md.Entries[0], md.Entries[1]
fmt.Printf("%#v\n", a.Parts)// trackparse.Parts{Lead:"**[**", Time:"14:21", Gap:"**] ", Rest:"10. Nitepunk - ID**"}names = nilfor _, x := range a.Track.Artists { names = append(names, x.Name)}fmt.Printf("%q\n", names) // ["Nitepunk"]fmt.Printf("%q\n", a.Track.Title) // "ID"fmt.Printf("%+v\n", *a.Track.Position) // {Raw:10 Number:10}fmt.Printf("%q\n", b.Track.Title) // "Stigma"trackparse_tracklist *md = trackparse_parse_tracklist( "**[**14:21**] 10. Nitepunk - ID**\n* 18:02 Noisia - _Stigma_", TRACKPARSE_NUL_TERMINATED);const trackparse_entry *a = &md->entries[0], *b = &md->entries[1];
printf("\"%s\" \"%s\" \"%s\" \"%s\"\n", a->parts.lead.ptr, a->parts.time.ptr, a->parts.gap.ptr, a->parts.rest.ptr);// "**[**" "14:21" "**] " "10. Nitepunk - ID**"for (size_t i = 0; i < a->track->artists_count; i++) { printf("%s\n", a->track->artists[i].name.ptr);}// Nitepunkprintf("%s\n", a->track->title.ptr); // IDprintf("%s %d\n", a->track->position->raw.ptr, a->track->position->number); // 10 10printf("%s\n", b->track->title.ptr); // Stigmatrackparse_tracklist_free(md);Right next to the time, a run of one or two * or _ is read as emphasis by its position, with or
without a partner, so **14:21 Artist - Title still has its time. Anywhere else, a * or _ only
counts when it has a partner on the same line and its outer side is a space, a bracket, another *
or _, or the end of the line. So names keep their stars and underscores: P*nk, *NSYNC, DJ_Name, Noisia_-_Stigma and a censored F**k come out as
written. Runs of three or more, ~~, || and backticks are never treated as Markdown
(R13.12).
Layered tracks
Section titled “Layered tracks”DJ tracklists mark a track played over the previous one, like an acapella on the second deck, with
w/ where the track number would go. Such a line gets layered: true. The w/ stays in rest and
is left out of the parsed track. An untimed layered line plays at the previous track's time, so it
doesn't warn time-missing,
and it doesn't count as a neighbor for bare track numbers. Open the
example in the
playground.
const layers = parseTracklist("00:00 Noisia - Stigma\nw/ Phace - Psycho (Acapella)\n03:10 Mefjus - Sleepless");const e = layers.entries[1];
e.layered; // truee.time; // nulle.track.artists.map((a) => a.name); // [ 'Phace' ]e.track.title; // 'Psycho'layers.warnings; // []layers = parse_tracklist("00:00 Noisia - Stigma\nw/ Phace - Psycho (Acapella)\n03:10 Mefjus - Sleepless")e = layers.entries[1]
e.layered # Truee.time # None[a.name for a in e.track.artists] # ['Phace']e.track.title # 'Psycho'layers.warnings # ()let layers = parse_tracklist("00:00 Noisia - Stigma\nw/ Phace - Psycho (Acapella)\n03:10 Mefjus - Sleepless");let e = &layers.entries[1];
e.layered; // true&e.time; // Nonelet track = e.track.as_ref().unwrap();track.artists.iter().map(|a| &a.name).collect::<Vec<_>>(); // ["Phace"]&track.title; // "Psycho"&layers.warnings; // []layers := trackparse.ParseTracklist("00:00 Noisia - Stigma\nw/ Phace - Psycho (Acapella)\n03:10 Mefjus - Sleepless")e := layers.Entries[1]
fmt.Println(e.Layered) // truefmt.Println(e.Time == nil) // truenames = nilfor _, a := range e.Track.Artists { names = append(names, a.Name)}fmt.Printf("%q\n", names) // ["Phace"]fmt.Printf("%q\n", e.Track.Title) // "Psycho"fmt.Println(len(layers.Warnings)) // 0trackparse_tracklist *layers = trackparse_parse_tracklist( "00:00 Noisia - Stigma\nw/ Phace - Psycho (Acapella)\n03:10 Mefjus - Sleepless", TRACKPARSE_NUL_TERMINATED);const trackparse_entry *e = &layers->entries[1];
printf("%d\n", e->layered); // 1printf("%d\n", e->time == NULL); // 1for (size_t i = 0; i < e->track->artists_count; i++) { printf("%s\n", e->track->artists[i].name.ptr);}// Phaceprintf("%s\n", e->track->title.ptr); // Psychoprintf("%zu\n", layers->warnings_count); // 0trackparse_tracklist_free(layers);Only w/ (or W/) at the start of the track text, after any time or bullet, and followed by
whitespace and a track counts, so 00:30 w/ Phace - Psycho is layered too. w/ inside a line
(Noisia w/ Phace - Stigma), right after a track number (10. w/ …) or glued to the name
(w/Noisia) is left alone, and so are with, + and x
(R13.13).
Line kinds
Section titled “Line kinds”| Kind | When |
|---|---|
track |
a timed line, or an untimed line with an artist/title separator |
marker |
no separator and a word like intro, outro, break or interview |
header |
an untimed line ending in :, or something like Part 2 or Hour 2 |
link |
starts with http://, https:// or www. |
note |
any other untimed line |
blank |
empty or only whitespace |
Only track and marker entries have a track. No line is ever dropped. In Rust the kind is the
enum EntryKind (EntryKind::Track, EntryKind::Marker
and so on), in Go the string type EntryKind (trackparse.EntryKindTrack,
trackparse.EntryKindMarker), in C the enum trackparse_entry_kind (TRACKPARSE_ENTRY_TRACK,
TRACKPARSE_ENTRY_MARKER). The marker words are in
marker-words.json. The kinds are
R13.3.
Options
Section titled “Options”parseTracklist takes the parse options mode
(default "tracklist"), knownArtists, splitAnd and keywords, plus two of its own
(snake_case keyword arguments in Python, setters of TracklistOptions
in Rust, fields of TracklistOptions in Go, setters of a
trackparse_tracklist_options handle in C). audioSeconds is the length
of the audio, and turns on the check for times after the end. markerWords adds marker words to
the built-in ones (R13.10):
const mix = parseTracklist("00:00 Intro\n03:00 Drop\n1:02:03 Noisia - Stigma", { audioSeconds: 3600, markerWords: ["drop"],});
mix.entries.map((e) => e.kind); // [ 'marker', 'marker', 'track' ]mix.warnings;// [ { code: 'time-after-audio-end', line: 3, severity: 'warning', suggestion: null } ]mix = parse_tracklist( "00:00 Intro\n03:00 Drop\n1:02:03 Noisia - Stigma", audio_seconds=3600, marker_words=["drop"],)
[e.kind for e in mix.entries] # ['marker', 'marker', 'track']mix.warnings# (TracklistWarning(code='time-after-audio-end', line=3, severity='warning', suggestion=None),)use trackparse::tracklist::{parse_tracklist_with, TracklistOptions};
let options = TracklistOptions::new().audio_seconds(3600.0).marker_words(["drop"]);let mix = parse_tracklist_with("00:00 Intro\n03:00 Drop\n1:02:03 Noisia - Stigma", &options);
mix.entries.iter().map(|e| e.kind).collect::<Vec<_>>(); // [Marker, Marker, Track]&mix.warnings;// [TracklistWarning { code: TimeAfterAudioEnd, line: 3, severity: Warning, suggestion: None }]options := trackparse.TracklistOptions{AudioSeconds: trackparse.Ptr(3600.0), MarkerWords: []string{"drop"}}mix := trackparse.ParseTracklistWith("00:00 Intro\n03:00 Drop\n1:02:03 Noisia - Stigma", options)
kinds = nilfor _, e := range mix.Entries { kinds = append(kinds, e.Kind)}fmt.Println(kinds) // [marker marker track]for _, w := range mix.Warnings { fmt.Println(w.Code, w.Line, w.Severity, w.Suggestion == nil)}// time-after-audio-end 3 warning truetrackparse_tracklist_options *options = trackparse_tracklist_options_new();trackparse_tracklist_options_set_audio_seconds(options, 3600);trackparse_tracklist_options_add_marker_word(options, "drop", TRACKPARSE_NUL_TERMINATED);trackparse_tracklist *mix = trackparse_parse_tracklist_with( "00:00 Intro\n03:00 Drop\n1:02:03 Noisia - Stigma", TRACKPARSE_NUL_TERMINATED, options);
for (size_t i = 0; i < mix->entries_count; i++) { printf("%s%s", i ? " " : "", trackparse_entry_kind_name(mix->entries[i].kind));}printf("\n"); // marker marker trackfor (size_t i = 0; i < mix->warnings_count; i++) { const trackparse_tracklist_warning *w = &mix->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-after-audio-end 3 warning 1trackparse_tracklist_free(mix);trackparse_tracklist_options_free(options);Without markerWords, 03:00 Drop is a track line with no separator, and it warns line-unparsed.
The options are listed under Tracklist API. The
playground has a field for audioSeconds but none for markerWords, so
this link shows
both warnings.
Checks
Section titled “Checks”The warnings of the first list:
list.warnings;// [// { code: 'no-start-at-zero', line: 2, severity: 'info', suggestion: null },// { code: 'time-out-of-order', line: 8, severity: 'warning',// suggestion: { line: 8, raw: '01:11:02', seconds: 4262 } }// ]tl.warnings# (TracklistWarning(code='no-start-at-zero', line=2, severity='info', suggestion=None),# TracklistWarning(code='time-out-of-order', line=8, severity='warning',# suggestion=Suggestion(line=8, raw='01:11:02', seconds=4262)))&list.warnings;// [TracklistWarning { code: NoStartAtZero, line: 2, severity: Info, suggestion: None },// TracklistWarning { code: TimeOutOfOrder, line: 8, severity: Warning,// suggestion: Some(Suggestion { line: 8, raw: "01:11:02", seconds: 4262.0 }) }]for _, w := range list.Warnings { fmt.Println(w.Code, w.Line, w.Severity) if w.Suggestion != nil { fmt.Printf("%+v\n", *w.Suggestion) }}// no-start-at-zero 2 info// time-out-of-order 8 warning// {Line:8 Raw:01:11:02 Seconds:4262}for (size_t i = 0; i < list->warnings_count; i++) { const trackparse_tracklist_warning *w = &list->warnings[i]; printf("%s %d %s\n", trackparse_tracklist_warning_code_name(w->code), w->line, trackparse_severity_name(w->severity)); if (w->suggestion) { printf("line %d: %s (%g)\n", w->suggestion->line, w->suggestion->raw.ptr, w->suggestion->seconds); }}// no-start-at-zero 2 info// time-out-of-order 8 warning// line 8: 01:11:02 (4262)trackparse_tracklist_free(list);00:11:02 sits between 01:07:44 and 01:15:36. Changing one digit gives exactly one time that
fits, 01:11:02, so the warning carries it as a suggestion. When several fixes would fit, or none
does, suggestion is null (None, nil in Go, NULL in C) and you only get the warning. The checks are
R13.7, and Suggestions
describes the search.
Sometimes the typo is on the line before. In 01:22:21 followed by 01:03:55, the second line is
flagged, but the suggestion is to change the first one to 01:02:21. All the codes are listed in
Warnings, with an example of handling them in
each language. To apply a suggestion, see
Editing tracklists.
Bare track numbers
Section titled “Bare track numbers”Some lists number their lines without a dot: 1 Artist - Title, 2 Artist - Title. A single
parse() call would read 1 Artist as the artist's name, and it should, because 2 Unlimited
exists. In a list, trackparse looks at the neighbors: a bare number counts as a position when the
nearest line before or after it carries the next or previous number
(R13.5).
Tracklist mode
Section titled “Tracklist mode”Inside a tracklist, the first - is the separator on almost every line, so each line is
parsed with mode: "tracklist" (Modes). These lines all go wrong with a plain parse() and right in a list:
| Line | parse(line) |
In a tracklist |
|---|---|---|
Electrosoul System - Liquid Metal |
title Electrosoul System, Liquid Metal as genre junk |
Electrosoul System / Liquid Metal |
Effector - 2012 |
title Effector, year 2012 |
Effector / 2012 |
Paperclip - Anticipation VIP |
title Paperclip, a vip version |
Paperclip / Anticipation VIP |
8 Linkin Park_-_Points Of Authority (Gydra Bootleg) |
no separator | position 8, Linkin Park / Points Of Authority, bootleg by Gydra |
10 Optiv & BTK-Inception (Gydra remix) |
no separator | position 10, Optiv, BTK / Inception, remix by Gydra |
The first three open in the playground in tracklist mode; set the mode back to auto there to see
what a plain parse() makes of them. The last two need neighbors: the position needs a 7 or 9 next to it, and the unspaced
BTK-Inception dash only splits on a timed line when at least half the list uses spaced dashes.
Labels in a list
Section titled “Labels in a list”Radio show lists often end each line with the record label after a bullet. Each line's track gets
it as label, with a note after a
second bullet in junk. A line with a bullet but no dash is not cut: its track part has no
separator, so it gets a line-unparsed
warning as it would without the bullet.
const radio = parseTracklist([ "00:00 VISION Radio Intro", "00:48 Tom Finster - Age Of Spin • WEAREHUMANS", "12:57 KROON ‘All The King’s Men’ EP Minimix • VISION", "52:29 Noisia - concussion • VISION • VISION RADIO RELOAD",].join("\n"));
radio.entries.map((e) => e.track?.label ?? null); // [ null, 'WEAREHUMANS', null, 'VISION' ]radio.entries[3].track.junk; // [ { raw: 'VISION RADIO RELOAD', kind: 'note' } ]radio.warnings.map((w) => `${w.code} on line ${w.line}`); // [ 'line-unparsed on line 3' ]radio = parse_tracklist("\n".join([ "00:00 VISION Radio Intro", "00:48 Tom Finster - Age Of Spin • WEAREHUMANS", "12:57 KROON ‘All The King’s Men’ EP Minimix • VISION", "52:29 Noisia - concussion • VISION • VISION RADIO RELOAD",]))
[e.track.label if e.track else None for e in radio.entries] # [None, 'WEAREHUMANS', None, 'VISION']radio.entries[3].track.junk # (Junk(raw='VISION RADIO RELOAD', kind='note'),)[f"{w.code} on line {w.line}" for w in radio.warnings] # ['line-unparsed on line 3']let radio = parse_tracklist(&[ "00:00 VISION Radio Intro", "00:48 Tom Finster - Age Of Spin • WEAREHUMANS", "12:57 KROON ‘All The King’s Men’ EP Minimix • VISION", "52:29 Noisia - concussion • VISION • VISION RADIO RELOAD",].join("\n"));
radio.entries.iter().map(|e| e.track.as_ref().and_then(|t| t.label.as_deref())).collect::<Vec<_>>();// [None, Some("WEAREHUMANS"), None, Some("VISION")]&radio.entries[3].track.as_ref().unwrap().junk; // [Junk { raw: "VISION RADIO RELOAD", kind: Note }]radio.warnings.iter().map(|w| format!("{} on line {}", w.code, w.line)).collect::<Vec<_>>();// ["line-unparsed on line 3"]radio := trackparse.ParseTracklist(strings.Join([]string{ "00:00 VISION Radio Intro", "00:48 Tom Finster - Age Of Spin • WEAREHUMANS", "12:57 KROON ‘All The King’s Men’ EP Minimix • VISION", "52:29 Noisia - concussion • VISION • VISION RADIO RELOAD",}, "\n"))
for _, e := range radio.Entries { if e.Track != nil && e.Track.Label != nil { fmt.Println(e.Line, *e.Track.Label) }}// 2 WEAREHUMANS// 4 VISIONfmt.Printf("%+v\n", radio.Entries[3].Track.Junk) // [{Raw:VISION RADIO RELOAD Kind:note}]for _, w := range radio.Warnings { fmt.Println(w.Code, "on line", w.Line)}// line-unparsed on line 3trackparse_tracklist *radio = trackparse_parse_tracklist( "00:00 VISION Radio Intro\n" "00:48 Tom Finster - Age Of Spin • WEAREHUMANS\n" "12:57 KROON ‘All The King’s Men’ EP Minimix • VISION\n" "52:29 Noisia - concussion • VISION • VISION RADIO RELOAD", TRACKPARSE_NUL_TERMINATED);
for (size_t i = 0; i < radio->entries_count; i++) { const trackparse_track *t = radio->entries[i].track; if (t && t->label) printf("%zu %s\n", i + 1, t->label->ptr);}// 2 WEAREHUMANS// 4 VISIONconst trackparse_junk *note = &radio->entries[3].track->junk[0];printf("%s: %s\n", note->kind_name.ptr, note->raw.ptr); // note: VISION RADIO RELOADfor (size_t i = 0; i < radio->warnings_count; i++) { printf("%s on line %d\n", trackparse_tracklist_warning_code_name(radio->warnings[i].code), radio->warnings[i].line);}// line-unparsed on line 3trackparse_tracklist_free(radio);A bullet that starts a line is a list bullet, not a label separator: • Noisia - Stigma • VISION
has • in parts.lead and the label VISION. After a time it is part of the
track text (00:00 • Noisia - Stigma • VISION gives the artist • Noisia). A timed line without a
dash stays a marker (05:00 Intro • VISION). Open this list in the playground
to see the labels in the table.
A Tracklist (R13.8) serializes like a single track: JSON.stringify(list) in JavaScript,
tl.to_dict() in Python, list.to_json() in Rust, json.Marshal(list) in Go and trackparse_tracklist_to_json(list) in C give the same JSON, with camelCase keys such
as specVersion and firstTime. See
Serializing to JSON.
- Editing tracklists: fix times, shift, sort, insert and delete lines.
- Tracklist API: every field and option.
- Warnings: every code and what to do with it.
- Modes: the single-line mode every entry is parsed in.