import "../setup.ts"; import { assertEquals } from "@std/assert"; import { parsePlaylistPage } from "../../remote/youtube-playlist.ts"; function ytPage(data: unknown): string { return ``; } const YT_DATA = { metadata: { playlistMetadataRenderer: { title: "My mix" } }, contents: { list: [ { lockupViewModel: { contentType: "LOCKUP_CONTENT_TYPE_VIDEO", contentId: "vid1", metadata: { lockupMetadataViewModel: { title: { content: "First" } }, }, contentImage: { overlays: [{ thumbnailBadgeViewModel: { text: "1:02:03" } }], }, }, }, { lockupViewModel: { contentType: "LOCKUP_CONTENT_TYPE_PLAYLIST", contentId: "ignored", }, }, { playlistVideoRenderer: { videoId: "vid2", title: { runs: [{ text: "Second" }] }, lengthSeconds: "235", }, }, ], }, }; Deno.test("parsePlaylistPage: current and legacy rows", () => { assertEquals(parsePlaylistPage(ytPage(YT_DATA), "PLx"), { listId: "PLx", title: "My mix", tracks: [ { videoId: "vid1", title: "First", duration: 3723 }, { videoId: "vid2", title: "Second", duration: 235 }, ], }); assertEquals(parsePlaylistPage("", "PLx"), null); assertEquals(parsePlaylistPage(ytPage({ contents: {} }), "PLx"), null); });