Skip to content

Modes

The same string can mean different things depending on where it came from. Blink-182-All The Small Things is clearly artist and title on YouTube. In a music library, a tight dash like that is more likely part of a name. Modes tell trackparse how much guessing the source can take.

Mode For What it adds
clean store metadata, ID3 tags Only a spaced dash separates artist and title
youtube video titles, scrobbles Pipe segments, "Title" by Artist, Artist: "Title", unspaced dashes, trailing junk, the uploader fallback
filename files on disk Strips the extension, reads _ as a space, accepts 01-Track numbering
tracklist one line of a tracklist The first spaced dash always separates, and the words after it are never read as a version or genre suffix
auto anything (the default) Picks filename, youtube or clean from the string. It never picks tracklist

The resolved mode is in track.mode, so you can always see which one ran. You pick one with the mode option. In Rust the option is the enum ModeOption and the resolved mode is Mode, which has no Auto. In Go both are the string type Mode: trackparse.ModeAuto ("auto") asks for auto, an empty Mode in ParseOptions means auto too, and Track.Mode is never ModeAuto. In C both are the enum trackparse_mode: TRACKPARSE_MODE_AUTO is what a new options handle uses until trackparse_parse_options_set_mode changes it, and a result's mode is never TRACKPARSE_MODE_AUTO; trackparse_mode_name gives the name. The mode rules are R2 in the spec.

  1. A known audio or video extension at the end (.mp3, .flac, .wav, .mp4…) means filename.
  2. Junk (a genre bracket doesn't count), a |, or a platform suffix like - YouTube means youtube.
  3. Anything else is clean.

That order is R2.1. Open the file name or the video title in the playground to see the mode it picks.

import { parse } from "trackparse";
const file = parse("07_Burial_-_Archangel.mp3");
[file.mode, file.position, file.artists[0].name, file.title];
// [ 'filename', { raw: '07', number: 7 }, 'Burial', 'Archangel' ]
const video = parse("Noisia - Stigma | Official Video");
[video.mode, video.title, video.junk];
// [ 'youtube', 'Stigma', [ { raw: 'Official Video', kind: 'video' } ] ]

Set it yourself when you know the strings are video titles. It takes guesses that clean won't, and every guess shows up in warnings. The three below are R6.6, R6.5 and R6.7; pipes are R2.4:

const show = (t) => [t.artists.map((a) => a.name), t.title, t.warnings];
show(parse('"Numb" by Linkin Park', { mode: "youtube" }));
// [ [ 'Linkin Park' ], 'Numb', [ 'bySplit' ] ]
show(parse('Linkin Park: "Numb"', { mode: "youtube" }));
// [ [ 'Linkin Park' ], 'Numb', [ 'quotedTitleSplit' ] ]
show(parse("Blink-182-All The Small Things", { mode: "youtube" }));
// [ [ 'Blink-182' ], 'All The Small Things', [ 'unspacedDashSplit' ] ]

In clean mode the last one comes back with no artist, the whole string as the title and a noSeparator warning. That's the safe answer when you can't be sure. Compare the two in the playground: youtube and clean.

Many music videos are titled with only the song name, and the artist is the channel. Pass the channel as uploader and youtube mode uses it when there's no separator. Auto-generated suffixes like - Topic and VEVO are dropped (R6.8; try it):

show(parse("Around the World", { mode: "youtube", uploader: "Daft Punk - Topic" }));
// [ [ 'Daft Punk' ], 'Around the World', [] ]

The extension comes off first, and a name without spaces gets its underscores turned into spaces (R2.3). A leading number then counts as a track number in more forms than elsewhere, such as 311 - and 01-Track (R4.2). Try the first line in the playground.

parse("02_Aphex_Twin_-_Xtal.flac").artists[0].name; // 'Aphex Twin'
parse("311 - Amber.mp3").position; // { raw: '311', number: 311 }
parse("311 - Amber").artists[0].name; // '311'

The 311 lines show why the mode matters. In a file name a leading number with a dash is a track number. Anywhere else, 311 could be a band.

Inside a tracklist almost every line is Artist - Title, so the first spaced dash can be trusted (R6.10, R13.6). A single string doesn't get that benefit of the doubt:

const plain = parse("Electrosoul System - Liquid Metal");
[plain.artists, plain.title, plain.junk];
// [ [], 'Electrosoul System', [ { raw: 'Liquid Metal', kind: 'genre' } ] ]
show(parse("Electrosoul System - Liquid Metal", { mode: "tracklist" }));
// [ [ 'Electrosoul System' ], 'Liquid Metal', [] ]

parseTracklist (parse_tracklist in Python and Rust, ParseTracklist in Go, trackparse_parse_tracklist in C) uses this mode for every line. You only need to set it yourself when you parse tracklist lines one at a time. The playground can show this line in tracklist mode. Tracklist mode in the tracklist guide has more lines that need it.