All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import "../setup.ts";
|
|
import { assertEquals } from "@std/assert";
|
|
import { parsePlaylistPage } from "../../remote/youtube-playlist.ts";
|
|
|
|
function ytPage(data: unknown): string {
|
|
return `<script>var ytInitialData = ${JSON.stringify(data)};</script>`;
|
|
}
|
|
|
|
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("<html></html>", "PLx"), null);
|
|
assertEquals(parsePlaylistPage(ytPage({ contents: {} }), "PLx"), null);
|
|
});
|