trackparse 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@ Parse music track names into structured metadata: artists, featured artists, rem
9
9
 
10
10
  This is the JavaScript/TypeScript reference implementation of the
11
11
  [trackparse spec](https://github.com/4matic/trackparse/blob/main/spec/SPEC.md). It passes all
12
- 15,000+ shared fixtures. Zero dependencies, ESM and CommonJS, TypeScript types included, never
12
+ 12,965 shared fixtures. Zero dependencies, ESM and CommonJS, TypeScript types included, never
13
13
  throws.
14
14
 
15
15
  The principle is **extract, don't delete**: everything recognised lands in a field (artists with
@@ -127,13 +127,13 @@ r.junk; // [ { raw: 'Full Album', kind: 'other' } ]
127
127
 
128
128
  ### `SPEC_VERSION`
129
129
 
130
- The spec version this build implements (`"0.1.0"`).
130
+ The spec version this build implements, e.g. `"0.3.0"`. Always equal to the package version.
131
131
 
132
132
  ## Options
133
133
 
134
134
  | Option | Default | Effect |
135
135
  |---|---|---|
136
- | `mode` | `"auto"` | `"clean"` (tags, store metadata), `"youtube"` (video titles), `"filename"`, or `"auto"` to detect. |
136
+ | `mode` | `"auto"` | `"clean"` (tags, store metadata), `"youtube"` (video titles), `"filename"`, `"tracklist"` (one line of a tracklist), or `"auto"` to detect. |
137
137
  | `uploader` | – | YouTube channel, used as the artist when no separator is found. ` - Topic` and `VEVO` are stripped. |
138
138
  | `knownArtists` | `[]` | Names never split (`Chase & Status`). There is no built-in list. |
139
139
  | `splitAnd` | `"auto"` | `and` splits only after a comma in the same list (`A, B and C`), so `Simon and Garfunkel` stays one. `"always"` / `"never"`. |
@@ -157,7 +157,7 @@ All types are exported (`import type { ParsedTrack } from "trackparse"`).
157
157
  ```ts
158
158
  interface ParsedTrack {
159
159
  input: string; // original, untouched
160
- mode: "clean" | "youtube" | "filename"; // resolved mode
160
+ mode: "clean" | "youtube" | "filename" | "tracklist"; // resolved mode
161
161
  position: { raw: string; number: number } | null;
162
162
  timestamp: { raw: string; seconds: number } | null;
163
163
  artists: Artist[]; // primary, featured, producer (not remixers)
@@ -201,9 +201,91 @@ The full field reference, a gallery of examples and the comparison with other li
201
201
  [spec](https://github.com/4matic/trackparse/blob/main/spec/SPEC.md) and its
202
202
  [fixtures](https://github.com/4matic/trackparse/tree/main/spec/fixtures).
203
203
 
204
+ ## Tracklists
205
+
206
+ `trackparse/tracklist` parses a whole tracklist: one entry per line with its kind, start time and
207
+ a full `ParsedTrack`, plus checks with line numbers. Joining `raw + eol` over the entries gives the
208
+ input back byte for byte, whatever the line endings. It's a separate entry point (about 7.6 KiB
209
+ gzipped), so you only pay for it if you import it.
210
+
211
+ ```js
212
+ import { applyEdits, parseTracklist } from "trackparse/tracklist";
213
+ // const { applyEdits, parseTracklist } = require("trackparse/tracklist");
214
+
215
+ const text = [
216
+ "Hour 2",
217
+ "48:20 Noisia - Stigma",
218
+ "52:47 Mefjus & Kasra - Bandwagon (Phace Remix)",
219
+ "56:05 Black Sun Empire - ID",
220
+ "59:31 Alix Perez - Fade Away",
221
+ "01:03:10 Interview with Hybris",
222
+ "01:07:44 Imanu - Sacrifice",
223
+ "00:11:02 Current Value feat. Teddy Killerz - Payload", // typo for 01:11:02
224
+ "01:15:36 Hybris - Spinning Top",
225
+ ].join("\r\n");
226
+
227
+ const list = parseTracklist(text);
228
+
229
+ list.entries.map((e) => e.kind);
230
+ // [ 'header', 'track', 'track', 'track', 'track', 'marker', 'track', 'track', 'track' ]
231
+ list.entries[2].time; // { raw: '52:47', seconds: 3167 }
232
+ list.entries[2].track.versions[0].type; // 'remix'
233
+ list.entries[3].track.flags.unknownTitle; // true
234
+
235
+ list.warnings;
236
+ // [
237
+ // { code: 'no-start-at-zero', line: 2, severity: 'info', suggestion: null },
238
+ // { code: 'time-out-of-order', line: 8, severity: 'warning',
239
+ // suggestion: { line: 8, raw: '01:11:02', seconds: 4262 } }
240
+ // ]
241
+ list.stats;
242
+ // { lines: 9, tracks: 7, markers: 1, timed: 8, firstTime: 2900, lastTime: 4536 }
243
+ ```
244
+
245
+ `applyEdits` rewrites only the lines you name. Times keep their line's style, and the rest of the
246
+ text, CRLF included, stays as it was:
247
+
248
+ ```js
249
+ const fix = list.warnings[1].suggestion;
250
+ const result = applyEdits(text, [
251
+ { op: "set-time", line: fix.line, seconds: fix.seconds },
252
+ { op: "shift", seconds: 45, from: 5 },
253
+ ]);
254
+
255
+ result.changed; // [ 5, 6, 7, 8, 9 ]
256
+ result.warnings; // [ { code: 'style-upgraded', edit: 1, line: 5 } ]
257
+ result.text.split("\r\n")[4]; // '01:00:16 Alix Perez - Fade Away' (was 59:31)
258
+ ```
259
+
260
+ Edits: `set-time {line, seconds}`, `shift {seconds, lines? | from?}`
261
+ (all timed lines when neither is given), `sort-by-time {}`, `set-rest {line, rest}`,
262
+ `insert {after, text}` (`after: 0` inserts at the top), `delete {line}`.
263
+ A bad edit changes nothing and warns `edit-invalid`; a time pushed below zero stops at zero and
264
+ warns `time-clamped`.
265
+
266
+ Warning codes: `time-missing`, `time-out-of-order` (with a one- or two-digit `suggestion` when
267
+ exactly one fix fits), `time-duplicate`, `no-start-at-zero`, `time-after-audio-end` (pass
268
+ `audioSeconds`), `invalid-time`, `position-gap`, `position-duplicate`, `line-unparsed`.
269
+
270
+ Options: `mode` (default `"tracklist"`), `knownArtists`, `splitAnd`, `keywords`, `audioSeconds`,
271
+ `markerWords`. Every type is exported (`import type { Tracklist, Edit } from
272
+ "trackparse/tracklist"`).
273
+
274
+ Each line is parsed with `mode: "tracklist"`, where the first spaced dash always separates artist
275
+ and title. `parse()` takes it too:
276
+
277
+ ```js
278
+ parse("Electrosoul System - Liquid Metal").title; // 'Electrosoul System'
279
+ parse("Electrosoul System - Liquid Metal", { mode: "tracklist" }).title; // 'Liquid Metal'
280
+ ```
281
+
282
+ Field tables and the full list of rules: [main README](https://github.com/4matic/trackparse#tracklists)
283
+ and [SPEC R13](https://github.com/4matic/trackparse/blob/main/spec/SPEC.md#r13-tracklists).
284
+
204
285
  ## Limitations
205
286
 
206
- One track string per call (no multi-line tracklists yet), no label/catalog, key or BPM fields, and
287
+ One track string per `parse()` call; tracklists go through `trackparse/tracklist`, which reads
288
+ start times only (no durations, trailing times or ranges). No label/catalog, key or BPM fields, and
207
289
  no built-in artist database: pass `knownArtists` for names that contain a joiner.
208
290
 
209
291
  ## License