Skip to content

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";

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.

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 }

Paste it into the playground to see the table, the warnings and the fix button.

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

parts 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.

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'

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).

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; // true
e.time; // null
e.track.artists.map((a) => a.name); // [ 'Phace' ]
e.track.title; // 'Psycho'
layers.warnings; // []

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).

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.

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 } ]

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.

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 } }
// ]

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.

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).

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.

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' ]

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.