Connect release groups to musicbrainz id #157

Merged
wojtek merged 6 commits from 46---connect-release-groups-to-musicbrainz-id into main 2024-03-08 23:28:53 +01:00
7 changed files with 59 additions and 38 deletions
Showing only changes of commit 3753850945 - Show all commits

View File

@ -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));

View File

@ -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,

View File

@ -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![],
}
}

View File

@ -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()

View File

@ -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 {

View File

@ -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);

View File

@ -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 {