Route import through automation engine and show per-track progress
- 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
This commit is contained in:
parent
68b4aace68
commit
4786dc21ec
2 changed files with 44 additions and 35 deletions
|
|
@ -47498,24 +47498,26 @@ def import_album_process():
|
||||||
errors.append(err_msg)
|
errors.append(err_msg)
|
||||||
logger.error(f"Import processing error: {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")
|
add_activity_item("📥", "Album Imported", f"{album_name} by {artist_name} ({processed}/{len(matches)} tracks)", "Now")
|
||||||
|
|
||||||
try:
|
# Emit events through automation engine — same chain as download batches
|
||||||
if automation_engine:
|
# batch_complete → auto-scan → library_scan_completed → auto-update DB
|
||||||
automation_engine.emit('import_completed', {
|
if processed > 0:
|
||||||
'track_count': str(processed),
|
try:
|
||||||
'album_name': album_name or '',
|
if automation_engine:
|
||||||
'artist': artist_name or '',
|
automation_engine.emit('import_completed', {
|
||||||
})
|
'track_count': str(processed),
|
||||||
except Exception:
|
'album_name': album_name or '',
|
||||||
pass
|
'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
|
# Rebuild suggestions cache since staging contents changed
|
||||||
if processed > 0:
|
if processed > 0:
|
||||||
|
|
@ -47756,24 +47758,26 @@ def import_singles_process():
|
||||||
errors.append(err_msg)
|
errors.append(err_msg)
|
||||||
logger.error(f"Import single processing error: {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")
|
add_activity_item("📥", "Singles Imported", f"{processed}/{len(files)} tracks processed", "Now")
|
||||||
|
|
||||||
try:
|
# Emit events through automation engine — same chain as download batches
|
||||||
if automation_engine:
|
# batch_complete → auto-scan → library_scan_completed → auto-update DB
|
||||||
automation_engine.emit('import_completed', {
|
if processed > 0:
|
||||||
'track_count': str(processed),
|
try:
|
||||||
'album_name': '',
|
if automation_engine:
|
||||||
'artist': 'Various',
|
automation_engine.emit('import_completed', {
|
||||||
})
|
'track_count': str(processed),
|
||||||
except Exception:
|
'album_name': '',
|
||||||
pass
|
'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
|
# Rebuild suggestions cache since staging contents changed
|
||||||
if processed > 0:
|
if processed > 0:
|
||||||
|
|
|
||||||
|
|
@ -60255,6 +60255,14 @@ function _importQueueAdd(job) {
|
||||||
|
|
||||||
async function _importQueueRunJob(entry, job) {
|
async function _importQueueRunJob(entry, job) {
|
||||||
for (let i = 0; i < job.items.length; i++) {
|
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 {
|
try {
|
||||||
let resp;
|
let resp;
|
||||||
if (job.type === 'album') {
|
if (job.type === 'album') {
|
||||||
|
|
@ -60279,9 +60287,6 @@ async function _importQueueRunJob(entry, job) {
|
||||||
if (data.success) entry.processed += (data.processed || 0);
|
if (data.success) entry.processed += (data.processed || 0);
|
||||||
if (data.errors && data.errors.length > 0) entry.errors.push(...data.errors);
|
if (data.errors && data.errors.length > 0) entry.errors.push(...data.errors);
|
||||||
} catch (err) {
|
} 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}`);
|
entry.errors.push(`${itemName}: ${err.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue