Introduction
trackparse reads the names of music tracks the way people write them: store metadata, YouTube titles, file names, scrobbles, the tracklist under a mix. It gives you back an object with the artists and their roles, the clean title, every remix or version with its credits, and the noise that was around it.
It comes as five packages with the same behaviour: trackparse on
npm for JavaScript and TypeScript, trackparse on
PyPI for Python, trackparse on
crates.io for Rust, the module
github.com/4matic/trackparse/go for Go,
and a C library with one header,
trackparse.h, released
as a source tarball and an amalgamation on each
GitHub Release from 0.7.1 on. Every example on
this site has a tab for each language. The API docs of the Rust crate are on
docs.rs, and those of the Go module on
pkg.go.dev.
Here is what trackparse finds in one line (try it in the playground):
01. Wilkinson ft. Becky Hill & Tom Cane - Afterglow (Sub Focus VIP Remix) [Official Video]└┬┘ └───┬───┘ └───────────┬───────────┘ └───┬───┘ └─────────┬─────────┘ └───────┬──────┘ │ │ │ │ │ │ position 1 featured ×2 title remix · Sub Focus · vip │ │ primary junk: videoThe one rule
Section titled “The one rule”Extract, don't delete. Everything trackparse recognizes goes into a field. Everything it doesn't recognize stays in the title, verbatim.
Other parsers do less, or more than you want. Some return two strings and leave the rest to you.
Others strip anything in brackets, which turns (I Can't Get No) Satisfaction into Satisfaction
and loses every remix credit. trackparse would rather leave an odd bracket in the title than throw
away something you needed.
The same rule shows up in smaller ways:
[Official Video]leaves the title, but it lands injunkas{ raw: "Official Video", kind: "video" }. An unknown bracket stays in the title as written (R5.8).- When the parser had to guess (an unspaced dash, a
"Title" by Artistpattern),warningssays which guess it made. The codes are listed under Warnings. - Every key of the output is always present, so you never have to check whether a field exists (the output model).
- No string makes it fail.
parsenever throws in JavaScript or Python, never panics in Rust or Go, and in C returnsNULLonly when memory runs out (R0.8).
What you get back
Section titled “What you get back”import { parse } from "trackparse";
parse("Queen - Bohemian Rhapsody (Live at Wembley 1986)");from trackparse import parse
parse("Queen - Bohemian Rhapsody (Live at Wembley 1986)").to_dict()use trackparse::parse;
parse("Queen - Bohemian Rhapsody (Live at Wembley 1986)").to_json();import ( "encoding/json" "fmt"
"github.com/4matic/trackparse/go")
data, _ := json.Marshal(trackparse.Parse("Queen - Bohemian Rhapsody (Live at Wembley 1986)"))fmt.Println(string(data))#include <trackparse.h>
trackparse_track *t = trackparse_parse("Queen - Bohemian Rhapsody (Live at Wembley 1986)", TRACKPARSE_NUL_TERMINATED);trackparse_string *json = trackparse_track_to_json(t);printf("%s\n", json->str.ptr); // {"input":"Queen - Bohemian Rhapsody (Live at Wembley 1986)","mode":"clean",…}trackparse_string_free(json);trackparse_track_free(t);{ "input": "Queen - Bohemian Rhapsody (Live at Wembley 1986)", "mode": "clean", "position": null, "timestamp": null, "artists": [{ "name": "Queen", "role": "primary", "joiner": null, "source": "artist" }], "title": "Bohemian Rhapsody", "fullTitle": "Bohemian Rhapsody (Live at Wembley 1986)", "versions": [ { "type": "live", "raw": "Live at Wembley 1986", "artists": [], "modifiers": [], "descriptor": "at Wembley", "year": 1986, "unknownArtist": false, "delimiter": "(" } ], "year": null, "label": null, "flags": { "explicit": false, "clean": false, "unknownArtist": false, "unknownTitle": false }, "junk": [], "warnings": []}All five give this JSON: the packages pass the same fixtures and give the same output on every
fixture input (Ports has the one Unicode
note). In JavaScript the result is a plain object. In Python it is a frozen
dataclass with snake_case attributes, and to_dict() turns it into the JSON above. In Rust it is a
struct with snake_case fields, and to_json() writes that JSON as a string. In Go it is a struct
with exported CamelCase fields, and json.Marshal writes that JSON. In C it is a read-only
struct with snake_case members that owns its memory, and trackparse_track_to_json writes that
JSON. The parse reference explains every field, and
Serializing to JSON shows the round trip in each
language. Try this track in the playground.
Names in each language
Section titled “Names in each language”The docs use the JavaScript and JSON names in running text. Python and Rust use snake_case for the
same things, Go uses exported CamelCase, and C prefixes every name with trackparse_:
| What | JavaScript |
|---|---|
| Parse | parse(s, options?) |
| A field | track.fullTitle |
| An option | { knownArtists: […] } |
| A value | "remix", null |
| Lists | arrays |
| JSON | JSON.stringify(track) |
| What | Python |
|---|---|
| Parse | parse(s, **options) |
| A field | track.full_title |
| An option | known_artists=[…] |
| A value | "remix", None |
| Lists | tuples |
| JSON | track.to_dict() |
| What | Rust |
|---|---|
| Parse | parse(s), parse_with(s, &options) |
| A field | track.full_title |
| An option | ParseOptions::new().known_artists([…]) |
| A value | VersionType::Remix, None |
| Lists | Vec |
| JSON | track.to_json(), or serde |
| What | Go |
|---|---|
| Parse | Parse(s), ParseWith(s, options) |
| A field | track.FullTitle |
| An option | ParseOptions{KnownArtists: …} |
| A value | VersionTypeRemix, nil |
| Lists | slices |
| JSON | json.Marshal(track) |
| What | C |
|---|---|
| Parse | trackparse_parse(s, len), trackparse_parse_with(s, len, options) |
| A field | track->full_title |
| An option | trackparse_parse_options_add_known_artist |
| A value | TRACKPARSE_VERSION_REMIX, NULL |
| Lists | a pointer and a _count |
| JSON | trackparse_track_to_json(track) |
Other functions has the full table of function names.
Spec first
Section titled “Spec first”Behaviour isn't defined by the JavaScript code. It's defined by a written spec with numbered rules (R0 to R13), and by 13,565 fixtures that pin those rules down. The JavaScript package is the reference implementation. The Python package, the Rust crate, the Go module and the C library pass the same fixtures and produce the same JSON, byte for byte, on every fixture input. How it's tested and Ports have the details.
If you wonder why something parses the way it does, there's a rule ID for it, and a fixture that cites that rule.
When not to use it
Section titled “When not to use it”If all you need is a cleaned-up string to send to a scrobbler, metadata-filter is a fine choice and smaller in scope. trackparse is for when you need to know who did what.
It also has no artist database. & is a joiner, so Chase & Status comes out as two artists unless
you pass it in knownArtists (known_artists in Python and Rust, KnownArtists in Go, trackparse_parse_options_add_known_artist in C). More on that in
Artists and credits. The other gaps are listed under
Limitations and roadmap.
- Getting started: install it and parse your first track.
- How it works: the pipeline behind the result.
- What it understands: real inputs and their results.
- Playground: try your own strings in the browser.