fixed metadata import
This commit is contained in:
+10
-2
@@ -24,6 +24,9 @@ pub struct TrackImport {
|
||||
pub featured_artists: Vec<String>,
|
||||
pub album_artists: Vec<String>,
|
||||
pub release_title: String,
|
||||
/// Release type ("album", "single", ...) when known from a richer
|
||||
/// source than file tags (e.g. federation metadata); None = "album".
|
||||
pub release_type: Option<String>,
|
||||
pub year: Option<i32>,
|
||||
pub track_number: Option<i32>,
|
||||
pub disc_number: Option<i32>,
|
||||
@@ -186,6 +189,7 @@ pub fn read_file(path: &Path) -> Result<TrackImport> {
|
||||
featured_artists: featured,
|
||||
album_artists,
|
||||
release_title: album.unwrap_or_else(|| "Unknown Album".to_string()),
|
||||
release_type: None,
|
||||
year,
|
||||
track_number,
|
||||
disc_number,
|
||||
@@ -243,8 +247,12 @@ pub fn upsert_track(library: &Library, import: &TrackImport) -> Result<(i64, boo
|
||||
}
|
||||
None => {
|
||||
tx.execute(
|
||||
"INSERT INTO releases (title, release_type, year) VALUES (?1, 'album', ?2)",
|
||||
params![import.release_title, import.year],
|
||||
"INSERT INTO releases (title, release_type, year) VALUES (?1, ?2, ?3)",
|
||||
params![
|
||||
import.release_title,
|
||||
import.release_type.as_deref().unwrap_or("album"),
|
||||
import.year,
|
||||
],
|
||||
)?;
|
||||
let id = tx.last_insert_rowid();
|
||||
for (position, name) in import.album_artists.iter().enumerate() {
|
||||
|
||||
+2
-3
@@ -130,7 +130,6 @@ pub struct ExportTrack {
|
||||
pub title: String,
|
||||
pub year: Option<i32>,
|
||||
pub duration_seconds: f64,
|
||||
pub file_path: String,
|
||||
pub artist_names: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -434,7 +433,7 @@ impl Library {
|
||||
track_artists.entry(id).or_default().push(name);
|
||||
}
|
||||
let mut statement = conn.prepare(
|
||||
"SELECT t.id, t.title, r.year, t.duration_seconds, t.file_path
|
||||
"SELECT t.id, t.title, r.year, t.duration_seconds
|
||||
FROM tracks t JOIN releases r ON r.id = t.release_id",
|
||||
)?;
|
||||
let tracks = statement
|
||||
@@ -444,7 +443,6 @@ impl Library {
|
||||
title: row.get(1)?,
|
||||
year: row.get(2)?,
|
||||
duration_seconds: row.get(3)?,
|
||||
file_path: row.get(4)?,
|
||||
artist_names: Vec::new(),
|
||||
})
|
||||
})?
|
||||
@@ -883,6 +881,7 @@ mod tests {
|
||||
|
||||
fn add_track(lib: &Library, title: &str, artist: &str, album: &str) -> i64 {
|
||||
let import = import::TrackImport {
|
||||
release_type: None,
|
||||
file_path: format!("/music/{artist}/{album}/{title}.mp3"),
|
||||
title: title.to_string(),
|
||||
artists: vec![artist.to_string()],
|
||||
|
||||
Reference in New Issue
Block a user