Connect release groups to musicbrainz id #157
@ -1,5 +1,5 @@
|
||||
pub static DATABASE_JSON: &str = "{\
|
||||
\"V20240302\":\
|
||||
\"V20240308\":\
|
||||
[\
|
||||
{\
|
||||
\"name\":\"Album_Artist ‘A’\",\
|
||||
@ -10,8 +10,11 @@ pub static DATABASE_JSON: &str = "{\
|
||||
\"Qobuz\":[\"https://www.qobuz.com/nl-nl/interpreter/artist-a/download-streaming-albums\"]\
|
||||
},\
|
||||
\"albums\":[\
|
||||
{\"title\":\"album_title a.a\",\"seq\":1},\
|
||||
{\"title\":\"album_title a.b\",\"seq\":1}\
|
||||
{\
|
||||
\"title\":\"album_title a.a\",\"seq\":1,\
|
||||
\"musicbrainz\":\"https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000\"\
|
||||
},\
|
||||
{\"title\":\"album_title a.b\",\"seq\":1,\"musicbrainz\":null}\
|
||||
]\
|
||||
},\
|
||||
{\
|
||||
@ -27,10 +30,16 @@ pub static DATABASE_JSON: &str = "{\
|
||||
\"Qobuz\":[\"https://www.qobuz.com/nl-nl/interpreter/artist-b/download-streaming-albums\"]\
|
||||
},\
|
||||
\"albums\":[\
|
||||
{\"title\":\"album_title b.a\",\"seq\":1},\
|
||||
{\"title\":\"album_title b.b\",\"seq\":3},\
|
||||
{\"title\":\"album_title b.c\",\"seq\":2},\
|
||||
{\"title\":\"album_title b.d\",\"seq\":4}\
|
||||
{\"title\":\"album_title b.a\",\"seq\":1,\"musicbrainz\":null},\
|
||||
{\
|
||||
\"title\":\"album_title b.b\",\"seq\":3,\
|
||||
\"musicbrainz\":\"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111\"\
|
||||
},\
|
||||
{\
|
||||
\"title\":\"album_title b.c\",\"seq\":2,\
|
||||
\"musicbrainz\":\"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112\"\
|
||||
},\
|
||||
{\"title\":\"album_title b.d\",\"seq\":4,\"musicbrainz\":null}\
|
||||
]\
|
||||
},\
|
||||
{\
|
||||
@ -39,8 +48,8 @@ pub static DATABASE_JSON: &str = "{\
|
||||
\"musicbrainz\":\"https://musicbrainz.org/artist/11111111-1111-1111-1111-111111111111\",\
|
||||
\"properties\":{},\
|
||||
\"albums\":[\
|
||||
{\"title\":\"album_title c.a\",\"seq\":0},\
|
||||
{\"title\":\"album_title c.b\",\"seq\":0}\
|
||||
{\"title\":\"album_title c.a\",\"seq\":0,\"musicbrainz\":null},\
|
||||
{\"title\":\"album_title c.b\",\"seq\":0,\"musicbrainz\":null}\
|
||||
]\
|
||||
},\
|
||||
{\
|
||||
@ -49,8 +58,8 @@ pub static DATABASE_JSON: &str = "{\
|
||||
\"musicbrainz\":null,\
|
||||
\"properties\":{},\
|
||||
\"albums\":[\
|
||||
{\"title\":\"album_title d.a\",\"seq\":0},\
|
||||
{\"title\":\"album_title d.b\",\"seq\":0}\
|
||||
{\"title\":\"album_title d.a\",\"seq\":0,\"musicbrainz\":null},\
|
||||
{\"title\":\"album_title d.b\",\"seq\":0,\"musicbrainz\":null}\
|
||||
]\
|
||||
}\
|
||||
]\
|
||||
|
@ -13,7 +13,20 @@ use crate::core::{
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub enum DeserializeDatabase {
|
||||
V20240302(Vec<DeserializeArtist>),
|
||||
V20240308(Vec<DeserializeArtist>),
|
||||
}
|
||||
|
||||
impl TryFrom<DeserializeDatabase> for Collection {
|
||||
type Error = LoadError;
|
||||
|
||||
fn try_from(database: DeserializeDatabase) -> Result<Self, Self::Error> {
|
||||
match database {
|
||||
DeserializeDatabase::V20240308(collection) => collection
|
||||
.into_iter()
|
||||
.map(|artist| artist.try_into())
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@ -29,19 +42,7 @@ pub struct DeserializeArtist {
|
||||
pub struct DeserializeAlbum {
|
||||
title: String,
|
||||
seq: u8,
|
||||
}
|
||||
|
||||
impl TryFrom<DeserializeDatabase> for Collection {
|
||||
type Error = LoadError;
|
||||
|
||||
fn try_from(database: DeserializeDatabase) -> Result<Self, Self::Error> {
|
||||
match database {
|
||||
DeserializeDatabase::V20240302(collection) => collection
|
||||
.into_iter()
|
||||
.map(|artist| artist.try_into())
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
musicbrainz: Option<String>,
|
||||
}
|
||||
|
||||
impl TryFrom<DeserializeArtist> for Artist {
|
||||
@ -53,19 +54,25 @@ impl TryFrom<DeserializeArtist> for Artist {
|
||||
sort: artist.sort.map(ArtistId::new),
|
||||
musicbrainz: artist.musicbrainz.map(TryInto::try_into).transpose()?,
|
||||
properties: artist.properties,
|
||||
albums: artist.albums.into_iter().map(Into::into).collect(),
|
||||
albums: artist
|
||||
.albums
|
||||
.into_iter()
|
||||
.map(TryInto::try_into)
|
||||
.collect::<Result<Vec<Album>, LoadError>>()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DeserializeAlbum> for Album {
|
||||
fn from(album: DeserializeAlbum) -> Self {
|
||||
Album {
|
||||
impl TryFrom<DeserializeAlbum> for Album {
|
||||
type Error = LoadError;
|
||||
|
||||
fn try_from(album: DeserializeAlbum) -> Result<Self, Self::Error> {
|
||||
Ok(Album {
|
||||
id: AlbumId { title: album.title },
|
||||
date: AlbumDate::default(),
|
||||
seq: AlbumSeq(album.seq),
|
||||
musicbrainz: None,
|
||||
musicbrainz: album.musicbrainz.map(TryInto::try_into).transpose()?,
|
||||
tracks: vec![],
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,13 @@ use crate::core::collection::{album::Album, artist::Artist, Collection};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum SerializeDatabase<'a> {
|
||||
V20240302(Vec<SerializeArtist<'a>>),
|
||||
V20240308(Vec<SerializeArtist<'a>>),
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Collection> for SerializeDatabase<'a> {
|
||||
fn from(collection: &'a Collection) -> Self {
|
||||
SerializeDatabase::V20240308(collection.iter().map(Into::into).collect())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
@ -22,12 +28,7 @@ pub struct SerializeArtist<'a> {
|
||||
pub struct SerializeAlbum<'a> {
|
||||
title: &'a str,
|
||||
seq: u8,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Collection> for SerializeDatabase<'a> {
|
||||
fn from(collection: &'a Collection) -> Self {
|
||||
SerializeDatabase::V20240302(collection.iter().map(Into::into).collect())
|
||||
}
|
||||
musicbrainz: Option<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Artist> for SerializeArtist<'a> {
|
||||
@ -35,7 +36,7 @@ impl<'a> From<&'a Artist> for SerializeArtist<'a> {
|
||||
SerializeArtist {
|
||||
name: &artist.id.name,
|
||||
sort: artist.sort.as_ref().map(|id| id.name.as_ref()),
|
||||
musicbrainz: artist.musicbrainz.as_ref().map(|mb| mb.as_ref()),
|
||||
musicbrainz: artist.musicbrainz.as_ref().map(AsRef::as_ref),
|
||||
properties: artist
|
||||
.properties
|
||||
.iter()
|
||||
@ -51,6 +52,7 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> {
|
||||
SerializeAlbum {
|
||||
title: &album.id.title,
|
||||
seq: album.seq.0,
|
||||
musicbrainz: album.musicbrainz.as_ref().map(AsRef::as_ref),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
src/tests.rs
12
src/tests.rs
@ -482,6 +482,10 @@ macro_rules! full_collection {
|
||||
artist_a.albums[0].seq = AlbumSeq(1);
|
||||
artist_a.albums[1].seq = AlbumSeq(1);
|
||||
|
||||
artist_a.albums[0].musicbrainz = Some(MusicBrainz::from_str(
|
||||
"https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000"
|
||||
).unwrap());
|
||||
|
||||
let artist_b = iter.next().unwrap();
|
||||
assert_eq!(artist_b.id.name, "Album_Artist ‘B’");
|
||||
|
||||
@ -507,6 +511,14 @@ macro_rules! full_collection {
|
||||
artist_b.albums[2].seq = AlbumSeq(2);
|
||||
artist_b.albums[3].seq = AlbumSeq(4);
|
||||
|
||||
artist_b.albums[1].musicbrainz = Some(MusicBrainz::from_str(
|
||||
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111"
|
||||
).unwrap());
|
||||
|
||||
artist_b.albums[2].musicbrainz = Some(MusicBrainz::from_str(
|
||||
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112"
|
||||
).unwrap());
|
||||
|
||||
let artist_c = iter.next().unwrap();
|
||||
assert_eq!(artist_c.id.name, "The Album_Artist ‘C’");
|
||||
|
||||
|
@ -1 +1 @@
|
||||
{"V20240302":[{"name":"Аркона","sort":"Arkona","musicbrainz":"https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212","properties":{"Bandcamp":["https://arkonamoscow.bandcamp.com/"],"MusicButler":["https://www.musicbutler.io/artist-page/283448581"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums"]},"albums":[{"title":"Slovo","seq":0}]},{"name":"Eluveitie","sort":null,"musicbrainz":"https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38","properties":{"MusicButler":["https://www.musicbutler.io/artist-page/269358403"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/eluveitie/download-streaming-albums"]},"albums":[{"title":"Vên [re‐recorded]","seq":0},{"title":"Slania","seq":0}]},{"name":"Frontside","sort":null,"musicbrainz":"https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490","properties":{"MusicButler":["https://www.musicbutler.io/artist-page/826588800"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/frontside/download-streaming-albums"]},"albums":[{"title":"…nasze jest królestwo, potęga i chwała na wieki…","seq":0}]},{"name":"Heaven’s Basement","sort":"Heaven’s Basement","musicbrainz":"https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc","properties":{"MusicButler":["https://www.musicbutler.io/artist-page/291158685"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/heaven-s-basement/download-streaming-albums"]},"albums":[{"title":"Paper Plague","seq":0},{"title":"Unbreakable","seq":0}]},{"name":"Metallica","sort":null,"musicbrainz":"https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab","properties":{"MusicButler":["https://www.musicbutler.io/artist-page/3996865"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/metallica/download-streaming-albums"]},"albums":[{"title":"Ride the Lightning","seq":0},{"title":"S&M","seq":0}]}]}
|
||||
{"V20240308":[{"name":"Аркона","sort":"Arkona","musicbrainz":"https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212","properties":{"Bandcamp":["https://arkonamoscow.bandcamp.com/"],"MusicButler":["https://www.musicbutler.io/artist-page/283448581"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums"]},"albums":[{"title":"Slovo","seq":0,"musicbrainz":null}]},{"name":"Eluveitie","sort":null,"musicbrainz":"https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38","properties":{"MusicButler":["https://www.musicbutler.io/artist-page/269358403"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/eluveitie/download-streaming-albums"]},"albums":[{"title":"Vên [re‐recorded]","seq":0,"musicbrainz":null},{"title":"Slania","seq":0,"musicbrainz":null}]},{"name":"Frontside","sort":null,"musicbrainz":"https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490","properties":{"MusicButler":["https://www.musicbutler.io/artist-page/826588800"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/frontside/download-streaming-albums"]},"albums":[{"title":"…nasze jest królestwo, potęga i chwała na wieki…","seq":0,"musicbrainz":null}]},{"name":"Heaven’s Basement","sort":"Heaven’s Basement","musicbrainz":"https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc","properties":{"MusicButler":["https://www.musicbutler.io/artist-page/291158685"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/heaven-s-basement/download-streaming-albums"]},"albums":[{"title":"Paper Plague","seq":0,"musicbrainz":null},{"title":"Unbreakable","seq":0,"musicbrainz":null}]},{"name":"Metallica","sort":null,"musicbrainz":"https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab","properties":{"MusicButler":["https://www.musicbutler.io/artist-page/3996865"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/metallica/download-streaming-albums"]},"albums":[{"title":"Ride the Lightning","seq":0,"musicbrainz":null},{"title":"S&M","seq":0,"musicbrainz":null}]}]}
|
Loading…
Reference in New Issue
Block a user