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