feat(spotify): implement milestone M4 importers
This commit is contained in:
38
skills/spotify/tests/m3u.test.ts
Normal file
38
skills/spotify/tests/m3u.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { test } from "node:test";
|
||||
|
||||
import { parseM3u, readM3u } from "../src/importers/m3u.js";
|
||||
|
||||
test("parses EXTINF metadata and ignores comments", () => {
|
||||
const refs = parseM3u(`#EXTM3U
|
||||
#EXTINF:123,Radiohead - Karma Police
|
||||
/music/01 - ignored filename.mp3
|
||||
# comment
|
||||
#EXTINF:123,Massive Attack - Teardrop
|
||||
/music/02 - fallback.mp3
|
||||
`);
|
||||
|
||||
assert.equal(refs.some((ref) => ref.artist === "Radiohead" && ref.title === "Karma Police"), true);
|
||||
assert.equal(refs.some((ref) => ref.artist === "Massive Attack" && ref.title === "Teardrop"), true);
|
||||
});
|
||||
|
||||
test("falls back to filename when EXTINF is absent", () => {
|
||||
const refs = parseM3u("/music/01 - Radiohead - Karma Police.flac\n");
|
||||
|
||||
assert.equal(refs[0].artist, "Radiohead");
|
||||
assert.equal(refs[0].title, "Karma Police");
|
||||
});
|
||||
|
||||
test("reads m3u from file", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "spotify-m3u-"));
|
||||
const path = join(root, "playlist.m3u8");
|
||||
await writeFile(path, "#EXTINF:123,Radiohead - Karma Police\n/music/track.mp3\n");
|
||||
|
||||
const refs = await readM3u(path);
|
||||
|
||||
assert.equal(refs[0].artist, "Radiohead");
|
||||
assert.equal(refs[0].title, "Karma Police");
|
||||
});
|
||||
Reference in New Issue
Block a user