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

@ -28,8 +28,7 @@ class GameManager {
settings: {
songsPerPlayer: 3,
maxPlayers: 10,
minPlayers: 3,
requireYoutubeLinks: false
minPlayers: 3
},
players: [{
id: hostId,
@ -300,15 +299,12 @@ class GameManager {
return { error: 'Maximum number of songs reached' };
}
// We only require the YouTube link now
if (!song.youtubeLink) {
return { error: 'YouTube link is required' };
}
// If the YouTube link isn't valid, return an error
const videoId = await youtubeAPI.extractVideoId(song.youtubeLink);
if (!videoId) {
return { error: 'Invalid YouTube link' };
// If we have a YouTube link, validate it
if (song.youtubeLink) {
const videoId = await youtubeAPI.extractVideoId(song.youtubeLink);
if (!videoId) {
return { error: 'Invalid YouTube link' };
}
}
// Handle async metadata fetching
@ -329,6 +325,20 @@ class GameManager {
}
}
/**
* Get metadata for a single YouTube video
* @param {string} videoId - YouTube video ID
* @returns {Promise<Object>} Video metadata
*/
async getYouTubeVideoMetadata(videoId) {
try {
return await youtubeAPI.getVideoMetadata(videoId);
} catch (error) {
console.error('Error getting YouTube video metadata:', error);
return { error: 'Failed to get video metadata' };
}
}
/**
* Helper method to add a song to a player
* @param {number} playerIndex - Index of the player in the lobby