Skip to content

Options

parse, parseArtists and createParser take the same options. JavaScript takes an object, Python takes keyword arguments, Rust takes a ParseOptions value through the _with functions, Go takes a ParseOptions struct through the With functions, and C takes an options handle through the _with functions.

interface ParseOptions {
mode?: "auto" | "clean" | "youtube" | "filename" | "tracklist";
knownArtists?: string[];
uploader?: string;
splitAnd?: "auto" | "always" | "never";
keywords?: KeywordOptions;
}

The C setters are on the options handle and are named after the option in snake_case: trackparse_parse_options_set_mode, _set_uploader and _set_split_and. A list option is an add_ setter that takes one entry, named in the singular: _add_known_artist. keywords has no setter of its own; each of its lists is an add_ setter, listed under keywords.

JavaScript Python and Rust
Go
Default
mode mode
Mode
"auto" Which mode to use. auto picks filename, youtube or clean from the string
knownArtists known_artists
KnownArtists
empty Names that are never split, like Chase & Status or Earth, Wind & Fire. Matched case- and accent-insensitively. See knownArtists
uploader uploader
Uploader
none The YouTube channel. In youtube mode it becomes the artist when there's no separator. - Topic and VEVO are dropped. See the uploader fallback
splitAnd split_and
SplitAnd
"auto" auto splits on and only after a comma or semicolon (A, B and C), so Simon and Garfunkel stays whole. always and never do what they say. See and is special
keywords keywords
Keywords
none Extra vocabulary, see keywords below

All five options work the same in parse, parseArtists (which ignores mode and uploader) and createParser. The playground has a field for each but keywords: this link opens the example above with all four set.

In Rust the values are enums: ModeOption::Auto, Clean, Youtube, Filename or Tracklist, and SplitAnd::Auto, Always or Never. The option structs are #[non_exhaustive], so start from ParseOptions::new() (or default()) and chain setters. The fields are public and can also be assigned.

In Go the values are typed strings with constants: trackparse.ModeAuto, ModeClean, ModeYouTube, ModeFilename or ModeTracklist (the type Mode), and SplitAndAuto, SplitAndAlways or SplitAndNever (the type SplitAnd). The zero value of ParseOptions is the defaults: an empty Mode is auto, an empty SplitAnd is auto and an empty Uploader is none. A string that is not one of the constants behaves as an unknown value does in JavaScript.

In C the options are an opaque handle: create it with trackparse_parse_options_new(), call a setter per option, pass it to trackparse_parse_with, trackparse_parse_artists_with or trackparse_parser_new, and free it with trackparse_parse_options_free. An option you never set keeps its default, and an empty uploader is none, as in Go. Setters copy their input, so the strings you pass can be freed right after the call, and the add_ setters append one entry each. A setter returns false only when memory runs out. A NULL handle means the defaults. The values are the enums TRACKPARSE_MODE_AUTO, _CLEAN, _YOUTUBE, _FILENAME and _TRACKLIST, and TRACKPARSE_SPLIT_AND_AUTO, _ALWAYS and _NEVER; a value out of range falls back to the default, as an unknown value does in JavaScript. The declarations are in trackparse.h.

Options never cause an error. An unknown mode, a knownArtists that isn't a list or a keyword of the wrong type is ignored and the default is used. In Rust, Go and C the options are typed, so most of those values can't be written at all. The option rules are R12 in the spec.

In Python the options can also travel as a dict, typed as the ParseOptions TypedDict: parse(s, **options). In Rust with the serde feature, ParseOptions reads from JSON with the JavaScript key names ({"mode":"youtube","knownArtists":["Chase & Status"]}). Reading is strict: a missing key is the default, an unknown name such as "mode":"radio" is an error.

keywords adds words to the built-in vocabulary. It can't take any away. In Python its keys are snake_case too: version_heads, feat_markers. In Rust, KeywordOptions has one setter per word, and each call adds one entry. In Go, Keywords holds slices: the two maps of the JavaScript options are ordered slices of VersionHead and JunkPhrase, because a Go map has no insertion order. They are read as JavaScript reads an object: a repeated key keeps its first place and takes the last value, and integer-like keys come first, in ascending order. In C, each add_ setter on the options handle adds one entry, and the version heads and junk phrases are read in that same JavaScript order. The type and kind are spec names given as strings, so a name that is not one of the built-in types also works, as in JavaScript. The junk kinds are those of junk, note included. The built-in lists are JSON files in spec/data, and the keyword rules are R12. Your own words in the versions guide has another example.

