mirror of
https://github.com/markuryy/shark.git
synced 2025-12-12 11:41:02 +00:00
feat(services): improve lyrics fetch progress and status updates
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { settings } from '$lib/stores/settings';
|
||||
import { setSuccess, setWarning, setError, setInfo } from '$lib/stores/status';
|
||||
import { setSuccess, setWarning, setError, setInfo, removeStatus } from '$lib/stores/status';
|
||||
import { checkApiStatus, fetchAndSaveLyrics } from '$lib/services/lrclib';
|
||||
import { scanForTracksWithoutLyrics, loadCachedTracksWithoutLyrics, type TrackWithoutLyrics } from '$lib/library/lyricScanner';
|
||||
import { getLyricsScanTimestamp, upsertTrack } from '$lib/library/database';
|
||||
@@ -116,13 +116,16 @@
|
||||
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
const totalTracks = tracks.length;
|
||||
|
||||
setInfo(`Fetching lyrics for ${tracks.length} tracks...`, 0);
|
||||
// Create a single status message that we'll update
|
||||
const statusId = setInfo(`Fetching lyrics... 0/${totalTracks}`, 0);
|
||||
|
||||
const tracksCopy = [...tracks];
|
||||
|
||||
for (let i = 0; i < tracksCopy.length; i++) {
|
||||
const track = tracksCopy[i];
|
||||
// Process tracks one by one, removing from array as we go
|
||||
let processedCount = 0;
|
||||
while (tracks.length > 0) {
|
||||
const track = tracks[0]; // Always process first track
|
||||
processedCount++;
|
||||
|
||||
try {
|
||||
const result = await fetchAndSaveLyrics(track.path, {
|
||||
@@ -133,23 +136,37 @@
|
||||
});
|
||||
|
||||
if (result.success && (result.hasLyrics || result.instrumental)) {
|
||||
// Update database to mark track as having lyrics
|
||||
await upsertTrack({
|
||||
path: track.path,
|
||||
title: track.title,
|
||||
artist: track.artist,
|
||||
album: track.album,
|
||||
duration: Math.round(track.duration),
|
||||
format: track.format,
|
||||
has_lyrics: true
|
||||
});
|
||||
|
||||
successCount++;
|
||||
// Remove from UI immediately on success
|
||||
tracks = tracks.slice(1);
|
||||
} else {
|
||||
failCount++;
|
||||
// Remove from list even if no lyrics found
|
||||
tracks = tracks.slice(1);
|
||||
}
|
||||
} catch (error) {
|
||||
failCount++;
|
||||
// Remove from list on error
|
||||
tracks = tracks.slice(1);
|
||||
}
|
||||
|
||||
// Update progress
|
||||
if ((i + 1) % 10 === 0 || i === tracksCopy.length - 1) {
|
||||
setInfo(`Fetching lyrics... ${i + 1}/${tracksCopy.length}`, 0);
|
||||
}
|
||||
// Update progress message
|
||||
setInfo(`Fetching lyrics... ${processedCount}/${totalTracks}`, 0);
|
||||
}
|
||||
|
||||
// Rescan to update the list
|
||||
tracks = [];
|
||||
await handleScan();
|
||||
// Remove the progress message
|
||||
removeStatus(statusId);
|
||||
|
||||
// Show completion message
|
||||
if (successCount > 0 && failCount > 0) {
|
||||
@@ -377,12 +394,6 @@
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.status-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
font-weight: bold;
|
||||
font-size: 11px;
|
||||
|
||||
Reference in New Issue
Block a user