From b61c0e0b62ae2358260553bd18a3ee15813c1ade Mon Sep 17 00:00:00 2001 From: Polochon-street Date: Tue, 12 Apr 2022 22:06:49 +0200 Subject: [PATCH] Add album_artist and duration to song. --- CHANGELOG.md | 3 ++- data/s16_mono_22_5kHz.flac | Bin 221444 -> 221444 bytes data/s32_stereo_44_1_kHz.mp3 | Bin 177981 -> 177981 bytes src/song.rs | 25 +++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 143d1a1..f24bdf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ #Changelog ## bliss 0.5.0 +* Add `album_artist` and `duration` to `Song`. * Fix a bug in `estimate_tuning` that led to empty chroma errors. * Remove the unusued Library trait, and extract a few useful functions from - there (`analyze_paths`, `closest_to_album_group`. + there (`analyze_paths`, `closest_to_album_group`). * Rename `distance` module to `playlist`. * Remove all traces of the "analyse" word vs "analyze" to make the codebase more coherent. diff --git a/data/s16_mono_22_5kHz.flac b/data/s16_mono_22_5kHz.flac index 7cc9bf4d0f26cbf7b389bb9d1d2323771ba5a7f3..7bea0ddf51480ec39f57c22f70b6226a93b54b96 100644 GIT binary patch delta 190 zcmZoU#M^R+cY<#HEM5i%2A{;TG*b&bV+%b)0|PdofFKZuc!v16+6JZOC1w^EC*~!m z3IGKigF-xmLu_3V%Q90GLVP1sKw>^lp}y!63c3o8IZ36t3XVl3nZ+d_1HtN$4di2B zP+$lNa&-3g3-xt!4YD;b;smO5cl8T$wGGHGXk?K8xbfge`R2U}?Rym%ftYFgUIk`% F2LLoUHdX)t delta 177 zcmZoU#M^R+cYzsUX1+&k!G1WI;}#pu4MIkgIJ#et`f;TTqB+aEPr-Vp(R2 xLWpmKC{QdlFF8LYwa8Wg#p*@|g^d^A$WMGA+PqhxeXjx|5HoGxtHA8;000bAF}VN$ diff --git a/data/s32_stereo_44_1_kHz.mp3 b/data/s32_stereo_44_1_kHz.mp3 index f4a0eb72afb33258987259810e3c91a62ee87036..def78cb7c4999756397e122202a2d56d1ecc1481 100644 GIT binary patch delta 132 zcmdn{j%)8bt~5^7sv}r%}dNIE>6r#PGt!3 z3^Bqc?CkFc6lMjg4#+QH2nldC1ai57T$jYM%oK$X-w1|~;9ysvAU{yhC$TKe)I!h1 eR8P>*zyK%+1OI;qOq{6DxS@3e, /// Song's album name, read from the metadata pub album: Option, + /// Song's album's artist name, read from the metadata + pub album_artist: Option, /// Song's tracked number, read from the metadata pub track_number: Option, /// Song's genre, read from the metadata (`""` if empty) pub genre: Option, /// bliss analysis results pub analysis: Analysis, + /// The song's duration + pub duration: Duration, /// Version of the features the song was analyzed with. /// A simple integer that is bumped every time a breaking change /// is introduced in the features. @@ -290,10 +295,12 @@ impl Song { Ok(Song { path: raw_song.path, artist: raw_song.artist, + album_artist: raw_song.album_artist, title: raw_song.title, album: raw_song.album, track_number: raw_song.track_number, genre: raw_song.genre, + duration: raw_song.duration, analysis: Song::analyze(raw_song.sample_array)?, features_version: FEATURES_VERSION, }) @@ -477,6 +484,13 @@ impl Song { t => Some(t.to_string()), }; }; + if let Some(album_artist) = format.metadata().get("album_artist") { + song.album_artist = match album_artist { + "" => None, + t => Some(t.to_string()), + }; + }; + let in_channel_layout = { if codec.channel_layout() == ChannelLayout::empty() { ChannelLayout::default(codec.channels().into()) @@ -569,6 +583,8 @@ impl Song { drop(tx); song.sample_array = child.join().unwrap()?; + let duration_seconds = song.sample_array.len() as f32 / SAMPLE_RATE as f32; + song.duration = Duration::from_nanos((duration_seconds * 1e9_f32).round() as u64); Ok(song) } } @@ -577,10 +593,12 @@ impl Song { pub(crate) struct InternalSong { pub path: PathBuf, pub artist: Option, + pub album_artist: Option, pub title: Option, pub album: Option, pub track_number: Option, pub genre: Option, + pub duration: Duration, pub sample_array: Vec, } @@ -723,10 +741,17 @@ mod tests { fn test_tags() { let song = Song::decode(Path::new("data/s16_mono_22_5kHz.flac")).unwrap(); assert_eq!(song.artist, Some(String::from("David TMX"))); + assert_eq!( + song.album_artist, + Some(String::from("David TMX - Album Artist")) + ); assert_eq!(song.title, Some(String::from("Renaissance"))); assert_eq!(song.album, Some(String::from("Renaissance"))); assert_eq!(song.track_number, Some(String::from("02"))); assert_eq!(song.genre, Some(String::from("Pop"))); + // Test that there is less than 10ms of difference between what + // the song advertises and what we compute. + assert!((song.duration.as_millis() as f32 - 11070.).abs() < 10.); } #[test]