fix: complete database insertion for Qobuz downloads
Critical bug fix: - insert_qobuz_download_with_grouping() was missing required NOT NULL fields - Added file_size_bytes, last_modified, indexed_at to INSERT - Extract bit_depth and sample_rate from FLAC file properties - Proper type conversion for bit_depth (u8 -> u32) Root cause: - INSERT statement incomplete vs schema requirements - Silent failure in post_process_track() - Downloaded tracks organized correctly but never inserted to library DB - Local Library view empty despite toggle ON Now working: - Download completes successfully - FLAC tags and artwork embedded - Files organized as Artist/Album/Track.flac - Track inserted to local_tracks with source='qobuz_download' - Albums appear in Local Library when toggle ON cp
This commit is contained in:
1 parent
0b72c3fba9
commit
f1dcd96e14
2 files changed
+37
-5
No files matched your search
@@ -41,7 +41,22 @@ async fn post_process_track(
|
||||
// 4. Organize file into artist/album structure
|
||||
let new_path = organize_download(track_id, current_path, download_root, &metadata)?;
|
||||
|
||||
// 5. ALWAYS insert into local library DB (visibility controlled by toggle)
|
||||
// 5. Extract audio properties from FLAC file
|
||||
use lofty::AudioFile;
|
||||
let (bit_depth, sample_rate) = match lofty::read_from_path(&new_path) {
|
||||
Ok(tagged_file) => {
|
||||
let properties = tagged_file.properties();
|
||||
let bit_depth = properties.bit_depth().map(|bd| bd as u32);
|
||||
let sample_rate = properties.sample_rate().map(|sr| sr as f64);
|
||||
(bit_depth, sample_rate)
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Failed to read audio properties for track {}: {}", track_id, e);
|
||||
(None, None)
|
||||
}
|
||||
};
|
||||
|
||||
// 6. ALWAYS insert into local library DB (visibility controlled by toggle)
|
||||
let lib_guard = library_db.lock().await;
|
||||
|
||||
// Generate album_group_key: album|album_artist
|
||||
@@ -61,8 +76,8 @@ async fn post_process_track(
|
||||
&new_path,
|
||||
&album_group_key,
|
||||
&metadata.album,
|
||||
None, // bit_depth not in CompleteTrackMetadata
|
||||
None, // sample_rate not in CompleteTrackMetadata
|
||||
bit_depth,
|
||||
sample_rate,
|
||||
) {
|
||||
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),
|
||||
|
||||
@@ -1456,15 +1456,29 @@ impl LibraryDatabase {
|
||||
bit_depth: Option<u32>,
|
||||
sample_rate: Option<f64>,
|
||||
) -> Result<(), LibraryError> {
|
||||
use std::time::SystemTime;
|
||||
|
||||
// Get file size if file exists
|
||||
let file_size_bytes = std::fs::metadata(file_path)
|
||||
.map(|m| m.len() as i64)
|
||||
.unwrap_or(0);
|
||||
|
||||
// Get current timestamp
|
||||
let now = SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as i64;
|
||||
|
||||
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,
|
||||
file_size_bytes, last_modified, indexed_at,
|
||||
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)
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, 'qobuz_download', ?19)
|
||||
"#,
|
||||
params![
|
||||
file_path,
|
||||
@@ -1478,8 +1492,11 @@ impl LibraryDatabase {
|
||||
duration_secs as i64,
|
||||
"flac",
|
||||
bit_depth.map(|v| v as i64),
|
||||
sample_rate,
|
||||
sample_rate.unwrap_or(44100.0) as i64,
|
||||
2, // Assume stereo
|
||||
file_size_bytes,
|
||||
now,
|
||||
now,
|
||||
album_group_key,
|
||||
album_group_title,
|
||||
track_id as i64,
|
||||
|
||||
Reference in new issue
Block a user