fix(downloads): add album grouping keys for proper library display

Critical fix for downloads not appearing in library:

Problem: Downloads inserted without album_group_key/album_group_title
Result: Albums not grouped/displayed in Local Library UI

Solution:
1. Create insert_qobuz_download_with_grouping() method
2. Pass all metadata: album_artist, track_number, year, etc.
3. Generate album_group_key: 'album|album_artist'
4. Set album_group_title for proper display

Now downloads will:
- Group correctly by album in Local Library
- Show proper album artist (not track artist)
- Display track numbers and year
- Appear in UI when toggle is ON

cp
This commit is contained in:
vicrodh committed 2026-01-14 22:51:03 -06:00
1 parent 01be29133a
commit 0b72c3fba9
2 files changed
+64 -2

No files matched your search

+13 -2
View File
@@ -43,17 +43,28 @@ async fn post_process_track(
// 5. ALWAYS insert into local library DB (visibility controlled by toggle) // 5. ALWAYS insert into local library DB (visibility controlled by toggle)
let lib_guard = library_db.lock().await; let lib_guard = library_db.lock().await;
match lib_guard.insert_qobuz_download_direct(
// Generate album_group_key: album|album_artist
let album_artist = metadata.album_artist.as_ref().unwrap_or(&metadata.artist);
let album_group_key = format!("{}|{}", metadata.album, album_artist);
match lib_guard.insert_qobuz_download_with_grouping(
track_id, track_id,
&metadata.title, &metadata.title,
&metadata.artist, &metadata.artist,
Some(&metadata.album), Some(&metadata.album),
metadata.album_artist.as_deref(),
metadata.track_number,
metadata.disc_number,
metadata.year,
metadata.duration_secs, metadata.duration_secs,
&new_path, &new_path,
&album_group_key,
&metadata.album,
None, // bit_depth not in CompleteTrackMetadata None, // bit_depth not in CompleteTrackMetadata
None, // sample_rate not in CompleteTrackMetadata None, // sample_rate not in CompleteTrackMetadata
) { ) {
Ok(_) => log::info!("Track {} inserted to local library DB", track_id), Ok(_) => log::info!("Track {} inserted to local library DB with group key: {}", track_id, album_group_key),
Err(e) => log::error!("Failed to insert track {} to library DB: {}", track_id, e), Err(e) => log::error!("Failed to insert track {} to library DB: {}", track_id, e),
} }
+51
View File
@@ -1438,6 +1438,57 @@ impl LibraryDatabase {
Ok(()) Ok(())
} }
/// Insert a Qobuz download with full metadata and album grouping
pub fn insert_qobuz_download_with_grouping(
&self,
track_id: u64,
title: &str,
artist: &str,
album: Option<&str>,
album_artist: Option<&str>,
track_number: Option<u32>,
disc_number: Option<u32>,
year: Option<u32>,
duration_secs: u64,
file_path: &str,
album_group_key: &str,
album_group_title: &str,
bit_depth: Option<u32>,
sample_rate: Option<f64>,
) -> Result<(), LibraryError> {
self.conn.execute(
r#"
INSERT INTO local_tracks (
file_path, title, artist, album, album_artist,
track_number, disc_number, year, duration_secs,
format, bit_depth, sample_rate, channels,
album_group_key, album_group_title,
source, qobuz_track_id
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, 'qobuz_download', ?16)
"#,
params![
file_path,
title,
artist,
album.unwrap_or("Unknown Album"),
album_artist.unwrap_or(artist),
track_number.map(|v| v as i64),
disc_number.map(|v| v as i64),
year.map(|v| v as i64),
duration_secs as i64,
"flac",
bit_depth.map(|v| v as i64),
sample_rate,
2, // Assume stereo
album_group_key,
album_group_title,
track_id as i64,
],
)
.map_err(|e| LibraryError::Database(format!("Failed to insert Qobuz download: {}", e)))?;
Ok(())
}
/// Remove a Qobuz download from the library by track_id /// Remove a Qobuz download from the library by track_id
pub fn remove_qobuz_download(&self, qobuz_track_id: u64) -> Result<(), LibraryError> { pub fn remove_qobuz_download(&self, qobuz_track_id: u64) -> Result<(), LibraryError> {
self.conn.execute( self.conn.execute(