Refactor song submission process to include YouTube metadata fetching; remove YouTube link requirement from settings for improved flexibility

This commit is contained in:
2025-04-24 20:04:26 +02:00
parent 77df851e95
commit a7929cf144
5 changed files with 167 additions and 84 deletions

View File

@ -150,10 +150,11 @@ io.on('connection', (socket) => {
});
// Add a song
socket.on('add_song', ({ song }, callback) => {
socket.on('add_song', async ({ song }, callback) => {
try {
console.log(`[DEBUG] Attempting to add song: ${JSON.stringify(song)}`);
const result = gameManager.addSong(socket.id, song);
// Fix: Properly await the result of the async addSong function
const result = await gameManager.addSong(socket.id, song);
if (result.error) {
console.log(`[DEBUG] Error adding song: ${result.error}`);
@ -225,6 +226,24 @@ io.on('connection', (socket) => {
}
});
// Get metadata for a single YouTube video
socket.on('get_video_metadata', async ({ videoId }, callback) => {
try {
if (!videoId || typeof videoId !== 'string') {
if (callback) callback({ error: 'Invalid video ID' });
return;
}
const metadata = await gameManager.getYouTubeVideoMetadata(videoId);
// Send response to client
if (callback) callback({ metadata });
} catch (error) {
console.error('Error getting YouTube metadata:', error);
if (callback) callback({ error: 'Failed to get YouTube metadata' });
}
});
// Mark player as ready
socket.on('player_ready', (_, callback) => {
try {