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.
Parse options
Section titled “Parse options”interface ParseOptions { mode?: "auto" | "clean" | "youtube" | "filename" | "tracklist"; knownArtists?: string[]; uploader?: string; splitAnd?: "auto" | "always" | "never"; keywords?: KeywordOptions;}parse( input, *, mode: ModeOption = "auto", # "auto" | "clean" | "youtube" | "filename" | "tracklist" uploader: Optional[str] = None, known_artists: Sequence[str] = (), split_and: str = "auto", # "auto" | "always" | "never" keywords: Optional[KeywordOptions] = None,)#[non_exhaustive]pub struct ParseOptions { pub mode: ModeOption, // Auto | Clean | Youtube | Filename | Tracklist pub uploader: Option<String>, pub known_artists: Vec<String>, pub split_and: SplitAnd, // Auto | Always | Never pub keywords: Option<KeywordOptions>,}Start from the defaults and chain a setter per option
(ParseOptions on docs.rs):
use trackparse::{parse_with, ModeOption, ParseOptions, SplitAnd};
let input = "Chase & Status - Baddadan";let options = ParseOptions::new() .mode(ModeOption::Youtube) .known_artists(["Chase & Status"]) .uploader("Daft Punk - Topic") .split_and(SplitAnd::Never);&parse_with(input, &options).artists[0].name; // "Chase & Status"type ParseOptions struct { Mode Mode // ModeAuto | ModeClean | ModeYouTube | ModeFilename | ModeTracklist; "" means auto Uploader string // empty means none KnownArtists []string SplitAnd SplitAnd // SplitAndAuto | SplitAndAlways | SplitAndNever; "" means auto Keywords Keywords}Set the fields you need. The others keep their zero value, which is the default
(ParseOptions on pkg.go.dev):
import ( "fmt"
"github.com/4matic/trackparse/go")
input := "Chase & Status - Baddadan"options := trackparse.ParseOptions{ Mode: trackparse.ModeYouTube, KnownArtists: []string{"Chase & Status"}, Uploader: "Daft Punk - Topic", SplitAnd: trackparse.SplitAndNever,}fmt.Printf("%q\n", trackparse.ParseWith(input, options).Artists[0].Name) // "Chase & Status"#include <trackparse.h>
trackparse_parse_options *trackparse_parse_options_new(void);void trackparse_parse_options_free(trackparse_parse_options *o);bool trackparse_parse_options_set_mode(trackparse_parse_options *o, trackparse_mode mode);bool trackparse_parse_options_set_uploader(trackparse_parse_options *o, const char *s, size_t len);bool trackparse_parse_options_add_known_artist(trackparse_parse_options *o, const char *s, size_t len);bool trackparse_parse_options_set_split_and(trackparse_parse_options *o, trackparse_split_and v);Create a handle and call a setter per option. The options you don't set keep their defaults:
const char *input = "Chase & Status - Baddadan";trackparse_parse_options *options = trackparse_parse_options_new();trackparse_parse_options_set_mode(options, TRACKPARSE_MODE_YOUTUBE);trackparse_parse_options_add_known_artist(options, "Chase & Status", TRACKPARSE_NUL_TERMINATED);trackparse_parse_options_set_uploader(options, "Daft Punk - Topic", TRACKPARSE_NUL_TERMINATED);trackparse_parse_options_set_split_and(options, TRACKPARSE_SPLIT_AND_NEVER);trackparse_track *t = trackparse_parse_with(input, TRACKPARSE_NUL_TERMINATED, options);printf("%s\n", t->artists[0].name.ptr); // Chase & Statustrackparse_track_free(t);trackparse_parse_options_free(options);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 |
modeMode |
"auto" |
Which mode to use. auto picks filename, youtube or clean from the string |
knownArtists |
known_artistsKnownArtists |
empty | Names that are never split, like Chase & Status or Earth, Wind & Fire. Matched case- and accent-insensitively. See knownArtists |
uploader |
uploaderUploader |
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_andSplitAnd |
"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 |
keywordsKeywords |
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
Section titled “keywords”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}class KeywordOptions(TypedDict, total=False): version_heads: dict[str, VersionType] # {"rerub": "rework"} descriptors: list[str] # extra style words, like the built-in "D'n'B" genres: list[str] # extra genre names (junk kind 'genre') junk: dict[str, JunkKind] # {"live stream": "other"} feat_markers: list[str] # extra feat markers#[non_exhaustive]pub struct KeywordOptions { pub version_heads: Vec<(String, VersionType)>, // .version_head("rerub", VersionType::Rework) pub descriptors: Vec<String>, // .descriptor(…): extra style words, like the built-in "D'n'B" pub genres: Vec<String>, // .genre(…): extra genre names (junk kind Genre) pub junk: Vec<(String, JunkKind)>, // .junk("live stream", JunkKind::Other) pub feat_markers: Vec<String>, // .feat_marker(…): extra feat markers}type Keywords struct { VersionHeads []VersionHead // {Key: "rerub", Type: VersionTypeRework} Descriptors []string // extra style words, like the built-in "D'n'B" Genres []string // extra genre names (junk kind genre) Junk []JunkPhrase // {Phrase: "live stream", Kind: JunkKindOther} FeatMarkers []string // extra feat markers}/* Each call adds one entry; type and kind are spec names ("rework", "other"). */bool trackparse_parse_options_add_version_head(trackparse_parse_options *o, const char *key, size_t key_len, const char *type, size_t type_len);bool trackparse_parse_options_add_descriptor(trackparse_parse_options *o, const char *s, size_t len);bool trackparse_parse_options_add_genre(trackparse_parse_options *o, const char *s, size_t len);bool trackparse_parse_options_add_junk(trackparse_parse_options *o, const char *phrase, size_t phrase_len, const char *kind, size_t kind_len);bool trackparse_parse_options_add_feat_marker(trackparse_parse_options *o, const char *s, size_t len);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'from trackparse import create_parser
parser = create_parser( known_artists=["Chase & Status", "Camo & Krooked"], keywords={"version_heads": {"rerub": "rework"}},)
t = parser.parse("Chase & Status x Camo & Krooked - Track (Alix Perez Rerub)")[a.name for a in t.artists] # ['Chase & Status', 'Camo & Krooked']t.versions[0].type # 'rework'use trackparse::{KeywordOptions, ParseOptions, Parser, VersionType};
let options = ParseOptions::new() .known_artists(["Chase & Status", "Camo & Krooked"]) .keywords(KeywordOptions::new().version_head("rerub", VersionType::Rework));let parser = Parser::new(&options);
let t = parser.parse("Chase & Status x Camo & Krooked - Track (Alix Perez Rerub)");t.artists.iter().map(|a| &a.name).collect::<Vec<_>>(); // ["Chase & Status", "Camo & Krooked"]t.versions[0].version_type; // Reworkparser := trackparse.NewParser(trackparse.ParseOptions{ KnownArtists: []string{"Chase & Status", "Camo & Krooked"}, Keywords: trackparse.Keywords{ VersionHeads: []trackparse.VersionHead{{Key: "rerub", Type: trackparse.VersionTypeRework}}, },})
t := parser.Parse("Chase & Status x Camo & Krooked - Track (Alix Perez Rerub)")fmt.Printf("%q\n", []string{t.Artists[0].Name, t.Artists[1].Name}) // ["Chase & Status" "Camo & Krooked"]fmt.Println(t.Versions[0].Type) // reworktrackparse_parse_options *o = trackparse_parse_options_new();trackparse_parse_options_add_known_artist(o, "Chase & Status", TRACKPARSE_NUL_TERMINATED);trackparse_parse_options_add_known_artist(o, "Camo & Krooked", TRACKPARSE_NUL_TERMINATED);trackparse_parse_options_add_version_head(o, "rerub", TRACKPARSE_NUL_TERMINATED, "rework", TRACKPARSE_NUL_TERMINATED);trackparse_parser *parser = trackparse_parser_new(o);trackparse_parse_options_free(o);
t = trackparse_parser_parse(parser, "Chase & Status x Camo & Krooked - Track (Alix Perez Rerub)", TRACKPARSE_NUL_TERMINATED);for (size_t i = 0; i < t->artists_count; i++) { printf("%s\n", t->artists[i].name.ptr);}// Chase & Status// Camo & Krookedprintf("%s\n", t->versions[0].type_name.ptr); // reworktrackparse_track_free(t);trackparse_parser_free(parser);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' } ]from trackparse import parse
parse("Artist - Song [Some Label Rip]").title # 'Song [Some Label Rip]'
r = parse("Artist - Song [Some Label Rip]", keywords={"junk": {"some label rip": "label"}})r.title # 'Song'r.junk # (Junk(raw='Some Label Rip', kind='label'),)use trackparse::{parse, parse_with, JunkKind, KeywordOptions, ParseOptions};
parse("Artist - Song [Some Label Rip]").title; // "Song [Some Label Rip]"
let keywords = KeywordOptions::new().junk("some label rip", JunkKind::Label);let r = parse_with("Artist - Song [Some Label Rip]", &ParseOptions::new().keywords(keywords));&r.title; // "Song"&r.junk; // [Junk { raw: "Some Label Rip", kind: Label }]fmt.Printf("%q\n", trackparse.Parse("Artist - Song [Some Label Rip]").Title) // "Song [Some Label Rip]"
keywords := trackparse.Keywords{ Junk: []trackparse.JunkPhrase{{Phrase: "some label rip", Kind: trackparse.JunkKindLabel}},}r := trackparse.ParseWith("Artist - Song [Some Label Rip]", trackparse.ParseOptions{Keywords: keywords})fmt.Printf("%q\n", r.Title) // "Song"fmt.Printf("%+v\n", r.Junk) // [{Raw:Some Label Rip Kind:label}]t = trackparse_parse("Artist - Song [Some Label Rip]", TRACKPARSE_NUL_TERMINATED);printf("%s\n", t->title.ptr); // Song [Some Label Rip]trackparse_track_free(t);
o = trackparse_parse_options_new();trackparse_parse_options_add_junk(o, "some label rip", TRACKPARSE_NUL_TERMINATED, "label", TRACKPARSE_NUL_TERMINATED);trackparse_track *r = trackparse_parse_with("Artist - Song [Some Label Rip]", TRACKPARSE_NUL_TERMINATED, o);printf("%s\n", r->title.ptr); // Songfor (size_t i = 0; i < r->junk_count; i++) { printf("%s: %s\n", r->junk[i].kind_name.ptr, r->junk[i].raw.ptr);}// label: Some Label Riptrackparse_track_free(r);trackparse_parse_options_free(o);Tracklist options
Section titled “Tracklist options”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_secondsAudioSeconds |
none | Length of the audio. Turns on the time-after-audio-end check |
markerWords |
marker_wordsMarkerWords |
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 options
Section titled “Format options”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.
See also
Section titled “See also”parseandParsedTrackfor what comes back.- Tracklist API for the tracklist options next to
parseTracklistandapplyEdits. createParserto resolve options once for many calls.- Modes and Artists and credits for
what
mode,uploader,knownArtistsandsplitAndchange. - Specification, R12 for the exact option rules.