Add musicbrainz field to album
This commit is contained in:
parent
965a1d7cbf
commit
3753850945
@ -5,6 +5,7 @@ use std::{
|
||||
|
||||
use crate::core::collection::{
|
||||
merge::{Merge, MergeSorted, WithId},
|
||||
musicbrainz::MusicBrainz,
|
||||
track::{Track, TrackFormat},
|
||||
};
|
||||
|
||||
@ -14,6 +15,7 @@ pub struct Album {
|
||||
pub id: AlbumId,
|
||||
pub date: AlbumDate,
|
||||
pub seq: AlbumSeq,
|
||||
pub musicbrainz: Option<MusicBrainz>,
|
||||
pub tracks: Vec<Track>,
|
||||
}
|
||||
|
||||
@ -50,6 +52,16 @@ impl AlbumDate {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for AlbumDate {
|
||||
fn from(year: u32) -> Self {
|
||||
AlbumDate {
|
||||
year,
|
||||
month: AlbumMonth::default(),
|
||||
day: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Ord, Eq, Hash)]
|
||||
pub enum AlbumMonth {
|
||||
@ -115,6 +127,16 @@ impl AlbumStatus {
|
||||
}
|
||||
|
||||
impl Album {
|
||||
pub fn new<Id: Into<AlbumId>, Date: Into<AlbumDate>>(id: Id, date: Date) -> Self {
|
||||
Album {
|
||||
id: id.into(),
|
||||
date: date.into(),
|
||||
seq: AlbumSeq::default(),
|
||||
musicbrainz: None,
|
||||
tracks: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &AlbumId) {
|
||||
(&self.date, &self.seq, &self.id)
|
||||
}
|
||||
@ -209,22 +231,14 @@ mod tests {
|
||||
let album_id_1 = AlbumId {
|
||||
title: String::from("album z"),
|
||||
};
|
||||
let album_1 = Album {
|
||||
id: album_id_1,
|
||||
date: date.clone(),
|
||||
seq: AlbumSeq(1),
|
||||
tracks: vec![],
|
||||
};
|
||||
let mut album_1 = Album::new(album_id_1, date.clone());
|
||||
album_1.set_seq(AlbumSeq(1));
|
||||
|
||||
let album_id_2 = AlbumId {
|
||||
title: String::from("album a"),
|
||||
};
|
||||
let album_2 = Album {
|
||||
id: album_id_2,
|
||||
date: date.clone(),
|
||||
seq: AlbumSeq(2),
|
||||
tracks: vec![],
|
||||
};
|
||||
let mut album_2 = Album::new(album_id_2, date.clone());
|
||||
album_2.set_seq(AlbumSeq(2));
|
||||
|
||||
assert_ne!(album_1, album_2);
|
||||
assert!(album_1 < album_2);
|
||||
@ -232,12 +246,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn set_clear_seq() {
|
||||
let mut album = Album {
|
||||
id: "an album".into(),
|
||||
date: AlbumDate::default(),
|
||||
seq: AlbumSeq::default(),
|
||||
tracks: vec![],
|
||||
};
|
||||
let mut album = Album::new("An album", AlbumDate::default());
|
||||
|
||||
assert_eq!(album.seq, AlbumSeq(0));
|
||||
|
||||
|
@ -36,7 +36,7 @@ pub struct ArtistId {
|
||||
|
||||
impl Artist {
|
||||
/// Create new [`Artist`] with the given [`ArtistId`].
|
||||
pub fn new<ID: Into<ArtistId>>(id: ID) -> Self {
|
||||
pub fn new<Id: Into<ArtistId>>(id: Id) -> Self {
|
||||
Artist {
|
||||
id: id.into(),
|
||||
sort: None,
|
||||
|
@ -64,6 +64,7 @@ impl From<DeserializeAlbum> for Album {
|
||||
id: AlbumId { title: album.title },
|
||||
date: AlbumDate::default(),
|
||||
seq: AlbumSeq(album.seq),
|
||||
musicbrainz: None,
|
||||
tracks: vec![],
|
||||
}
|
||||
}
|
||||
|
@ -141,12 +141,11 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
|
||||
.find(|album| album.id == album_id)
|
||||
{
|
||||
Some(album) => album.tracks.push(track),
|
||||
None => artist.albums.push(Album {
|
||||
id: album_id,
|
||||
date: album_date,
|
||||
seq: AlbumSeq(0),
|
||||
tracks: vec![track],
|
||||
}),
|
||||
None => {
|
||||
let mut album = Album::new(album_id, album_date);
|
||||
album.tracks.push(track);
|
||||
artist.albums.push(album);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -748,12 +747,9 @@ mod tests {
|
||||
let album_id_2 = AlbumId::new("another album");
|
||||
|
||||
let mut database_result = vec![Artist::new(artist_id.clone())];
|
||||
database_result[0].albums.push(Album {
|
||||
id: album_id.clone(),
|
||||
date: AlbumDate::default(),
|
||||
seq: AlbumSeq::default(),
|
||||
tracks: vec![],
|
||||
});
|
||||
database_result[0]
|
||||
.albums
|
||||
.push(Album::new(album_id.clone(), AlbumDate::default()));
|
||||
|
||||
database
|
||||
.expect_load()
|
||||
|
10
src/tests.rs
10
src/tests.rs
@ -19,6 +19,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -79,6 +80,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -124,6 +126,7 @@ macro_rules! library_collection {
|
||||
day: 6,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -162,6 +165,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -200,6 +204,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -238,6 +243,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -288,6 +294,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -326,6 +333,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -374,6 +382,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -412,6 +421,7 @@ macro_rules! library_collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
|
@ -744,7 +744,7 @@ impl IUi for Ui {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use musichoard::collection::{album::AlbumId, artist::ArtistId};
|
||||
use musichoard::collection::artist::ArtistId;
|
||||
|
||||
use crate::tui::{
|
||||
app::{AppPublic, AppPublicInner, Delta},
|
||||
@ -868,12 +868,9 @@ mod tests {
|
||||
#[test]
|
||||
fn empty_album() {
|
||||
let mut artists: Vec<Artist> = vec![Artist::new(ArtistId::new("An artist"))];
|
||||
artists[0].albums.push(Album {
|
||||
id: AlbumId::new("An album"),
|
||||
date: AlbumDate::default(),
|
||||
seq: AlbumSeq::default(),
|
||||
tracks: vec![],
|
||||
});
|
||||
artists[0]
|
||||
.albums
|
||||
.push(Album::new("An album", AlbumDate::default()));
|
||||
let mut selection = Selection::new(&artists);
|
||||
|
||||
draw_test_suite(&artists, &mut selection);
|
||||
|
@ -42,6 +42,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -227,6 +228,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -306,6 +308,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -469,6 +472,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -622,6 +626,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -645,6 +650,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -753,6 +759,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
@ -854,6 +861,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
day: 0,
|
||||
},
|
||||
seq: AlbumSeq(0),
|
||||
musicbrainz: None,
|
||||
tracks: vec![
|
||||
Track {
|
||||
id: TrackId {
|
||||
|
Loading…
Reference in New Issue
Block a user