trackparse
Documentation · Getting started · Playground · API on docs.rs
Turn messy track names into structured data: who made it, who's featured, who remixed it, and what's just noise.
01. Wilkinson ft. Becky Hill & Tom Cane - Afterglow (Sub Focus VIP Remix) [Official Video]
Most title parsers split that into "Wilkinson ft. Becky Hill & Tom Cane" and
"Afterglow (Sub Focus VIP Remix)" and stop. Others "clean" it and throw the feat and the remix
away. trackparse keeps all of it. Everything it recognizes goes into a field, and anything it
doesn't recognize stays in the title, word for word.
This is the Rust port of trackparse. Its behaviour is defined by a shared spec and pinned by 13,130 fixtures. It passes all of them, and for every fixture input its output is byte-identical to the JavaScript and Python packages.
- Rust 1.74 or later (the minimum supported version; CI runs the test suite on 1.74 and on stable)
- One dependency (
unicode-normalization);serdeis optional - No
unsafe, no regular expressions - Never panics and never returns an error: any
&strgives a result
Install
# with Serialize / Deserialize on the types
Quick start
Docs: Getting started
use ;
let track = parse;
let credits: = track.artists.iter.map.collect;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let options = new.joiners;
assert_eq!;
to_json() returns the spec's JSON form as compact text, with the same camelCase keys the
JavaScript package uses:
let track = parse;
println!;
(Reformatted for width; the keys and values are exactly what to_json() returns.)
API
Docs: Other functions
parse(input: &str) -> ParsedTrack
parse_with(input: &str, options: &ParseOptions) -> ParsedTrack
parse_artists(input: &str) -> Vec<Artist>
parse_artists_with(input: &str, options: &ParseOptions) -> Vec<Artist>
format_track(track: &ParsedTrack) -> String
format_track_with(track: &ParsedTrack, options: &FormatOptions) -> String
normalize(input: &str) -> String
all_artists(track: &ParsedTrack) -> Vec<Artist>
Parser::new(options: &ParseOptions) -> Parser // parser.parse(..), parser.parse_artists(..)
SPEC_VERSION: &str
tracklist::parse_tracklist(text: &str) -> Tracklist
tracklist::parse_tracklist_with(text: &str, options: &TracklistOptions) -> Tracklist
tracklist::apply_edits(text: &str, edits: &[Edit]) -> EditResult
tracklist::apply_edits_with(text: &str, edits: &[Edit], options: &TracklistOptions) -> EditResult
Every function has a plain form with the default options and a _with form that takes them.
parse and ParseOptions
Docs: parse and ParsedTrack · Options
| Option | Default | |
|---|---|---|
mode |
ModeOption::Auto |
Clean, Youtube, Filename, Tracklist, or Auto to detect from the string. See Modes |
uploader |
None |
YouTube channel name, used as the artist when there's no separator (- Topic and VEVO are dropped) |
known_artists |
empty | Names that are never split. There is no built-in list |
split_and |
SplitAnd::Auto |
Auto splits on and only after a comma (A, B and C), so Simon and Garfunkel stays whole. Also Always, Never |
keywords |
None |
Extra vocabulary, added to the built-in lists (see below) |
Options are built with chained setters. The structs are #[non_exhaustive], so start from
ParseOptions::new() (or default()); the fields are public and can also be assigned.
use ;
let names = ;
assert_eq!;
let options = new.known_artists;
assert_eq!;
let options = new.split_and;
assert_eq!;
KeywordOptions adds words to the built-in lists:
| Setter | Field | |
|---|---|---|
version_head(word, VersionType) |
version_heads |
Word that sets a version type ("rerub" as VersionType::Rework) |
descriptor(word) |
descriptors |
Words kept as a version's descriptor |
genre(word) |
genres |
Genre words |
junk(phrase, JunkKind) |
junk |
Phrase to junk kind ("some label rip" as JunkKind::Label) |
feat_marker(marker) |
feat_markers |
Extra feat markers |
use ;
assert_eq!;
let keywords = new.junk;
let track = parse_with;
assert_eq!;
assert_eq!;
assert_eq!;
ParsedTrack
Docs: ParsedTrack fields
| Field | Type | |
|---|---|---|
input |
String |
The original string, untouched |
mode |
Mode |
Resolved mode: Clean, Youtube, Filename or Tracklist |
position |
Option<Position> |
Track number: Position { raw: "01", number: 1 } |
timestamp |
Option<Timestamp> |
Leading cue time: [12:34] gives Timestamp { raw: "12:34", seconds: 754 } |
artists |
Vec<Artist> |
Primary, featured and producer credits. Remixers live in versions |
title |
String |
Clean title. Brackets it doesn't recognize stay in |
full_title |
String |
title with the versions re-attached |
versions |
Vec<Version> |
Remixes and other versions, left to right |
year |
Option<u32> |
From (2015) or - 2015 |
flags |
Flags |
explicit, clean, unknown_artist, unknown_title |
junk |
Vec<Junk> |
What was taken out, each with a kind |
warnings |
Vec<Warning> |
Heuristics that fired |
Artist { name, role, joiner, source }:
roleisArtistRole::Primary,Featured,RemixerorProducer.joineris the text before the name as written ("&",",","ft.","prod. by"), orNonefor the first name in a list.sourceis where the credit came from:ArtistSource::Artist(left of the dash),Title(right of it) orVersion.
Version { version_type, raw, artists, modifiers, descriptor, year, unknown_artist, delimiter }
(version_type is type in JSON):
use ;
let track = parse;
let version = &track.versions;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let track = parse;
let version = &track.versions;
assert_eq!;
assert_eq!;
assert_eq!;
Version types, junk kinds, warnings, roles and modes are enums (VersionType, JunkKind,
Warning, ArtistRole, ArtistSource, Mode, ModeOption, VersionDelimiter), listed in the
API reference and on
docs.rs. Each has as_str() (the name
used in the spec and in JSON), from_name(), ALL, Display and FromStr:
use VersionType;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Most of these enums are #[non_exhaustive]: a later spec version can add a version type or a
warning, so a match on them needs a _ arm.
JSON and serde
Docs: Serializing to JSON
Every result type has to_json(), which writes compact JSON matching
parsed-track.schema.json
and
tracklist.schema.json
(fullTitle, unknownArtist, ...). The bytes are the same as JSON.stringify(parse(s)) in
JavaScript. It needs no feature and no dependency.
With the serde feature, the result types, the options and Edit implement Serialize and
Deserialize with the same keys, so serde_json writes the same text and reads it back:
use Edit;
use ;
let track = parse;
let json = to_string.unwrap;
assert_eq!;
assert_eq!;
let options: ParseOptions =
from_str.unwrap;
assert_eq!;
let edit: Edit = from_str.unwrap;
assert_eq!;
assert_eq!;
Numbers are written as to_json() writes them: whole seconds are integers (90, not 90.0), and
a value of 2^53 and more has the digits JavaScript prints. For every result the parser can produce
the two texts are equal. The edge cases, all in an Edit or an option you build yourself:
- Seconds from 0.000001 up to 0.00001 are written in
serde_json's float notation (1e-6whereto_json()writes0.000001), and so are seconds of 1e21 and more by olderserde_jsonreleases (1e21for1e+21). The number is the same and reads back the same. - Non-finite seconds (NaN, infinity) are written as
null, asto_json()andJSON.stringifydo, andnullreads back as NaN.apply_editsreports such an edit asEditInvalideither way. - Line numbers above 2^53 are written as the nearest double, because that is what the edit runs
on (
Edit::delete(usize::MAX)is{"op":"delete","line":18446744073709552000}). KeywordOptionsmaps are written as JSON objects without repeated keys: a key added twice keeps its first place and takes the last value, as in a JavaScript object.
Reading options is strict: a missing key is the default, an unknown name such as
"mode":"radio" is an error.
parse_artists
Docs: parseArtists · Artists and credits
Splits a bare artist string (no title). parse_artists_with takes the same options as parse_with.
use parse_artists;
let credits: = parse_artists
.iter
.map
.collect;
assert_eq!;
format_track and FormatOptions
Docs: format · Formatting
Renders a track back to a string.
| Option | Default | |
|---|---|---|
feat |
FeatPlacement::Source |
Where featured artists go: Source (where they were), Artist, Title ((feat. X) after the title) or Omit |
feat_marker |
None |
Marker for featured artists, such as "featuring" |
joiners |
JoinerStyle::Original |
Original keeps the joiners as written. Canonical writes and as &, vs as vs. and every feat marker as feat. |
versions |
VersionsOption::All |
All or None |
producers |
true |
Include (prod. ...) credits |
position |
false |
Include the track number (01. ) |
use ;
let track = parse;
assert_eq!;
let options = new.feat.joiners;
assert_eq!;
let options = new.feat.versions;
assert_eq!;
let options = new.position;
assert_eq!;
normalize
Docs: normalize
The Unicode cleanup every function runs first: NFC, zero-width spaces, BOM and soft hyphens removed, fullwidth brackets, smart quotes and dash variants mapped to ASCII, whitespace collapsed. Running it twice changes nothing.
use normalize;
assert_eq!;
all_artists
Docs: allArtists
Credits plus every remixer, deduplicated.
use ;
let track = parse;
let credits: =
all_artists.iter.map.collect;
assert_eq!;
Parser
Docs: createParser
Resolves the options and builds the word tables once, for many calls. It is Send + Sync.
use ;
let options = new
.known_artists
.keywords;
let parser = new;
let track = parser.parse;
assert_eq!;
assert_eq!;
SPEC_VERSION
The spec version this build implements, "0.5.0" in this release. It equals the crate version:
the crate, the npm package, the PyPI package and the spec are released together and always share
one version number.
Modes
Docs: Modes
| Mode | For | Adds |
|---|---|---|
Clean |
Store metadata, tags | Only a spaced dash separates artist and title |
Youtube |
Video titles, scrobbles | Pipe segments, "Title" by Artist, Artist: "Title", unspaced dashes, trailing junk, uploader fallback |
Filename |
Files | Strips the extension, _ becomes a space, 01-Track numbering |
Auto |
Anything | Filename for known extensions, Youtube when it sees junk, pipes or platform suffixes, Clean otherwise |
Tracklist |
One line of a tracklist | The first spaced dash always separates; _-_ too. Never picked by Auto |
use ;
let youtube = new.mode;
let track = parse_with;
assert_eq!;
assert_eq!;
assert_eq!;
let track = parse;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let track = parse_with;
assert_eq!;
Warnings
Docs: Warnings
The parser never fails, but it says when it had to guess. track.warnings is a Vec<Warning>,
empty when every decision was unambiguous. as_str() gives the name used in the spec and in JSON.
| Warning | JSON name | Means |
|---|---|---|
NoSeparator |
noSeparator |
No artist/title separator was found. The whole string is the title |
AmbiguousSeparator |
ambiguousSeparator |
A two-part pipe title with no dash was read as artist and title |
UnspacedDashSplit |
unspacedDashSplit |
Split at a dash without spaces around it |
AsymmetricDashSplit |
asymmetricDashSplit |
Split at a dash with a space on one side only |
BySplit |
bySplit |
Read "Title" by Artist |
QuotedTitleSplit |
quotedTitleSplit |
Took a quoted span as the title and the text before it as the artist |
AmbiguousMixCredit |
ambiguousMixCredit |
<Name> Mix was read as a remix, but the name is long enough to be a style |
UnbalancedBrackets |
unbalancedBrackets |
A bracket was opened and never closed |
use ;
let track = parse;
assert!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Tracklists have their own warnings, with line numbers. They are listed under Tracklists.
Tracklists
Docs: Tracklists · Editing tracklists · Tracklist API · Warnings
trackparse::tracklist parses a whole tracklist, one entry per line, and checks it. Each entry
keeps its line exactly as written plus its own line ending, so joining every raw and eol is
always the input, CRLF or not.
use ;
use VersionType;
let text =
.join;
let list = parse_tracklist;
let joined: String = list.entries.iter.map.collect;
assert_eq!;
use ;
let kinds: = list.entries.iter.map.collect;
assert_eq!;
let entry = &list.entries;
let time = entry.time.as_ref.unwrap;
assert_eq!;
assert_eq!;
let track = entry.track.as_ref.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert!; // the ID
assert_eq!;
assert_eq!;
assert_eq!;
let warning = &list.warnings;
assert_eq!;
let fix = warning.suggestion.as_ref.unwrap;
assert_eq!;
let stats = &list.stats;
assert_eq!;
assert_eq!;
The suggestion exists because exactly one time, one digit away from 00:11:02, fits between its
neighbours. With several candidates or none, suggestion is None.
apply_edits takes a slice of Edit values and only rewrites the lines they name:
use ;
let text = "48:20 Noisia - Stigma\r\n59:31 Alix Perez - Fade Away\r\n00:03:10 Imanu - Sacrifice\r\n";
let edits = ;
let result = apply_edits;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let result = apply_edits;
assert_eq!;
A rewritten time keeps its line's style: 48:20 stays MM:SS, and a time that crosses the hour
gets hours, with a style-upgraded warning. A time pushed below zero stops at zero and warns
time-clamped. A bad edit changes nothing and warns edit-invalid.
TracklistOptions has mode (default ModeOption::Tracklist), known_artists, split_and,
keywords, audio_seconds (enables time-after-audio-end) and marker_words:
use ;
let options = new.audio_seconds;
let list = parse_tracklist_with;
assert_eq!;
assert_eq!;
| Result | Fields |
|---|---|
Tracklist |
spec_version, entries, warnings, stats |
TracklistEntry |
line (1-based), kind (EntryKind: Track, Marker, Header, Link, Note, Blank), eol, raw, parts, time, track (Option<ParsedTrack>), layered (the track text after any time starts with w/) |
Parts |
lead, time, gap, rest, joined they give raw |
TracklistWarning |
code (WarningCode), line, severity (Info or Warning), suggestion |
TimeValue |
raw, seconds (entry.time, or None on untimed lines) |
Suggestion |
line, raw, seconds (warning.suggestion, or None) |
Stats |
lines, tracks, markers, timed, first_time, last_time |
EditResult |
text, changed, warnings (EditWarning { code, edit, line }) |
Lists pasted with list bullets or Markdown emphasis (* 14:21 Artist - Title,
**[**14:21**] Artist - Title**) read like plain lines; the decoration stays in raw and parts.
A line whose track text (after any time) starts with w/ is layered: a track played over the
previous one
(Markdown,
layered tracks).
Warning codes (WarningCode): time-missing, time-out-of-order, time-duplicate,
no-start-at-zero, time-after-audio-end (needs audio_seconds), invalid-time, position-gap,
position-duplicate, line-unparsed. Edits: Edit::set_time(line, seconds),
Edit::shift(seconds) (all timed lines), Edit::shift_from(seconds, from),
Edit::shift_lines(seconds, lines), Edit::sort_by_time(), Edit::set_rest(line, rest),
Edit::insert(after, text) (after: 0 inserts at the top), Edit::delete(line). The
Tracklist API reference explains each
one, and the rules are in
SPEC R13.
Every line is parsed with ModeOption::Tracklist, where the first spaced dash always separates
artist and title. parse_with accepts it too:
use ;
let track = parse;
assert_eq!;
assert_eq!;
let options = new.mode;
assert_eq!;
Errors
No function returns a Result and none panics. parse gives a complete ParsedTrack for any
&str, "" included, and parse_tracklist and apply_edits return for any text. Options are
typed, so a wrong value does not compile. apply_edits reports an edit it cannot apply (a line
that does not exist, non-finite seconds) as an EditWarningCode::EditInvalid warning and leaves
the text alone.
The only fallible calls are conversions from text: FromStr on the enums returns UnknownName
for a name the spec does not have, and with the serde feature, deserializing options or edits
from JSON can fail as any serde type can.
How it is tested
Docs: How it's tested · Ports
cargo testruns all 13,130 shared fixtures (1,203 written by hand, the rest generated from the rules), the spec's invariants for single tracks and for tracklists on generated input (no panic in any mode,normalizeidempotent, the format round trip, no word lost, timing), and the API tests. The skip list is empty.scripts/compare-ports.mjsin the repository runs every fixture input through the JavaScript package and this crate and compares the complete JSON output, every field of it, not only the ones a fixture asserts. The Python package is checked the same way.- The Unicode facts the rules need (letters, uppercase letters, lowercase mapping) are tables generated from the reference implementation and compiled into the crate. The output does not depend on the compiler's Unicode version: Rust 1.74 and current stable give the same bytes. NFC and NFD are the exception, see Unicode version.
- With the
serdefeature, a test asserts thatserde_json::to_stringequalsto_json()for every fixture input. - Clippy denies
unwrap,expect,panic!and indexing in the library code, andunsafeis forbidden.
Unicode version
Normalization (NFC in normalize, NFD in the key that finds duplicate artists) comes from the
unicode-normalization crate and follows its Unicode version. This crate requires 0.1.26 or
later, which has the Unicode 18 tables; older releases have older tables and give other results
for some strings, so Cargo will not select them.
The JavaScript package normalizes with its runtime's tables, which are Unicode 17 on Node 24. Unicode 18 added 32 combining marks, so a string that contains one of them can come out with its marks in another order here than in JavaScript on that runtime. Strings without those marks are not affected, and every shared fixture gives the same bytes.
Performance
There are no regular expressions, so there is no regex backtracking. A 10,000-code-point input parses in under 20 ms in a release build. The test suite runs hostile repetitions of that length (thousands of duplicate credits, bracket groups or junk phrases) under a time ceiling.
Versioning
Changelog: rust/CHANGELOG.md
The crate version is the spec version (SPEC_VERSION). While it is 0.x, a release that changes
the output for some input bumps the minor version, and a patch release only fixes bugs. Cargo's
default requirement (trackparse = "0.5") already stays within one minor version, so cargo update
will not change your output. Read the changelog before moving to the next minor.
Other languages
Docs: Ports
The same parser exists for JavaScript and Python. All three implement one spec, pass the same fixtures, are released together under one version number, and return identical JSON for every fixture input. You can parse in one language and read the result in another. The one known difference is described under Unicode version.
| Language | Package | Install |
|---|---|---|
| JavaScript / TypeScript | trackparse on npm | npm install trackparse |
| Python | trackparse on PyPI | pip install trackparse |
| Rust | trackparse on crates.io | cargo add trackparse |
Limitations
Docs: Limitations and roadmap
parsetakes one track string. Whole tracklists go throughtrackparse::tracklist, which reads start times only: no durations, trailing times or time ranges.- Catalog numbers, key and BPM are not fields. They stay in the title.
- There is no artist database. Pass
known_artistsfor names that contain a joiner (Earth, Wind & Fire).
Development
From rust/ in the repository (Node 24 is needed for the
codegen script only):
TRACKPARSE_REPORT=1
Modules mirror the JS reference one to one (scanner.rs is scanner.ts, and so on) and cite the
same spec rule IDs. Behaviour changes start in the spec, not here: see
AGENTS.md.
Links
- Documentation, with every example in JavaScript, Python and Rust, and a playground that runs the parser in your browser
- API documentation on docs.rs
- Spec
- Changelog
- Project README
- GitHub repository
- npm package · PyPI package