51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
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("falls back to the filename from Windows paths", () => {
|
|
const refs = parseM3u(String.raw`C:\Users\fiori\iCloudDrive\Music\Classic Hits\Owner of a Lonely Heart.mp3`);
|
|
|
|
assert.deepEqual(refs, [
|
|
{
|
|
source: "Owner of a Lonely Heart",
|
|
query: "Owner of a Lonely Heart",
|
|
title: "Owner of a Lonely Heart"
|
|
}
|
|
]);
|
|
});
|
|
|
|
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");
|
|
});
|