diff --git a/webui/static/script.js b/webui/static/script.js index 9dc0fb9b..e88ac5df 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -2713,7 +2713,152 @@ async function openDownloadMissingModal(playlistId) { modal.style.display = 'flex'; } +async function openDownloadMissingModalForYouTube(virtualPlaylistId, playlistName, spotifyTracks) { + // Check if a process is already active for this virtual playlist + if (activeDownloadProcesses[virtualPlaylistId]) { + console.log(`Modal for ${virtualPlaylistId} already exists. Showing it.`); + const process = activeDownloadProcesses[virtualPlaylistId]; + if (process.modalElement) { + if (process.status === 'complete') { + showToast('Showing previous results. Close this modal to start a new analysis.', 'info'); + } + process.modalElement.style.display = 'flex'; + } + return; + } + console.log(`📥 Opening Download Missing Tracks modal for YouTube playlist: ${virtualPlaylistId}`); + + // Create virtual playlist object for compatibility with existing modal logic + const virtualPlaylist = { + id: virtualPlaylistId, + name: playlistName, + track_count: spotifyTracks.length + }; + + // Store the tracks in the cache for the modal to use + playlistTrackCache[virtualPlaylistId] = spotifyTracks; + currentPlaylistTracks = spotifyTracks; + currentModalPlaylistId = virtualPlaylistId; + + let modal = document.createElement('div'); + modal.id = `download-missing-modal-${virtualPlaylistId}`; + modal.className = 'download-missing-modal'; + modal.style.display = 'none'; + document.body.appendChild(modal); + + // Register the new process in our global state tracker using the same structure as Spotify + activeDownloadProcesses[virtualPlaylistId] = { + status: 'idle', + modalElement: modal, + poller: null, + batchId: null, + playlist: virtualPlaylist, + tracks: spotifyTracks + }; + + // Use the exact same modal HTML structure as the existing Spotify modal + modal.innerHTML = ` +
+ `; + + modal.style.display = 'flex'; +} function closeDownloadMissingModal(playlistId) { const process = activeDownloadProcesses[playlistId]; @@ -7108,8 +7253,8 @@ async function startYouTubeDownloadMissing(urlHash) { // Store reference for card navigation state.convertedSpotifyPlaylistId = virtualPlaylistId; - // Open the existing download missing tracks modal - await openDownloadMissingModal(virtualPlaylistId, playlistName, spotifyTracks); + // Open download missing tracks modal for YouTube playlist + await openDownloadMissingModalForYouTube(virtualPlaylistId, playlistName, spotifyTracks); // Update YouTube card phase when download process starts updateYouTubeCardPhase(urlHash, 'downloading');