interface KeywordOptions {
versionHeads?: Record<string, VersionType>; // { rerub: "rework" }
descriptors?: string[]; // extra style words, like the built-in "D'n'B"
genres?: string[]; // extra genre names (junk kind 'genre')
junk?: Record<string, JunkKind>; // { "live stream": "other" }
featMarkers?: string[]; // extra feat markers
}

Keys are compared the same way as the built-in words: ASCII letters are lowercased and one trailing . , ! ? : ; is ignored.

import { createParser } from "trackparse";
const parser = createParser({
knownArtists: ["Chase & Status", "Camo & Krooked"],
keywords: { versionHeads: { rerub: "rework" } },
});
const t = parser.parse("Chase & Status x Camo & Krooked - Track (Alix Perez Rerub)");
t.artists.map((a) => a.name); // [ 'Chase & Status', 'Camo & Krooked' ]
t.versions[0].type; // 'rework'

A junk phrase works the same way. Without the keyword the bracket stays in the title, because nothing recognizes it:

import { parse } from "trackparse";
parse("Artist - Song [Some Label Rip]").title; // 'Song [Some Label Rip]'
const r = parse("Artist - Song [Some Label Rip]", { keywords: { junk: { "some label rip": "label" } } });
r.title; // 'Song'
r.junk; // [ { raw: 'Some Label Rip', kind: 'label' } ]

parseTracklist and applyEdits (parse_tracklist and apply_edits in Python and Rust, ParseTracklist and ApplyEdits in Go, trackparse_parse_tracklist_with in C) take mode (default "tracklist"), knownArtists, splitAnd and keywords, plus two of their own. In Rust they are the setters of TracklistOptions, passed to parse_tracklist_with and apply_edits_with (TracklistOptions on docs.rs). In Go they are the fields of the TracklistOptions struct, passed to ParseTracklistWith and ApplyEditsWith. In C they are the setters of a trackparse_tracklist_options handle (trackparse_tracklist_options_new()), passed to trackparse_parse_tracklist_with. The rules are R13.10:

JavaScript Python and Rust
Go
Default Description
audioSeconds audio_seconds
AudioSeconds
none Length of the audio. Turns on the time-after-audio-end check
markerWords marker_words
MarkerWords
empty Extra marker words. With ["drop"], 03:00 Drop is a marker, not a track

In C these two are trackparse_tracklist_options_set_audio_seconds and trackparse_tracklist_options_add_marker_word (one word per call). The shared options have the same setters as on the parse options handle, with trackparse_tracklist_options_ in front: _set_mode, _set_split_and, _add_known_artist and the five keyword setters. There is no uploader on a tracklist.

In Go the zero value of TracklistOptions is the defaults too: an empty Mode means ModeTracklist, and ModeAuto asks for auto mode on each line. AudioSeconds is a *float64, so nil means no length and trackparse.Ptr(0.0) is an audio of length 0, as audioSeconds: 0 is in JavaScript. In C, an audio length that was never set is none, and trackparse_tracklist_options_set_audio_seconds(o, 0) is an audio of length 0. The default mode of a tracklist options handle is TRACKPARSE_MODE_TRACKLIST.

Tracklists has an example in each language, and the Tracklist API lists them again with the functions.

format has its own options (feat, featMarker, joiners, versions, producers, position, label). They are listed under Formatting. In Go they are the fields of FormatOptions; producers: false is OmitProducers: true there and label: false is OmitLabel: true, so the zero value keeps the producers and the label, and FeatMarker is a *string (nil keeps the input's marker). In Rust they are the setters of FormatOptions. In C they are the setters of a trackparse_format_options handle; trackparse_format_options_set_omit_producers(o, true) is producers: false, trackparse_format_options_set_omit_label(o, true) is label: false, and a marker never set with _set_feat_marker keeps the input's. The rules are R11.