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
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Every key is always present. When a guess was involved, `warnings` says which on
| **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 8.3 kB, only if you import it |
| **0** dependencies | ESM + CJS + TypeScript types, about 17 kB gzipped. `trackparse/tracklist` adds about 8.3 KiB, 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,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 |
Expand Down Expand Up @@ -313,12 +313,14 @@ 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)).
Lists pasted from Discord, Reddit, Telegram 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`. Away from the time, a `*` or `_` only counts as emphasis when it has a partner on the line,
so `P*nk`, `DJ_Name` and a censored `F**k` keep their stars and underscores
([details](https://4matic.github.io/trackparse/guides/tracklists/#markdown)). A line whose track
text starts with `w/` is `layered`: a track played over the previous one
([layered tracks](https://4matic.github.io/trackparse/guides/tracklists/#layered-tracks)).

### Tracklist mode

Expand Down Expand Up @@ -422,7 +424,8 @@ For tracklists, on random multi-line text and random edit lists:
- 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()` in tracklist mode on its text without Markdown
emphasis or a leading `w/`;
- Markdown emphasis around a time or a track line changes nothing.
- Markdown emphasis around a time or a track line gives the same kind, time and track as the plain
line.

### Real tracklists

Expand Down Expand Up @@ -570,7 +573,7 @@ that only parses single tracks never loads it.
| `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, 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 |
| `layered` | `boolean` | The track text (after any time) starts with `w/` and a space: 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 Down
3 changes: 2 additions & 1 deletion js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ exactly one fix fits), `time-duplicate`, `no-start-at-zero`, `time-after-audio-e

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
A line whose track text (after any time) starts 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)).

Expand Down
5 changes: 3 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ apply_edits(text, edits, *, <same options>) -> EditResult
| Result | Fields |
|---|---|
| `Tracklist` | `spec_version`, `entries`, `warnings`, `stats` |
| `TracklistEntry` | `line` (1-based), `kind` (`track`, `marker`, `header`, `link`, `note`, `blank`), `eol`, `raw`, `parts`, `time`, `track` (`ParsedTrack` or `None`), `layered` (the line starts with `w/`) |
| `TracklistEntry` | `line` (1-based), `kind` (`track`, `marker`, `header`, `link`, `note`, `blank`), `eol`, `raw`, `parts`, `time`, `track` (`ParsedTrack` or `None`), `layered` (the track text after any time starts with `w/`) |
| `Parts` | `lead`, `time`, `gap`, `rest`, joined they give `raw` |
| `TracklistWarning` | `code`, `line`, `severity` (`info` or `warning`), `suggestion` |
| `TimeValue` | `raw`, `seconds` (`entry.time`, or `None` on untimed lines) |
Expand All @@ -438,7 +438,8 @@ apply_edits(text, edits, *, <same options>) -> EditResult

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
A line whose track text (after any time) starts 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)).

Expand Down
37 changes: 32 additions & 5 deletions site/src/components/Playground.astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ const sample = [
"00:11:02 Current Value feat. Teddy Killerz - Payload",
"01:15:36 Hybris - Spinning Top",
].join("\n");

// Pasted from a chat or a comment: list bullets, Markdown emphasis and a layered `w/` line.
const markdownSample = [
"**Tracklist**",
"* 00:00 Noisia - Stigma",
"* 03:30 **Phace** - Psycho",
"**[**07:10**] 3. Mefjus - Sleepless**",
"w/ Hybris - Spinning Top (Acapella)",
"[10:45] Imanu - _Sacrifice_",
"* 14:20 Black Sun Empire - ID",
].join("\n");
---

