From bd2866b34822e7183ec27498894d9b33438a3608 Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Sun, 31 Aug 2025 21:44:26 -0700 Subject: [PATCH] Update script.js --- webui/static/script.js | 149 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 2 deletions(-) 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 = ` +
+
+

Download Missing Tracks - ${escapeHtml(playlistName)}

+ × +
+ +
+
+
+
${spotifyTracks.length}
+
Total Tracks
+
+
+
-
+
Found in Library
+
+
+
-
+
Missing Tracks
+
+
+
0
+
Downloaded
+
+
+ +
+
+
+ 🔍 Library Analysis + Ready to start +
+
+
+
+
+
+
+ ⏬ Downloads + Waiting for analysis +
+
+
+
+
+
+ +
+
+

📋 Track Analysis & Download Status

+
+
+ + + + + + + + + + + + + + ${spotifyTracks.map((track, index) => ` + + + + + + + + + + `).join('')} + +
#TrackArtistDurationLibrary MatchDownload StatusActions
${index + 1}${escapeHtml(track.name)}${track.artists.join(', ')}${formatDuration(track.duration_ms)}🔍 Pending--
+
+
+
+ + +
+ `; + + 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');