From 4786dc21ecbc8c1e42e9e546d41250e8969f6a10 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Thu, 2 Apr 2026 08:34:01 -0700 Subject: [PATCH] Route import through automation engine and show per-track progress MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove direct request_scan() calls from album and singles import — emit batch_complete through automation engine instead, matching the same chain as download batches (scan → DB update) - Show current track name in import queue status display instead of just processed/total count --- web_server.py | 68 ++++++++++++++++++++++-------------------- webui/static/script.js | 11 +++++-- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/web_server.py b/web_server.py index e32d74d6..92ba2eb8 100644 --- a/web_server.py +++ b/web_server.py @@ -47498,24 +47498,26 @@ def import_album_process(): errors.append(err_msg) logger.error(f"Import processing error: {err_msg}") - # Trigger library scan - if web_scan_manager and processed > 0: - threading.Thread( - target=lambda: web_scan_manager.request_scan("Import album processed"), - daemon=True - ).start() - add_activity_item("📥", "Album Imported", f"{album_name} by {artist_name} ({processed}/{len(matches)} tracks)", "Now") - try: - if automation_engine: - automation_engine.emit('import_completed', { - 'track_count': str(processed), - 'album_name': album_name or '', - 'artist': artist_name or '', - }) - except Exception: - pass + # Emit events through automation engine — same chain as download batches + # batch_complete → auto-scan → library_scan_completed → auto-update DB + if processed > 0: + try: + if automation_engine: + automation_engine.emit('import_completed', { + 'track_count': str(processed), + 'album_name': album_name or '', + 'artist': artist_name or '', + }) + automation_engine.emit('batch_complete', { + 'playlist_name': f"Import: {album_name}" if album_name else 'Import', + 'total_tracks': str(len(matches)), + 'completed_tracks': str(processed), + 'failed_tracks': str(len(errors)), + }) + except Exception: + pass # Rebuild suggestions cache since staging contents changed if processed > 0: @@ -47756,24 +47758,26 @@ def import_singles_process(): errors.append(err_msg) logger.error(f"Import single processing error: {err_msg}") - # Trigger library scan - if web_scan_manager and processed > 0: - threading.Thread( - target=lambda: web_scan_manager.request_scan("Import singles processed"), - daemon=True - ).start() - add_activity_item("📥", "Singles Imported", f"{processed}/{len(files)} tracks processed", "Now") - try: - if automation_engine: - automation_engine.emit('import_completed', { - 'track_count': str(processed), - 'album_name': '', - 'artist': 'Various', - }) - except Exception: - pass + # Emit events through automation engine — same chain as download batches + # batch_complete → auto-scan → library_scan_completed → auto-update DB + if processed > 0: + try: + if automation_engine: + automation_engine.emit('import_completed', { + 'track_count': str(processed), + 'album_name': '', + 'artist': 'Various', + }) + automation_engine.emit('batch_complete', { + 'playlist_name': 'Import: Singles', + 'total_tracks': str(len(files)), + 'completed_tracks': str(processed), + 'failed_tracks': str(len(errors)), + }) + except Exception: + pass # Rebuild suggestions cache since staging contents changed if processed > 0: diff --git a/webui/static/script.js b/webui/static/script.js index f856787b..0f7e84c8 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -60255,6 +60255,14 @@ function _importQueueAdd(job) { async function _importQueueRunJob(entry, job) { for (let i = 0; i < job.items.length; i++) { + const itemName = job.type === 'album' + ? (job.items[i].spotify_track?.name || `Track ${i + 1}`) + : (job.items[i].title || job.items[i].filename || `File ${i + 1}`); + + // Update status with current track info + entry.sublabel = `Processing ${i + 1}/${job.items.length}: ${itemName}`; + _importQueueRender(); + try { let resp; if (job.type === 'album') { @@ -60279,9 +60287,6 @@ async function _importQueueRunJob(entry, job) { if (data.success) entry.processed += (data.processed || 0); if (data.errors && data.errors.length > 0) entry.errors.push(...data.errors); } catch (err) { - const itemName = job.type === 'album' - ? (job.items[i].spotify_track?.name || `Track ${i + 1}`) - : (job.items[i].title || job.items[i].filename || `File ${i + 1}`); entry.errors.push(`${itemName}: ${err.message}`); }