Getting started
-
Install the package.
npm install trackparse # or: pnpm add / yarn add / bun add trackparseNode 18 or newer, or any runtime with ES2020. ESM and CommonJS both work, and the TypeScript types are included. The package is
trackparseon npm.pip install trackparse # or: uv add trackparsePython 3.9 or newer, no dependencies. The package ships
py.typedand passesmypy --strict. The package istrackparseon PyPI.cargo add trackparsecargo add trackparse --features serde # with Serialize and Deserialize on the typesRust 1.74 or newer. The only dependency is
unicode-normalization, and there is nounsafecode. The crate istrackparseon crates.io, and its API docs are on docs.rs.go get github.com/4matic/trackparse/go@latestGo 1.22 or newer, no dependencies. The package name is
trackparse. The API docs are on pkg.go.dev.include(FetchContent)FetchContent_Declare(trackparseURL https://github.com/4matic/trackparse/releases/download/c-v0.8.2/trackparse-c-0.8.2.tar.gzURL_HASH SHA256=… # the trackparse-c-0.8.2.tar.gz line of SHA256SUMS on the release)FetchContent_MakeAvailable(trackparse)target_link_libraries(my_app PRIVATE trackparse::trackparse)C11, no dependencies beyond libc,
libmand threads; it builds with GCC, Clang and MSVC. Each release from 0.7.1 on attaches the source tarball above (CMake 3.16 or newer),SHA256SUMSand an amalgamation to its GitHub Release. To build from a clone of the repository instead, follow the C README.cmake --installalso gives youfind_package(trackparse)and atrackparse.pcfor pkg-config. Without CMake, copytrackparse.candtrackparse.hfromtrackparse-c-0.8.2-amalgamation.zipinto your project and compile them with your sources (cc -std=c11 -DTRACKPARSE_STATIC main.c trackparse.c -lm -lpthread). The API is one header,trackparse.h, with a comment on every declaration. -
Parse a track with
parse(try it in the playground).import { parse } from "trackparse";// CommonJS: const { parse } = require("trackparse");const track = parse("Noisia feat. Foreign Beggars - Shellshock");track.title; // 'Shellshock'track.artists.map((a) => a.name); // [ 'Noisia', 'Foreign Beggars' ]track.artists[1].role; // 'featured'from trackparse import parsetrack = parse("Noisia feat. Foreign Beggars - Shellshock")track.title # 'Shellshock'[a.name for a in track.artists] # ['Noisia', 'Foreign Beggars']track.artists[1].role # 'featured'use trackparse::parse;let track = parse("Noisia feat. Foreign Beggars - Shellshock");track.title; // "Shellshock"track.artists.iter().map(|a| &a.name).collect::<Vec<_>>(); // ["Noisia", "Foreign Beggars"]track.artists[1].role; // Featuredimport ("fmt""github.com/4matic/trackparse/go")track := trackparse.Parse("Noisia feat. Foreign Beggars - Shellshock")fmt.Printf("%q\n", track.Title) // "Shellshock"names := []string{}for _, a := range track.Artists {names = append(names, a.Name)}fmt.Printf("%q\n", names) // ["Noisia" "Foreign Beggars"]fmt.Println(track.Artists[1].Role) // featured#include <trackparse.h>trackparse_track *track =trackparse_parse("Noisia feat. Foreign Beggars - Shellshock", TRACKPARSE_NUL_TERMINATED);printf("%s\n", track->title.ptr); // Shellshockfor (size_t i = 0; i < track->artists_count; i++) {printf("%s\n", track->artists[i].name.ptr);}// Noisia// Foreign Beggarsprintf("%s\n", trackparse_role_name(track->artists[1].role)); // featuredtrackparse_track_free(track);Input is UTF-8 with a byte length, or
TRACKPARSE_NUL_TERMINATEDfor a C string. The result owns its memory, so free it withtrackparse_track_free.trackparse_parsereturnsNULLonly when memory runs out; check for it in real code. -
Look at the versions and the noise.
const t = parse("Daft Punk - One More Time (Official Music Video) [HD]");t.title; // 'One More Time't.junk; // [ { raw: 'Official Music Video', kind: 'video' }, { raw: 'HD', kind: 'quality' } ]const r = parse("Dimension - Offshore (Mefjus Remix / Noisia Remix)");r.versions.map((v) => `${v.type} by ${v.artists[0].name}`);// [ 'remix by Mefjus', 'remix by Noisia' ]t = parse("Daft Punk - One More Time (Official Music Video) [HD]")t.title # 'One More Time't.junk # (Junk(raw='Official Music Video', kind='video'), Junk(raw='HD', kind='quality'))r = parse("Dimension - Offshore (Mefjus Remix / Noisia Remix)")[f"{v.type} by {v.artists[0].name}" for v in r.versions]# ['remix by Mefjus', 'remix by Noisia']let t = parse("Daft Punk - One More Time (Official Music Video) [HD]");&t.title; // "One More Time"&t.junk; // [Junk { raw: "Official Music Video", kind: Video }, Junk { raw: "HD", kind: Quality }]let r = parse("Dimension - Offshore (Mefjus Remix / Noisia Remix)");r.versions.iter().map(|v| format!("{} by {}", v.version_type, v.artists[0].name)).collect::<Vec<_>>();// ["remix by Mefjus", "remix by Noisia"]t := trackparse.Parse("Daft Punk - One More Time (Official Music Video) [HD]")fmt.Printf("%q\n", t.Title) // "One More Time"fmt.Printf("%+v\n", t.Junk) // [{Raw:Official Music Video Kind:video} {Raw:HD Kind:quality}]r := trackparse.Parse("Dimension - Offshore (Mefjus Remix / Noisia Remix)")for _, v := range r.Versions {fmt.Println(v.Type, "by", v.Artists[0].Name)}// remix by Mefjus// remix by Noisiatrackparse_track *t = trackparse_parse("Daft Punk - One More Time (Official Music Video) [HD]", TRACKPARSE_NUL_TERMINATED);printf("%s\n", t->title.ptr); // One More Timefor (size_t i = 0; i < t->junk_count; i++) {printf("%s: %s\n", t->junk[i].kind_name.ptr, t->junk[i].raw.ptr);}// video: Official Music Video// quality: HDtrackparse_track *r = trackparse_parse("Dimension - Offshore (Mefjus Remix / Noisia Remix)",TRACKPARSE_NUL_TERMINATED);for (size_t i = 0; i < r->versions_count; i++) {printf("%s by %s\n", r->versions[i].type_name.ptr, r->versions[i].artists[0].name.ptr);}// remix by Mefjus// remix by Noisiatrackparse_track_free(r); -
Tell it about names that contain a joiner with
knownArtists(try it).parse("Chase & Status - Baddadan").artists.map((a) => a.name);// [ 'Chase', 'Status' ]parse("Chase & Status - Baddadan", { knownArtists: ["Chase & Status"] }).artists.map((a) => a.name);// [ 'Chase & Status' ][a.name for a in parse("Chase & Status - Baddadan").artists]# ['Chase', 'Status'][a.name for a in parse("Chase & Status - Baddadan", known_artists=["Chase & Status"]).artists]# ['Chase & Status']use trackparse::{parse, parse_with, ParseOptions};parse("Chase & Status - Baddadan").artists.iter().map(|a| &a.name).collect::<Vec<_>>();// ["Chase", "Status"]let options = ParseOptions::new().known_artists(["Chase & Status"]);parse_with("Chase & Status - Baddadan", &options).artists.iter().map(|a| &a.name).collect::<Vec<_>>();// ["Chase & Status"]names = nilfor _, a := range trackparse.Parse("Chase & Status - Baddadan").Artists {names = append(names, a.Name)}fmt.Printf("%q\n", names) // ["Chase" "Status"]options := trackparse.ParseOptions{KnownArtists: []string{"Chase & Status"}}names = nilfor _, a := range trackparse.ParseWith("Chase & Status - Baddadan", options).Artists {names = append(names, a.Name)}fmt.Printf("%q\n", names) // ["Chase & Status"]trackparse_track *cs = trackparse_parse("Chase & Status - Baddadan", TRACKPARSE_NUL_TERMINATED);for (size_t i = 0; i < cs->artists_count; i++) {printf("%s\n", cs->artists[i].name.ptr);}// Chase// Statustrackparse_track_free(cs);trackparse_parse_options *options = trackparse_parse_options_new();trackparse_parse_options_add_known_artist(options, "Chase & Status", TRACKPARSE_NUL_TERMINATED);cs = trackparse_parse_with("Chase & Status - Baddadan", TRACKPARSE_NUL_TERMINATED, options);for (size_t i = 0; i < cs->artists_count; i++) {printf("%s\n", cs->artists[i].name.ptr);}// Chase & Statustrackparse_track_free(cs);trackparse_parse_options_free(options); -
Write it back with
format, or turn it into JSON.import { format } from "trackparse";format(t); // 'Daft Punk - One More Time'JSON.stringify(t); // '{"input":"Daft Punk - One More Time (Official Music Video) [HD]","mode":"youtube",…}'import jsonfrom trackparse import format_trackformat_track(t) # 'Daft Punk - One More Time'json.dumps(t.to_dict()) # '{"input": "Daft Punk - One More Time (Official Music Video) [HD]", "mode": "youtube", …}'use trackparse::format_track;format_track(&t); // "Daft Punk - One More Time"t.to_json(); // "{\"input\":\"Daft Punk - One More Time (Official Music Video) [HD]\",\"mode\":\"youtube\",…}"import "encoding/json"fmt.Println(trackparse.Format(t)) // Daft Punk - One More Timedata, _ := json.Marshal(t)fmt.Println(string(data)) // {"input":"Daft Punk - One More Time (Official Music Video) [HD]","mode":"youtube",…}trackparse_string *s = trackparse_format(t);printf("%s\n", s->str.ptr); // Daft Punk - One More Timetrackparse_string_free(s);trackparse_string *json = trackparse_track_to_json(t);printf("%s\n", json->str.ptr); // {"input":"Daft Punk - One More Time (Official Music Video) [HD]","mode":"youtube",…}trackparse_string_free(json);trackparse_track_free(t); -
Parse a whole tracklist.
import { parseTracklist } from "trackparse/tracklist";const list = parseTracklist("00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless (Phace Remix)");list.entries.map((e) => `${e.time.seconds}s ${e.track.title}`); // [ '0s Stigma', '250s Sleepless' ]list.warnings; // []from trackparse.tracklist import parse_tracklisttl = parse_tracklist("00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless (Phace Remix)")[f"{e.time.seconds}s {e.track.title}" for e in tl.entries] # ['0s Stigma', '250s Sleepless']tl.warnings # ()use trackparse::tracklist::parse_tracklist;let list = parse_tracklist("00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless (Phace Remix)");list.entries.iter().filter_map(|e| Some(format!("{}s {}", e.time.as_ref()?.seconds, e.track.as_ref()?.title))).collect::<Vec<_>>(); // ["0s Stigma", "250s Sleepless"]list.warnings; // []timeandtrackareOptions in Rust, because a blank line or a note has neither.list := trackparse.ParseTracklist("00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless (Phace Remix)")for _, e := range list.Entries {if e.Time != nil && e.Track != nil {fmt.Printf("%vs %s\n", e.Time.Seconds, e.Track.Title)}}// 0s Stigma// 250s Sleeplessfmt.Println(len(list.Warnings)) // 0TimeandTrackare pointers in Go,nilon a blank line or a note.trackparse_tracklist *list = trackparse_parse_tracklist("00:00 Noisia - Stigma\n04:10 Mefjus - Sleepless (Phace Remix)", TRACKPARSE_NUL_TERMINATED);for (size_t i = 0; i < list->entries_count; i++) {const trackparse_entry *e = &list->entries[i];if (e->time && e->track) printf("%gs %s\n", e->time->seconds, e->track->title.ptr);}// 0s Stigma// 250s Sleeplessprintf("%zu\n", list->warnings_count); // 0trackparse_tracklist_free(list);timeandtrackare pointers in C,NULLon a blank line or a note.
Where each task is explained
Section titled “Where each task is explained”| You want to | Read |
|---|---|
| see what kinds of input it reads | What it understands |
| read every field of the result | parse and ParsedTrack |
| pass options or your own keywords | Options, Modes |
| split a bare artist string | parseArtists, Artists and credits |
| write a track back as a string | Formatting |
| parse and check a tracklist | Tracklists, Tracklist API |
| fix times and edit a tracklist | Editing tracklists |
| react to warnings | Warnings |
| serialize to JSON and read it back | Serializing to JSON |
- Try your own strings in the playground.
- What it understands is a tour of real inputs.
- Working with mixes? Read Tracklists.