fix(downloads): add cover art path to local library for Qobuz downloads
Downloaded albums now properly display cover art in local library by passing artwork_path when inserting tracks to database. Cover art is saved as cover.jpg in album directory during post-processing. cp
This commit is contained in:
1 parent
481b1d18d7
commit
2d82d74b7f
3 files changed
+36
-6
No files matched your search
@@ -42,14 +42,22 @@ async fn post_process_track(
|
||||
let new_path = organize_download(track_id, current_path, download_root, &metadata)?;
|
||||
|
||||
// 5. Download and save album cover art as cover.jpg
|
||||
if let Some(artwork_url) = &metadata.artwork_url {
|
||||
let artwork_path = if let Some(artwork_url) = &metadata.artwork_url {
|
||||
// Extract album directory from the new_path
|
||||
if let Some(parent_dir) = std::path::Path::new(&new_path).parent() {
|
||||
if let Err(e) = save_album_artwork(parent_dir, artwork_url).await {
|
||||
match save_album_artwork(parent_dir, artwork_url).await {
|
||||
Ok(_) => Some(parent_dir.join("cover.jpg").to_string_lossy().to_string()),
|
||||
Err(e) => {
|
||||
log::warn!("Failed to save album artwork for track {}: {}", track_id, e);
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// 6. Extract audio properties from FLAC file
|
||||
use lofty::AudioFile;
|
||||
@@ -88,6 +96,7 @@ async fn post_process_track(
|
||||
&metadata.album,
|
||||
bit_depth,
|
||||
sample_rate,
|
||||
artwork_path.as_deref(),
|
||||
) {
|
||||
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),
|
||||
|
||||
@@ -9,7 +9,7 @@ use tokio::sync::Mutex;
|
||||
|
||||
use crate::api::QobuzClient;
|
||||
use crate::library::database::LibraryDatabase;
|
||||
use super::metadata::{fetch_complete_metadata, write_flac_tags, embed_artwork, organize_download};
|
||||
use super::metadata::{fetch_complete_metadata, write_flac_tags, embed_artwork, organize_download, save_album_artwork};
|
||||
|
||||
#[derive(Default, Serialize, Clone, Debug)]
|
||||
pub struct MigrationStatus {
|
||||
@@ -95,7 +95,24 @@ async fn migrate_single_track(
|
||||
// 4. Organize file into artist/album structure
|
||||
let new_path = organize_download(track_id, &legacy_path_str, download_root, &metadata)?;
|
||||
|
||||
// 5. Extract audio properties from FLAC file
|
||||
// 5. Save album artwork as cover.jpg
|
||||
let artwork_path = if let Some(artwork_url) = &metadata.artwork_url {
|
||||
if let Some(parent_dir) = std::path::Path::new(&new_path).parent() {
|
||||
match save_album_artwork(parent_dir, artwork_url).await {
|
||||
Ok(_) => Some(parent_dir.join("cover.jpg").to_string_lossy().to_string()),
|
||||
Err(e) => {
|
||||
log::warn!("Failed to save album artwork for track {}: {}", track_id, e);
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// 6. Extract audio properties from FLAC file
|
||||
use lofty::AudioFile;
|
||||
let (bit_depth, sample_rate) = match lofty::read_from_path(&new_path) {
|
||||
Ok(tagged_file) => {
|
||||
@@ -110,7 +127,7 @@ async fn migrate_single_track(
|
||||
}
|
||||
};
|
||||
|
||||
// 6. Insert into local library DB
|
||||
// 7. Insert into local library DB
|
||||
let lib_guard = library_db.lock().await;
|
||||
|
||||
let album_artist = metadata.album_artist.as_ref().unwrap_or(&metadata.artist);
|
||||
@@ -131,6 +148,7 @@ async fn migrate_single_track(
|
||||
&metadata.album,
|
||||
bit_depth,
|
||||
sample_rate,
|
||||
artwork_path.as_deref(),
|
||||
)
|
||||
.map_err(|e| format!("Failed to insert to library DB: {}", e))?;
|
||||
|
||||
|
||||
@@ -1455,6 +1455,7 @@ impl LibraryDatabase {
|
||||
album_group_title: &str,
|
||||
bit_depth: Option<u32>,
|
||||
sample_rate: Option<f64>,
|
||||
artwork_path: Option<&str>,
|
||||
) -> Result<(), LibraryError> {
|
||||
use std::time::SystemTime;
|
||||
|
||||
@@ -1477,8 +1478,9 @@ impl LibraryDatabase {
|
||||
format, bit_depth, sample_rate, channels,
|
||||
file_size_bytes, last_modified, indexed_at,
|
||||
album_group_key, album_group_title,
|
||||
artwork_path,
|
||||
source, qobuz_track_id
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, 'qobuz_download', ?19)
|
||||
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, 'qobuz_download', ?20)
|
||||
"#,
|
||||
params![
|
||||
file_path,
|
||||
@@ -1499,6 +1501,7 @@ impl LibraryDatabase {
|
||||
now,
|
||||
album_group_key,
|
||||
album_group_title,
|
||||
artwork_path,
|
||||
track_id as i64,
|
||||
],
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user