Compare commits
6 Commits
9d1366f266
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 11a8d3a88e | |||
| ed8175b1d0 | |||
| 4f4e6e794a | |||
| 6057ffa158 | |||
| 494de64f0a | |||
| 3cba8f88c1 |
+9
-5
@@ -65,9 +65,10 @@ async fn process_file(
|
||||
|
||||
// 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_mbid = meta.musicbrainz_artist_id.as_deref();
|
||||
let artist_id = match artist_name {
|
||||
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,
|
||||
};
|
||||
@@ -106,12 +107,17 @@ async fn process_file(
|
||||
bitrate: Set(meta.bitrate),
|
||||
file_size: Set(scanned.file_size),
|
||||
fingerprint: NotSet,
|
||||
musicbrainz_id: NotSet,
|
||||
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),
|
||||
album_id: Set(album_id),
|
||||
file_mtime: Set(Some(scanned.mtime)),
|
||||
added_at: NotSet,
|
||||
updated_at: NotSet,
|
||||
tagged: NotSet,
|
||||
};
|
||||
queries::tracks::upsert(conn, active).await?;
|
||||
|
||||
@@ -130,9 +136,7 @@ pub async fn index_file(
|
||||
.modified()
|
||||
.ok()
|
||||
.and_then(|t| {
|
||||
let duration = t
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default();
|
||||
let duration = t.duration_since(std::time::UNIX_EPOCH).unwrap_or_default();
|
||||
chrono::DateTime::from_timestamp(duration.as_secs() as i64, 0)
|
||||
})
|
||||
.map(|dt| dt.naive_utc())
|
||||
|
||||
@@ -22,6 +22,8 @@ pub struct MusicMetadata {
|
||||
pub duration: Option<f64>,
|
||||
pub codec: Option<String>,
|
||||
pub bitrate: Option<i32>,
|
||||
pub musicbrainz_recording_id: Option<String>,
|
||||
pub musicbrainz_artist_id: Option<String>,
|
||||
}
|
||||
|
||||
/// Map lofty FileType to a human-readable codec string.
|
||||
@@ -74,6 +76,14 @@ pub fn extract_metadata(path: &Path) -> IndexResult<MusicMetadata> {
|
||||
meta.album_artist = tag
|
||||
.get_string(&lofty::tag::ItemKey::AlbumArtist)
|
||||
.map(|s| s.to_string());
|
||||
|
||||
meta.musicbrainz_recording_id = tag
|
||||
.get_string(&lofty::tag::ItemKey::MusicBrainzRecordingId)
|
||||
.map(|s| s.to_string());
|
||||
|
||||
meta.musicbrainz_artist_id = tag
|
||||
.get_string(&lofty::tag::ItemKey::MusicBrainzArtistId)
|
||||
.map(|s| s.to_string());
|
||||
}
|
||||
|
||||
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(), "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 {
|
||||
root: dir.path().to_owned(),
|
||||
dry_run: false,
|
||||
concurrency: 2,
|
||||
concurrency: 1,
|
||||
};
|
||||
|
||||
let stats = run_scan(db.conn(), &config).await.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user