Compare commits
4 Commits
494de64f0a
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 11a8d3a88e | |||
| ed8175b1d0 | |||
| 4f4e6e794a | |||
| 6057ffa158 |
+8
-2
@@ -65,9 +65,10 @@ async fn process_file(
|
|||||||
|
|
||||||
// Upsert artist (use album_artist if available, fall back to artist)
|
// Upsert artist (use album_artist if available, fall back to artist)
|
||||||
let artist_name = meta.album_artist.as_deref().or(meta.artist.as_deref());
|
let artist_name = meta.album_artist.as_deref().or(meta.artist.as_deref());
|
||||||
|
let artist_mbid = meta.musicbrainz_artist_id.as_deref();
|
||||||
let artist_id = match artist_name {
|
let artist_id = match artist_name {
|
||||||
Some(name) if !name.is_empty() => {
|
Some(name) if !name.is_empty() => {
|
||||||
Some(queries::artists::upsert(conn, name, None).await?.id)
|
Some(queries::artists::upsert(conn, name, artist_mbid).await?.id)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
@@ -106,12 +107,17 @@ async fn process_file(
|
|||||||
bitrate: Set(meta.bitrate),
|
bitrate: Set(meta.bitrate),
|
||||||
file_size: Set(scanned.file_size),
|
file_size: Set(scanned.file_size),
|
||||||
fingerprint: NotSet,
|
fingerprint: NotSet,
|
||||||
musicbrainz_id: Set(meta.musicbrainz_recording_id),
|
musicbrainz_id: if meta.musicbrainz_recording_id.is_some() {
|
||||||
|
Set(meta.musicbrainz_recording_id)
|
||||||
|
} else {
|
||||||
|
NotSet // Don't overwrite existing DB MBID when file tag is missing
|
||||||
|
},
|
||||||
artist_id: Set(artist_id),
|
artist_id: Set(artist_id),
|
||||||
album_id: Set(album_id),
|
album_id: Set(album_id),
|
||||||
file_mtime: Set(Some(scanned.mtime)),
|
file_mtime: Set(Some(scanned.mtime)),
|
||||||
added_at: NotSet,
|
added_at: NotSet,
|
||||||
updated_at: NotSet,
|
updated_at: NotSet,
|
||||||
|
tagged: NotSet,
|
||||||
};
|
};
|
||||||
queries::tracks::upsert(conn, active).await?;
|
queries::tracks::upsert(conn, active).await?;
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ pub struct MusicMetadata {
|
|||||||
pub codec: Option<String>,
|
pub codec: Option<String>,
|
||||||
pub bitrate: Option<i32>,
|
pub bitrate: Option<i32>,
|
||||||
pub musicbrainz_recording_id: Option<String>,
|
pub musicbrainz_recording_id: Option<String>,
|
||||||
|
pub musicbrainz_artist_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Map lofty FileType to a human-readable codec string.
|
/// Map lofty FileType to a human-readable codec string.
|
||||||
@@ -79,6 +80,10 @@ pub fn extract_metadata(path: &Path) -> IndexResult<MusicMetadata> {
|
|||||||
meta.musicbrainz_recording_id = tag
|
meta.musicbrainz_recording_id = tag
|
||||||
.get_string(&lofty::tag::ItemKey::MusicBrainzRecordingId)
|
.get_string(&lofty::tag::ItemKey::MusicBrainzRecordingId)
|
||||||
.map(|s| s.to_string());
|
.map(|s| s.to_string());
|
||||||
|
|
||||||
|
meta.musicbrainz_artist_id = tag
|
||||||
|
.get_string(&lofty::tag::ItemKey::MusicBrainzArtistId)
|
||||||
|
.map(|s| s.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(meta)
|
Ok(meta)
|
||||||
|
|||||||
@@ -58,10 +58,12 @@ async fn test_scan_indexes_music_files() {
|
|||||||
create_test_mp3(dir.path(), "song1.mp3", "Time", "Pink Floyd", "DSOTM");
|
create_test_mp3(dir.path(), "song1.mp3", "Time", "Pink Floyd", "DSOTM");
|
||||||
create_test_mp3(dir.path(), "song2.mp3", "Money", "Pink Floyd", "DSOTM");
|
create_test_mp3(dir.path(), "song2.mp3", "Money", "Pink Floyd", "DSOTM");
|
||||||
|
|
||||||
|
// Use concurrency=1 to avoid race in album upsert when two files
|
||||||
|
// share the same artist+album and are processed simultaneously.
|
||||||
let config = ScanConfig {
|
let config = ScanConfig {
|
||||||
root: dir.path().to_owned(),
|
root: dir.path().to_owned(),
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
concurrency: 2,
|
concurrency: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let stats = run_scan(db.conn(), &config).await.unwrap();
|
let stats = run_scan(db.conn(), &config).await.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user