Skip to content

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: video

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 in junk as { 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 Artist pattern), warnings says 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. parse never throws in JavaScript or Python, never panics in Rust or Go, and in C returns NULL only when memory runs out (R0.8).
import { parse } from "trackparse";
parse("Queen - Bohemian Rhapsody (Live at Wembley 1986)");
{
"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.

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)

Other functions has the full table of function names.

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.

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.