Files
Website/src/routes/about/+page.server.ts
2025-12-06 23:43:32 +00:00

33 lines
955 B
TypeScript

import playdl, { type YouTubeVideo } from 'play-dl';
function shuffleArray(array: any[]) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
/** @type {import('./$types').PageServerLoad} */
export async function load({ params }) {
const playlistUrl = 'https://music.youtube.com/playlist?list=PLHqPHHvmOjJ6JwiYc3Fg-O5JGbVppI1VR&si=pJnM95siw3kQRlnr';
const playlist = await playdl.playlist_info(playlistUrl);
let songs = (await playlist.all_videos()).map((video: YouTubeVideo) => {
return {
title: video.title,
url: video.url,
author: video.channel?.name,
authorUrl: video.channel?.url,
thumbnail: video.thumbnails[0].url,
duration: video.durationRaw,
}
})
return {
songs: shuffleArray(songs)
};
}