Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- run: pnpm --filter trackparse typecheck
- run: pnpm --filter trackparse test
- run: pnpm --filter trackparse build
- name: Size budget (trackparse/tracklist adds <= 8 KiB gzip)
- name: Size budget (trackparse/tracklist adds <= 9 KiB gzip)
run: pnpm --filter trackparse size
- name: Package checks
working-directory: js
Expand Down
10 changes: 6 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ spec/
fixtures/handwritten/ curated cases by topic (edit by hand)
fixtures/generated/ combinatorial cases (NEVER edit by hand)
generator/ @trackparse/fixture-gen: writes fixtures/generated
(src/tracklist.ts + scenarios/tracklist.ts: multi-line tracklist cases)
(src/tracklist.ts + scenarios/tracklist.ts, tracklist-emphasis.ts:
multi-line tracklist cases)
proposals/tracklist.md the platform proposal behind R13 (historical; SPEC.md wins)
corpus/ git-ignored: private real-world corpora (platform data, never commit)
js/ npm package `trackparse`, reference implementation
Expand All @@ -27,6 +28,7 @@ js/ npm package `trackparse`, reference implementation
index.ts exports parseTracklist, applyEdits and the tracklist types
types.ts public tracklist types (mirror tracklist.schema.json)
options.ts R13.10 split.ts R13.1 lines + eol times.ts R13.2, R13.9.2
emphasis.ts R13.12 Markdown emphasis markers (pairing) and runs next to the time
kinds.ts R13.3, R13.4.2 candidate lines positions.ts R13.5
warnings.ts R13.7 + out-of-order suggestion search parse.ts R13.1–R13.8
edits.ts R13.9 applyEdits
Expand All @@ -47,7 +49,7 @@ js/ npm package `trackparse`, reference implementation
scripts/gen-data.ts codegen for data.generated.ts
scripts/conformance.ts pass-rate report per file and per rule
scripts/compat.mjs every fixture against dist/ (ESM + CJS) with plain Node 18+
scripts/size-check.mjs size budget: the tracklist entry may add at most 8 KiB gzip
scripts/size-check.mjs size budget: the tracklist entry may add at most 9 KiB gzip
test/runner.ts loads and runs shared fixtures
test/match.ts partial/exact matcher (spec/fixtures/README.md)
test/fixtures.test.ts every fixture + schema validation + xfail/skip handling
Expand All @@ -68,7 +70,7 @@ python/ PyPI package `trackparse` (Python 3.9+, zero deps, uv
_digits.py digit runs (js/src/digits.ts)
tracklist.py public `trackparse.tracklist` (parse_tracklist, apply_edits, types)
_tracklist_*.py one per js/src/tracklist file: _types, _options, _split, _times,
_kinds, _positions, _warnings, _parse, _edits
_kinds, _positions, _warnings, _parse, _edits, _emphasis
_tables.py R12 _context.py per-call context
_data.py GENERATED from spec/data + spec/VERSION (never edit)
scripts/gen_data.py codegen for _data.py (--check for CI)
Expand Down Expand Up @@ -180,7 +182,7 @@ Run from the repo root (pnpm workspace; Node ≥ 22 for development: pnpm 11 and
| `pnpm conformance` | JS pass rate per fixture file and per rule ID |
| `pnpm docs` · `pnpm docs:build` | Run the documentation site locally / build it into `site/dist` |
| `pnpm --filter trackparse compat` | After `build`: every fixture against `dist/` (ESM + CJS) with plain Node; runs on Node 18+ |
| `pnpm --filter trackparse size` | After `build`: fail if `trackparse/tracklist` adds more than 8 KiB gzip (ESM and CJS) |
| `pnpm --filter trackparse size` | After `build`: fail if `trackparse/tracklist` adds more than 9 KiB gzip (ESM and CJS) |
| `pnpm gen:data` | Regenerate `js/src/data.generated.ts` from `spec/data` + `spec/VERSION` |
| `pnpm gen:fixtures` | Regenerate `spec/fixtures/generated/*.json` |
| `pnpm gen:check` | Fail if generated fixtures or JS codegen are stale |
Expand Down
54 changes: 33 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ Every key is always present. When a guess was involved, `warnings` says which on

| Number | What it means |
|---|---|
| **12,965** shared fixtures | 1,148 written by hand, 11,817 generated from combinations. 100% pass in JS and Python, nothing skipped. |
| **1,074** of them on tracklists | 248 handwritten, 826 generated. Line splitting, times, warnings, edits |
| **1,293** JS tests | every fixture, a schema check on every output, property-based tests of the spec invariants, API tests |
| **13,124** shared fixtures | 1,197 written by hand, 11,927 generated from combinations. 100% pass in JS and Python, nothing skipped. |
| **1,233** of them on tracklists | 297 handwritten, 936 generated. Line splitting, times, bullets and Markdown, warnings, edits |
| **1,346** JS tests | every fixture, a schema check on every output, property-based tests of the spec invariants, API tests |
| **27** version types | remix, VIP, bootleg, extended, radio, original, live, remaster, sped up, … |
| **0** dependencies | ESM + CJS + TypeScript types, about 17 kB gzipped. `trackparse/tracklist` adds about 7.6 kB, only if you import it |
| **0** dependencies | ESM + CJS + TypeScript types, about 17 kB gzipped. `trackparse/tracklist` adds about 8.3 kB, only if you import it |
| **Node 18+** | CI runs the full suite on 22 and 24, and every fixture against the built package on 18 and 20 |
| **Python 3.9+** | 1,283 pytest tests on 3.9 to 3.14, plus every fixture against the built wheel. Output is byte-identical to JS |
| **Python 3.9+** | 1,336 pytest tests on 3.9 to 3.14, plus every fixture against the built wheel. Output is byte-identical to JS |
| **5,031** real tracklist lines | 117 podcast tracklists the tracklist rules were checked against. Every line round-trips byte for byte |
| **1 spec** | [`spec/SPEC.md`](spec/SPEC.md) defines the behaviour; the Python port passes the same fixtures, and so will Rust |

Expand Down Expand Up @@ -313,6 +313,13 @@ apply_edits(text, [{"op": "set-time", "line": 8, "seconds": 4262}]).changed
# (8,)
```

Lists pasted from Discord, Reddit or YouTube comments often keep their list bullets and Markdown.
`* 14:21 Artist - Title`, `**[**14:21**] 10. Artist - Title**` and `[14:21] **Artist** - _Title_`
all read like the plain line; the decoration stays in `raw` and `parts`. A `*` or `_` only counts as
emphasis when it has a partner on the line and sits against a space, a bracket or the line's end, so
`P*nk`, `DJ_Name` and a censored `F**k` keep their stars and underscores
([details](https://4matic.github.io/trackparse/guides/tracklists/#markdown)).

### Tracklist mode

**Docs:** [Tracklist mode](https://4matic.github.io/trackparse/guides/tracklists/#tracklist-mode)
Expand Down Expand Up @@ -344,14 +351,14 @@ of the list uses spaced dashes.

The fixtures in [`spec/fixtures`](spec/fixtures) are the source of truth. The spec says what should
happen, the fixtures pin it down, and every port has to pass all of them. The JS and Python
packages both do: **12,965 of 12,965**, with empty skip lists, in CI on every push.
packages both do: **13,124 of 13,124**, with empty skip lists, in CI on every push.

Passing a fixture only checks the fields the case asserts, so
[`scripts/compare-ports.mjs`](scripts/compare-ports.mjs) also runs every fixture input through both
ports and diffs the complete outputs, tracklists and edits included. Result: 0 differences, byte
for byte.

### Handwritten: 1,148 cases in 27 files
### Handwritten: 1,197 cases in 27 files

Each case cites the spec rules it exercises. 62 of them spell out the complete output field by
field, so nothing can drift unnoticed.
Expand All @@ -367,13 +374,13 @@ field, so nothing can drift unnoticed.
| Modes | 65 | YouTube pipes, `"Title" by Artist`, uploader fallback, filenames |
| Unicode and normalization | 71 | NFC, zero-width characters, fullwidth brackets, Cyrillic, CJK, Turkish İ |
| `format`, `parseArtists`, unknown IDs | 94 | Round-trips, canonical joiners, `ID - ID` |
| Tracklist mode | 54 | All 17 real podcast lines that single-line `parse()` gets wrong, the 6 real lines with no separator at all, `parse(s, { mode: "tracklist" })` |
| Tracklist lines and times | 70 | LF/CRLF/CR, trailing spaces, line kinds, every time form, brackets, gap separators, `=>` arrows, invalid times |
| Tracklist positions | 13 | The real 81-line list numbered `1 ` to `81 ` without dots, and the `2 Unlimited` guard |
| Tracklist warnings | 36 | Each code with its near-miss, and the 10 real out-of-order lists with their suggestions |
| Tracklist edits | 75 | `set-time` style keeping, shift, clamp, `sort-by-time`, insert/delete line endings, invalid edits, locality |
| Tracklist mode | 61 | All 17 real podcast lines that single-line `parse()` gets wrong, the 6 real lines with no separator at all, `parse(s, { mode: "tracklist" })`, Markdown emphasis around names, and names that keep their `*` and `_` |
| Tracklist lines and times | 104 | LF/CRLF/CR, trailing spaces, line kinds, every time form, brackets, gap separators, `=>` arrows, invalid times, list bullets, Markdown around times, `w/` lines |
| Tracklist positions | 15 | The real 81-line list numbered `1 ` to `81 ` without dots, and the `2 Unlimited` guard, with a `w/` line in between |
| Tracklist warnings | 38 | Each code with its near-miss, and the 10 real out-of-order lists with their suggestions |
| Tracklist edits | 79 | `set-time` style keeping, shift, clamp, `sort-by-time`, insert/delete line endings, invalid edits, locality |

### Generated: 11,817 cases
### Generated: 11,927 cases

A deterministic generator in [`spec/generator`](spec/generator) builds inputs from small "atoms": an
artist, a joiner, a feat placement, a version group, a junk suffix. Each atom carries its own
Expand All @@ -387,11 +394,13 @@ running a parser, so the generator can't just agree with the code it is testing.
| dash suffixes | 1,174 | | filenames | 780 |
| dedup | 1,008 | | unicode | 674 |
| feat placement | 922 | | prefixes | 577 |
| tracklists | 826 | | | |
| tracklists | 826 | | tracklists with Markdown | 110 |

The tracklist scenario crosses time forms (`MM:SS`, `H:MM:SS`, fractions, long minutes) with
brackets, gap separators, position styles, line endings, an extra blank, header or note line, and
the warning each combination should raise.
the warning each combination should raise. A second scenario crosses list bullets and Markdown
emphasis around the time (`**T**`, `**[T]**`, `[**T**]`, `_[T]_`…) with emphasis around each track
line; the expected tracks are the plain lines' tracks.

### Properties

Expand All @@ -411,7 +420,9 @@ For tracklists, on random multi-line text and random edit lists:
- `applyEdits(t, [])` returns `t`, and an edit never touches a line it doesn't name;
- `shift(+s)` then `shift(-s)` restores the text when nothing was clamped or upgraded;
- 10,000 lines parse in linear time (the JS suite allows 3 s; it takes about 0.6 s);
- a one-line list gives the same track as `parse(rest, { mode: "tracklist" })`.
- a one-line list gives the same track as `parse()` in tracklist mode on its text without Markdown
emphasis or a leading `w/`;
- Markdown emphasis around a time or a track line changes nothing.

### Real tracklists

Expand Down Expand Up @@ -556,9 +567,10 @@ that only parses single tracks never loads it.
| `kind` | `"track" \| "marker" \| "header" \| "link" \| "note" \| "blank"` | See below |
| `eol` | `"\n" \| "\r\n" \| "\r" \| ""` | The line's own terminator; `""` on a last line without one |
| `raw` | `string` | The line exactly as written, never normalized |
| `parts` | `{ lead, time, gap, rest }` | `raw` cut into four strings that join back into it. `lead` is spaces or an opening bracket, `gap` is what sits between the time and the track (`] `, ` - `, ` \| `, ` => `) |
| `parts` | `{ lead, time, gap, rest }` | `raw` cut into four strings that join back into it. `lead` is spaces, a list bullet, Markdown emphasis or an opening bracket, `gap` is what sits between the time and the track (`] `, ` - `, ` \| `, ` => `) |
| `time` | `{ raw, seconds } \| null` | `12:34`, `1:02:03`, `125:30` (long mixes), `00:00:07.500` (7.5 s) |
| `track` | `ParsedTrack \| null` | Parsed from `rest` in tracklist mode. Only `track` and `marker` lines have one |
| `track` | `ParsedTrack \| null` | Parsed from `rest` in tracklist mode, without Markdown emphasis, a leading `w/` and a bare track number. Only `track` and `marker` lines have one |
| `layered` | `boolean` | The line starts with `w/`: a track played over the previous one |

Kinds: a line with a time is a `marker` when it has no separator and a word like `intro`, `break`
or `interview` ([`spec/data/marker-words.json`](spec/data/marker-words.json)), otherwise a
Expand All @@ -573,7 +585,7 @@ warnings stay on `entries[i].track.warnings` and are not repeated here.

| Code | Severity | When |
|---|---|---|
| `time-missing` | warning | A track line has no time while other lines do |
| `time-missing` | warning | A track line has no time while other lines do (not raised on a `w/` line) |
| `time-out-of-order` | warning | Earlier than the previous timed line. May carry a `suggestion` |
| `time-duplicate` | warning | Same time as the previous timed line |
| `no-start-at-zero` | info | The first time isn't `0:00` |
Expand Down Expand Up @@ -662,8 +674,8 @@ spaced dashes. The checks run last, over the finished entries.

| Language | Package | Status |
|---|---|---|
| JavaScript / TypeScript | [`trackparse`](https://www.npmjs.com/package/trackparse) on npm | reference implementation, 12,965 / 12,965 fixtures, tracklists as `trackparse/tracklist` |
| Python | [`trackparse`](https://pypi.org/project/trackparse/) on PyPI | 12,965 / 12,965 fixtures, output identical to JS, tracklists as `trackparse.tracklist` |
| JavaScript / TypeScript | [`trackparse`](https://www.npmjs.com/package/trackparse) on npm | reference implementation, 13,124 / 13,124 fixtures, tracklists as `trackparse/tracklist` |
| Python | [`trackparse`](https://pypi.org/project/trackparse/) on PyPI | 13,124 / 13,124 fixtures, output identical to JS, tracklists as `trackparse.tracklist` |
| Rust | `trackparse` on crates.io | planned, same fixtures |

Want another language? The porting checklist is in [AGENTS.md](AGENTS.md).
Expand Down
10 changes: 8 additions & 2 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Parse music track names into structured metadata: artists, featured artists, rem

This is the JavaScript/TypeScript reference implementation of the
[trackparse spec](https://github.com/4matic/trackparse/blob/main/spec/SPEC.md). It passes all
12,965 shared fixtures. Zero dependencies, ESM and CommonJS, TypeScript types included, never
13,124 shared fixtures. Zero dependencies, ESM and CommonJS, TypeScript types included, never
throws.

The principle is **extract, don't delete**: everything recognised lands in a field (artists with
Expand Down Expand Up @@ -227,7 +227,7 @@ The full field reference, a gallery of examples and the comparison with other li

`trackparse/tracklist` parses a whole tracklist: one entry per line with its kind, start time and
a full `ParsedTrack`, plus checks with line numbers. Joining `raw + eol` over the entries gives the
input back byte for byte, whatever the line endings. It's a separate entry point (about 7.6 KiB
input back byte for byte, whatever the line endings. It's a separate entry point (about 8.3 KiB
gzipped), so you only pay for it if you import it.

```js
Expand Down Expand Up @@ -289,6 +289,12 @@ Warning codes: `time-missing`, `time-out-of-order` (with a one- or two-digit `su
exactly one fix fits), `time-duplicate`, `no-start-at-zero`, `time-after-audio-end` (pass
`audioSeconds`), `invalid-time`, `position-gap`, `position-duplicate`, `line-unparsed`.

Lists pasted with list bullets or Markdown emphasis (`* 14:21 Artist - Title`,
`**[**14:21**] Artist - Title**`) read like plain lines; the decoration stays in `raw` and `parts`.
A line starting with `w/` is `layered`: a track played over the previous one
([Markdown](https://4matic.github.io/trackparse/guides/tracklists/#markdown),
[layered tracks](https://4matic.github.io/trackparse/guides/tracklists/#layered-tracks)).

Options: `mode` (default `"tracklist"`), `knownArtists`, `splitAnd`, `keywords`, `audioSeconds`,
`markerWords`. Every type is exported (`import type { Tracklist, Edit } from
"trackparse/tracklist"`).
Expand Down
10 changes: 5 additions & 5 deletions js/scripts/size-check.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env node
/**
* Size budget for the `trackparse/tracklist` entry: its own code may add at most 8 KiB gzip on
* top of the core.
* Size budget for the `trackparse/tracklist` entry: its own code may add at most 9 KiB gzip on
* top of the core (8 KiB until 0.4.0, which added list bullets and Markdown emphasis).
*
* - ESM: tsup code-splits the shared core into a chunk that dist/index.js and dist/tracklist.js
* both import, so dist/tracklist.js is the tracklist code alone: gzip(tracklist.js) <= 8 KiB.
* both import, so dist/tracklist.js is the tracklist code alone: gzip(tracklist.js) <= 9 KiB.
* - CJS: each entry is bundled on its own, so dist/tracklist.cjs contains the core too:
* gzip(tracklist.cjs) - gzip(index.cjs) <= 8 KiB.
* gzip(tracklist.cjs) - gzip(index.cjs) <= 9 KiB.
*
* Usage: node scripts/size-check.mjs (after `pnpm build`). Zero dependencies.
*/
import { readFileSync } from "node:fs";
import { gzipSync } from "node:zlib";

const BUDGET = 8 * 1024;
const BUDGET = 9 * 1024;
const gz = (file) => gzipSync(readFileSync(new URL(`../dist/${file}`, import.meta.url))).length;

const checks = [
Expand Down
7 changes: 7 additions & 0 deletions js/src/data.generated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions js/src/tracklist/emphasis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/** R13.12 Markdown emphasis markers in a tracklist line. */
import { isWhitespace } from "../words.js";

/** Length of the maximal run of `*` or `_` at `at` (0 when there is none). */
function runLength(s: string, at: number): number {
const ch = s[at];
let j = at;
if (ch === "*" || ch === "_") while (s[j] === ch) j++;
return j - at;
}

/**
* R13.2.1 / R13.2.3: the length of an emphasis run at `at` (a maximal run of 1 or 2 `*` or `_`),
* else 0. Used next to the time, where runs are read by position rather than by pairing.
*/
export function emphasisRun(s: string, at: number): number {
const n = runLength(s, at);
return n <= 2 ? n : 0;
}

/** R13.12.2 outer side: line edge, R0.2 whitespace, a bracket, or a `*` / `_` of another run. */
const isOuter = (ch: string | undefined) =>
ch === undefined || isWhitespace(ch) || "[]()*_".includes(ch);
/** R13.12.2 inner side: a character that is not R0.2 whitespace. */
const isInner = (ch: string | undefined) => ch !== undefined && !isWhitespace(ch);

/**
* R13.12: `raw.slice(from)` without its emphasis markers. A run of 1 or 2 `*` or `_` closes when
* the character before it is an inner side and the one after it an outer side, and opens the other
* way round. A closer pairs with the nearest opener of the same characters; that opener and every
* opener after it leave the stack. One stack per run (`*`, `**`, `_`, `__`) keeps this linear.
*/
export function withoutMarkers(raw: string, from: number): string {
const marked: boolean[] = [];
const stacks: Record<string, number[]> = { "*": [], "**": [], _: [], __: [] };
for (let i = 0; i < raw.length; ) {
const len = runLength(raw, i) || 1;
const own = stacks[raw.slice(i, i + len)];
const before = raw[i - 1];
const after = raw[i + len];
const at = own && isInner(before) && isOuter(after) ? own.pop() : undefined;
if (at !== undefined) {
for (let m = 0; m < len; m++) marked[at + m] = marked[i + m] = true;
for (const st of Object.values(stacks)) while ((st[st.length - 1] ?? -1) > at) st.pop();
} else if (own && isOuter(before) && isInner(after)) own.push(i);
i += len;
}
let out = "";
for (let i = from; i < raw.length; i++) if (!marked[i]) out += raw[i];
return out;
}
Loading
Loading