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:
vicrodh committed 2026-01-20 00:49:57 -06:00
1 parent 6073cb96c1
commit ac77a31b06
2 files changed
+28

No files matched your search

+16
View File
@@ -1408,6 +1408,7 @@ pub async fn library_get_hidden_albums(
pub struct BackfillReport { pub struct BackfillReport {
pub total_downloads: usize, pub total_downloads: usize,
pub added_tracks: usize, pub added_tracks: usize,
pub repaired_tracks: usize,
pub skipped_tracks: usize, pub skipped_tracks: usize,
pub failed_tracks: Vec<String>, pub failed_tracks: Vec<String>,
} }
@@ -1422,6 +1423,7 @@ pub async fn library_backfill_downloads(
let mut report = BackfillReport { let mut report = BackfillReport {
total_downloads: 0, total_downloads: 0,
added_tracks: 0, added_tracks: 0,
repaired_tracks: 0,
skipped_tracks: 0, skipped_tracks: 0,
failed_tracks: Vec::new(), failed_tracks: Vec::new(),
}; };
@@ -1465,7 +1467,21 @@ pub async fn library_backfill_downloads(
.unwrap_or(false); .unwrap_or(false);
if exists { if exists {
// 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; report.skipped_tracks += 1;
},
Err(e) => {
log::warn!("Failed to repair track {}: {}", track_id, e);
report.failed_tracks.push(title);
}
}
continue; continue;
} }
+12
View File
@@ -2005,6 +2005,18 @@ impl LibraryDatabase {
Ok(count > 0) 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 /// Insert a Qobuz download into the library
pub fn insert_qobuz_download_direct( pub fn insert_qobuz_download_direct(
&self, &self,