Add repair functionality for damaged Qobuz downloads
Problem: Qobuz downloads that were already scanned lost their source = 'qobuz_download' marker. The previous fix only prevents future damage, but doesn't repair existing tracks. Solution: - Added repair_qobuz_download_source() to restore source marker - Modified library_backfill_downloads to repair existing tracks: - When a track exists, try to repair its source marker - Report shows: added, repaired, and skipped counts - This fixes downloads that lost their marker during scans User can now run the backfill command to: 1. Restore source markers for damaged downloads 2. Make "Show in Local Library" setting work correctly 3. Separate Qobuz downloads from scanned music again Files changed: - src-tauri/src/library/database.rs - src-tauri/src/library/commands.rs
This commit is contained in:
1 parent
6073cb96c1
commit
ac77a31b06
2 files changed
+31
-3
No files matched your search
@@ -1408,6 +1408,7 @@ pub async fn library_get_hidden_albums(
|
||||
pub struct BackfillReport {
|
||||
pub total_downloads: usize,
|
||||
pub added_tracks: usize,
|
||||
pub repaired_tracks: usize,
|
||||
pub skipped_tracks: usize,
|
||||
pub failed_tracks: Vec<String>,
|
||||
}
|
||||
@@ -1422,6 +1423,7 @@ pub async fn library_backfill_downloads(
|
||||
let mut report = BackfillReport {
|
||||
total_downloads: 0,
|
||||
added_tracks: 0,
|
||||
repaired_tracks: 0,
|
||||
skipped_tracks: 0,
|
||||
failed_tracks: Vec::new(),
|
||||
};
|
||||
@@ -1429,7 +1431,7 @@ pub async fn library_backfill_downloads(
|
||||
// Get all ready downloads directly from download cache DB
|
||||
let downloads = {
|
||||
let cache_db = download_cache_state.db.lock().await;
|
||||
|
||||
|
||||
let mut stmt = cache_db
|
||||
.conn()
|
||||
.prepare("SELECT track_id, title, artist, album, album_id, duration_secs, file_path, quality, bit_depth, sample_rate FROM cached_tracks WHERE status = 'ready'")
|
||||
@@ -1453,7 +1455,7 @@ pub async fn library_backfill_downloads(
|
||||
rows.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(|e| format!("Failed to collect downloads: {}", e))?
|
||||
}; // cache_db lock is dropped here
|
||||
|
||||
|
||||
report.total_downloads = downloads.len();
|
||||
|
||||
let library_db = state.db.lock().await;
|
||||
@@ -1465,7 +1467,21 @@ pub async fn library_backfill_downloads(
|
||||
.unwrap_or(false);
|
||||
|
||||
if exists {
|
||||
report.skipped_tracks += 1;
|
||||
// Track exists - try to repair its source marker if it's missing
|
||||
match library_db.repair_qobuz_download_source(track_id) {
|
||||
Ok(true) => {
|
||||
log::info!("Repaired source marker for track {}: {}", track_id, title);
|
||||
report.repaired_tracks += 1;
|
||||
},
|
||||
Ok(false) => {
|
||||
// Already has correct source, nothing to do
|
||||
report.skipped_tracks += 1;
|
||||
},
|
||||
Err(e) => {
|
||||
log::warn!("Failed to repair track {}: {}", track_id, e);
|
||||
report.failed_tracks.push(title);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -2005,6 +2005,18 @@ impl LibraryDatabase {
|
||||
Ok(count > 0)
|
||||
}
|
||||
|
||||
/// Repair the source field for a track that has qobuz_track_id but lost its source marker
|
||||
/// Returns true if the track was found and updated
|
||||
pub fn repair_qobuz_download_source(&self, qobuz_track_id: u64) -> Result<bool, LibraryError> {
|
||||
let updated = self.conn.execute(
|
||||
"UPDATE local_tracks SET source = 'qobuz_download'
|
||||
WHERE qobuz_track_id = ?1 AND (source IS NULL OR source != 'qobuz_download')",
|
||||
params![qobuz_track_id as i64],
|
||||
)
|
||||
.map_err(|e| LibraryError::Database(format!("Failed to repair download source: {}", e)))?;
|
||||
Ok(updated > 0)
|
||||
}
|
||||
|
||||
/// Insert a Qobuz download into the library
|
||||
pub fn insert_qobuz_download_direct(
|
||||
&self,
|
||||
|
||||
Reference in new issue
Block a user