Add custom playlists
This commit is contained in:
@ -1,6 +1,17 @@
|
||||
const { google } = require('googleapis');
|
||||
const youtube = google.youtube('v3');
|
||||
|
||||
const YOUTUBE_API_KEY = process.env.YOUTUBE_API_KEY;
|
||||
const PLAYLIST_ID = "PLmXxqSJJq-yXrCPGIT2gn8b34JjOrl4Xf";
|
||||
|
||||
const PLAYLISTS = {
|
||||
seventies: 'PLmXxqSJJq-yXrCPGIT2gn8b34JjOrl4Xf',
|
||||
eighties: 'PLmXxqSJJq-yUvMWKuZQAB_8yxnjZaOZUp',
|
||||
nineties: 'PLmXxqSJJq-yUF3jbzjF_pa--kuBuMlyQQ'
|
||||
};
|
||||
|
||||
const API_KEY = process.env.YOUTUBE_API_KEY;
|
||||
|
||||
let cachedSongs = null;
|
||||
let lastFetchTime = 0;
|
||||
const CACHE_TTL = 3600000; // 1 hour
|
||||
@ -68,4 +79,38 @@ const getAvailableSongIds = async () => {
|
||||
return songs.map(song => song.id);
|
||||
};
|
||||
|
||||
module.exports = {fetchPlaylistSongs, getAvailableSongIds};
|
||||
async function getPlaylistDetails() {
|
||||
try {
|
||||
const details = {};
|
||||
|
||||
for (const [genre, playlistId] of Object.entries(PLAYLISTS)) {
|
||||
const response = await youtube.playlists.list({
|
||||
key: API_KEY,
|
||||
part: 'snippet,contentDetails',
|
||||
id: playlistId
|
||||
});
|
||||
|
||||
const playlist = response.data.items[0];
|
||||
details[genre] = {
|
||||
id: playlistId,
|
||||
title: playlist.snippet.title,
|
||||
description: playlist.snippet.description,
|
||||
thumbnail: playlist.snippet.thumbnails.maxres || playlist.snippet.thumbnails.high,
|
||||
songCount: playlist.contentDetails.itemCount,
|
||||
votes: 0
|
||||
};
|
||||
}
|
||||
|
||||
return details;
|
||||
} catch (error) {
|
||||
console.error('Error fetching playlist details:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchPlaylistSongs,
|
||||
getAvailableSongIds,
|
||||
PLAYLISTS,
|
||||
getPlaylistDetails
|
||||
};
|
||||
|
Reference in New Issue
Block a user