<div class="pg not-content">
Expand Down Expand Up @@ -151,7 +162,13 @@ const sample = [
<label class="tp-label" for="tl-input">Tracklist text</label>
<span class="tp-muted" id="tl-meta"></span>
</div>
<textarea id="tl-input" class="tp-input" spellcheck="false" data-sample={sample}></textarea>
<textarea
id="tl-input"
class="tp-input"
spellcheck="false"
data-sample={sample}
data-sample-markdown={markdownSample}
></textarea>
<div class="tp-row">
<div>
<label class="tp-label" for="tl-audio">audioSeconds</label>
Expand All @@ -171,6 +188,7 @@ const sample = [
<div class="tp-row">
<button type="button" class="tp-btn small" id="tl-undo" disabled><Undo2 size={14} aria-hidden="true" /> Undo edit</button>
<button type="button" class="tp-btn small" id="tl-sample"><FileText size={14} aria-hidden="true" /> Load the sample</button>
<button type="button" class="tp-btn small" id="tl-sample-markdown"><FileText size={14} aria-hidden="true" /> Pasted with Markdown</button>
<button type="button" class="tp-btn small" data-copy="tl-input"><Copy size={14} aria-hidden="true" /><span>Copy text</span></button>
</div>
<p class="tp-muted" id="tl-editlog" aria-live="polite"></p>
Expand Down Expand Up @@ -593,8 +611,10 @@ const sample = [
const title = t ? escapeHtml(t.title) : `<span class="tp-none">${escapeHtml(e.raw.trim())}</span>`;
const vers = t ? t.versions.map((v) => chip(v.artists[0] ? `${v.type} · ${v.artists[0].name}` : v.type, "version")).join(" ") : "";
const pos = t?.position ? `${chip(`#${t.position.number}`, "position")} ` : "";
// R13.13: a `w/` line plays over the previous track.
const layered = e.layered ? `${chip("w/", "position", "Layered: played over the previous track")} ` : "";
const cls = [warn ? "is-warn" : "", changed.has(e.line) ? "is-changed" : ""].join(" ").trim();
return `<tr class="${cls}" id="tl-line-${e.line}"><td class="tl-num">${e.line}</td><td class="tl-kind${e.kind === "track" ? "" : " is-other"}">${e.kind}</td><td class="tl-time">${e.time ? escapeHtml(e.time.raw) : ""}</td><td>${pos}${artists}</td><td>${title}</td><td>${vers}</td></tr>`;
return `<tr class="${cls}" id="tl-line-${e.line}"><td class="tl-num">${e.line}</td><td class="tl-kind${e.kind === "track" ? "" : " is-other"}">${e.kind}</td><td class="tl-time">${e.time ? escapeHtml(e.time.raw) : ""}</td><td>${layered}${pos}${artists}</td><td>${title}</td><td>${vers}</td></tr>`;
}

function plural(n: number, word: string): string {
Expand Down Expand Up @@ -703,10 +723,17 @@ const sample = [
$("tl-editlog").textContent = "Undone.";
renderList();
});
$("tl-sample").addEventListener("click", () => {
tl.value = tl.dataset.sample ?? "";
// A sample replaces the text: the edit log and the undo history belong to the old one.
function loadSample(text: string | undefined) {
tl.value = text ?? "";
history_.length = 0;
undoBtn.disabled = true;
changed.clear();
$("tl-editlog").textContent = "";
renderList();
});
}
$("tl-sample").addEventListener("click", () => loadSample(tl.dataset.sample));
$("tl-sample-markdown").addEventListener("click", () => loadSample(tl.dataset.sampleMarkdown));

// ---- start -------------------------------------------------------------------------------
input.value = document.querySelector<HTMLButtonElement>("[data-example]")?.dataset.example ?? "";
Expand Down
36 changes: 36 additions & 0 deletions site/src/content/docs/guides/editing-tracklists.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,42 @@ When a time without hours crosses the hour, it gains hours in the style the rest
(`59:31` → `01:00:16`, or `1:00:16` if the list writes one-digit hours). The edit reports
`style-upgraded` so you know the line got longer.

## Bullets and Markdown stay

A list bullet or Markdown emphasis around a time sits in `lead` and `gap`, so a rewritten time keeps
it. Only the digits change:

<Tabs syncKey="lang">
<TabItem label="JavaScript">

```js
const text = "**[**52:47**] Mefjus - Bandwagon**\n**[**59:31**] Alix Perez - Fade Away**";
const result = applyEdits(text, [{ op: "shift", seconds: 45 }]);

result.text;
// '**[**53:32**] Mefjus - Bandwagon**\n**[**01:00:16**] Alix Perez - Fade Away**'
result.warnings; // [ { code: 'style-upgraded', edit: 0, line: 2 } ]
```

</TabItem>
<TabItem label="Python">

```python
text = "**[**52:47**] Mefjus - Bandwagon**\n**[**59:31**] Alix Perez - Fade Away**"
result = apply_edits(text, [{"op": "shift", "seconds": 45}])

result.text
# '**[**53:32**] Mefjus - Bandwagon**\n**[**01:00:16**] Alix Perez - Fade Away**'
result.warnings # (EditWarning(code='style-upgraded', edit=0, line=2),)
```

</TabItem>
</Tabs>

`set-rest` replaces everything after the gap, including a closing `**` at the end of the line. The
time is still read afterwards, because emphasis next to a time doesn't need a partner. A layered
`w/` line without a time moves with the timed line above it when you sort.

## When an edit can't apply

Edits never throw. A bad one changes nothing and reports why:
Expand Down
10 changes: 6 additions & 4 deletions site/src/content/docs/guides/tracklists.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ b.track.title # 'Stigma'
</TabItem>
</Tabs>

A `*` or `_` only counts as emphasis when it has a partner on the same line and sits against a
space, a bracket or the end of the line on its outer side. So names keep their stars and
underscores: `P*nk`, `*NSYNC`, `DJ_Name`, `Noisia_-_Stigma` and a censored `F**k` come out as
Right next to the time, a run of one or two `*` or `_` is read as emphasis by its position, with or
without a partner, so `**14:21 Artist - Title` still has its time. Anywhere else, a `*` or `_` only
counts when it has a partner on the same line and its outer side is a space, a bracket, another `*`
or `_`, or the end of the line. So names keep their stars and underscores: `P*nk`, `*NSYNC`, `DJ_Name`, `Noisia_-_Stigma` and a censored `F**k` come out as
written. Runs of three or more, `~~`, `||` and backticks are never treated as Markdown.

## Layered tracks
Expand Down Expand Up @@ -218,7 +219,8 @@ tl.warnings # ()
</TabItem>
</Tabs>

Only a leading `w/` (or `W/`) followed by a space counts. `w/` inside a line
Only `w/` (or `W/`) at the start of the track text, after any time or bullet, and followed by
whitespace and a track counts, so `00:30 w/ Phace - Psycho` is layered too. `w/` inside a line
(`Noisia w/ Phace - Stigma`), right after a track number (`10. w/ …`) or glued to the name
(`w/Noisia`) is left alone, and so are `with`, `+` and `x`.

Expand Down
15 changes: 15 additions & 0 deletions site/src/content/docs/guides/what-it-understands.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ it stays in the title. That's the rule: anything unrecognised is left alone.
are fine guesses on YouTube and bad ones in a music library, so the default `clean` mode won't make
them. In `youtube` mode it does, and it tells you through `warnings`. See [Modes](/trackparse/guides/modes/).

## In a tracklist

Lines of a pasted tracklist go through
[`parseTracklist`](/trackparse/guides/tracklists/), which also reads list bullets, Markdown
emphasis and `w/` lines. Each input below is one line; click it to open it in the playground's
tracklist tab.

| Line | Artists | Title | Other fields |
|---|---|---|---|
| [`* 00:00 Noisia - Stigma`](/trackparse/playground/#list=*%2000%3A00%20Noisia%20-%20Stigma) | Noisia | `Stigma` | time 0 s, bullet in `lead` |
| [`**[**00:00**] 10. Nitepunk - ID**`](/trackparse/playground/#list=**%5B**00%3A00**%5D%2010.%20Nitepunk%20-%20ID**) | Nitepunk | `ID` | time 0 s, position 10, `**` kept in `parts` |
| [`00:00 **Noisia** - _Stigma_`](/trackparse/playground/#list=00%3A00%20**Noisia**%20-%20_Stigma_) | Noisia | `Stigma` | time 0 s |
| [`w/ Nitepunk & Habstrakt - Point`](/trackparse/playground/#list=w%2F%20Nitepunk%20%26%20Habstrakt%20-%20Point) | Nitepunk, Habstrakt | `Point` | layered |
| [`00:00 P*nk - Raise Your Glass`](/trackparse/playground/#list=00%3A00%20P*nk%20-%20Raise%20Your%20Glass) | P\*nk | `Raise Your Glass` | the star stays |

## By topic

- [Artists and credits](/trackparse/guides/artists/): joiners, features, producers, `knownArtists`.
Expand Down
3 changes: 2 additions & 1 deletion site/src/content/docs/project/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ 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;
- shifting forward and back restores the text, unless something was clamped or upgraded;
- 10,000 lines parse in linear time (the JS suite allows 3 s; it takes about 0.6 s);
- Markdown emphasis around a time or a track line changes nothing.
- Markdown emphasis around a time or a track line gives the same kind, time and track as the plain
line.

## Port against port

Expand Down
2 changes: 1 addition & 1 deletion site/src/content/docs/reference/tracklist.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ One per line, in order.
| `parts` | `{ lead, time, gap, rest }` | `raw` cut into four strings that join back into it |
| `time` | `{ raw, seconds } \| null` | The start time |
| `track` | `ParsedTrack \| null` | Parsed from `rest` in tracklist mode, without its [Markdown emphasis](/trackparse/guides/tracklists/#markdown), a leading `w/` and a bare track number. Only `track` and `marker` lines have one |
| `layered` | `boolean` | The line starts with `w/`: a [layered track](/trackparse/guides/tracklists/#layered-tracks), played over the previous one |
| `layered` | `boolean` | The track text (after any time) starts with `w/` and a space: a [layered track](/trackparse/guides/tracklists/#layered-tracks), played over the previous one |

### TracklistWarning

Expand Down
Loading