diff --git a/src/core/collection/album.rs b/src/core/collection/album.rs index a0088cd..ffcdfb8 100644 --- a/src/core/collection/album.rs +++ b/src/core/collection/album.rs @@ -294,6 +294,7 @@ impl Merge for AlbumMeta { impl Merge for AlbumInfo { fn merge_in_place(&mut self, other: Self) { + self.status = self.status.take().or(other.status); self.primary_type = self.primary_type.take().or(other.primary_type); if self.secondary_types.is_empty() { self.secondary_types = other.secondary_types; diff --git a/src/external/database/json/testmod.rs b/src/external/database/json/testmod.rs index 04fd2b1..ccd7fce 100644 --- a/src/external/database/json/testmod.rs +++ b/src/external/database/json/testmod.rs @@ -14,13 +14,13 @@ pub static DATABASE_JSON: &str = "{\ \"title\":\"album_title a.a\",\"lib_id\":{\"Value\":1},\ \"date\":{\"year\":1998,\"month\":null,\"day\":null},\"seq\":1,\ \"musicbrainz\":{\"Some\":\"00000000-0000-0000-0000-000000000000\"},\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ },\ {\ \"title\":\"album_title a.b\",\"lib_id\":{\"Value\":2},\ \"date\":{\"year\":2015,\"month\":4,\"day\":null},\"seq\":1,\ \"musicbrainz\":\"None\",\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ }\ ]\ },\ @@ -41,25 +41,25 @@ pub static DATABASE_JSON: &str = "{\ \"title\":\"album_title b.a\",\"lib_id\":{\"Value\":3},\ \"date\":{\"year\":2003,\"month\":6,\"day\":6},\"seq\":1,\ \"musicbrainz\":\"None\",\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ },\ {\ \"title\":\"album_title b.b\",\"lib_id\":{\"Value\":4},\ \"date\":{\"year\":2008,\"month\":null,\"day\":null},\"seq\":3,\ \"musicbrainz\":{\"Some\":\"11111111-1111-1111-1111-111111111111\"},\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ },\ {\ \"title\":\"album_title b.c\",\"lib_id\":{\"Value\":5},\ \"date\":{\"year\":2009,\"month\":null,\"day\":null},\"seq\":2,\ \"musicbrainz\":{\"Some\":\"11111111-1111-1111-1111-111111111112\"},\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ },\ {\ \"title\":\"album_title b.d\",\"lib_id\":{\"Value\":6},\ \"date\":{\"year\":2015,\"month\":null,\"day\":null},\"seq\":4,\ \"musicbrainz\":\"None\",\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ }\ ]\ },\ @@ -73,13 +73,13 @@ pub static DATABASE_JSON: &str = "{\ \"title\":\"album_title c.a\",\"lib_id\":{\"Value\":7},\ \"date\":{\"year\":1985,\"month\":null,\"day\":null},\"seq\":0,\ \"musicbrainz\":\"None\",\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ },\ {\ \"title\":\"album_title c.b\",\"lib_id\":{\"Value\":8},\ \"date\":{\"year\":2018,\"month\":null,\"day\":null},\"seq\":0,\ \"musicbrainz\":\"None\",\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ }\ ]\ },\ @@ -93,13 +93,13 @@ pub static DATABASE_JSON: &str = "{\ \"title\":\"album_title d.a\",\"lib_id\":{\"Value\":9},\ \"date\":{\"year\":1995,\"month\":null,\"day\":null},\"seq\":0,\ \"musicbrainz\":\"None\",\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ },\ {\ \"title\":\"album_title d.b\",\"lib_id\":{\"Value\":10},\ \"date\":{\"year\":2028,\"month\":null,\"day\":null},\"seq\":0,\ \"musicbrainz\":\"None\",\ - \"primary_type\":\"Album\",\"secondary_types\":[]\ + \"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\ }\ ]\ }\ diff --git a/src/external/database/serde/common.rs b/src/external/database/serde/common.rs index 1cc230e..c4c245a 100644 --- a/src/external/database/serde/common.rs +++ b/src/external/database/serde/common.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use crate::core::collection::{ - album::{AlbumDate, AlbumLibId, AlbumPrimaryType, AlbumSecondaryType}, + album::{AlbumDate, AlbumLibId, AlbumPrimaryType, AlbumSecondaryType, AlbumStatus}, musicbrainz::MbRefOption, }; @@ -59,6 +59,32 @@ pub enum MbRefOptionDef { None, } +#[derive(Debug, Deserialize, Serialize)] +#[serde(remote = "AlbumStatus")] +pub enum AlbumStatusDef { + Official, + Promotion, + Bootleg, + PseudoRelease, + Withdrawn, + Cancelled, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct SerdeAlbumStatus(#[serde(with = "AlbumStatusDef")] AlbumStatus); + +impl From for AlbumStatus { + fn from(value: SerdeAlbumStatus) -> Self { + value.0 + } +} + +impl From for SerdeAlbumStatus { + fn from(value: AlbumStatus) -> Self { + SerdeAlbumStatus(value) + } +} + #[derive(Debug, Deserialize, Serialize)] #[serde(remote = "AlbumPrimaryType")] pub enum AlbumPrimaryTypeDef { diff --git a/src/external/database/serde/deserialize.rs b/src/external/database/serde/deserialize.rs index 889ca84..f73d46c 100644 --- a/src/external/database/serde/deserialize.rs +++ b/src/external/database/serde/deserialize.rs @@ -11,7 +11,7 @@ use crate::{ }, external::database::serde::common::{ MbRefOptionDef, SerdeAlbumDate, SerdeAlbumLibId, SerdeAlbumPrimaryType, - SerdeAlbumSecondaryType, + SerdeAlbumSecondaryType, SerdeAlbumStatus, }, }; @@ -46,6 +46,7 @@ pub struct DeserializeAlbum { date: SerdeAlbumDate, seq: u8, musicbrainz: DeserializeMbRefOption, + status: Option, primary_type: Option, secondary_types: Vec, } @@ -138,7 +139,7 @@ impl From for Album { date: album.date.into(), seq: AlbumSeq(album.seq), info: AlbumInfo { - status: None, + status: album.status.map(Into::into), primary_type: album.primary_type.map(Into::into), secondary_types: album.secondary_types.into_iter().map(Into::into).collect(), }, diff --git a/src/external/database/serde/serialize.rs b/src/external/database/serde/serialize.rs index a88657f..a794aa7 100644 --- a/src/external/database/serde/serialize.rs +++ b/src/external/database/serde/serialize.rs @@ -7,7 +7,7 @@ use crate::{ core::collection::{album::Album, artist::Artist, musicbrainz::IMusicBrainzRef, Collection}, external::database::serde::common::{ MbRefOptionDef, SerdeAlbumDate, SerdeAlbumLibId, SerdeAlbumPrimaryType, - SerdeAlbumSecondaryType, + SerdeAlbumSecondaryType, SerdeAlbumStatus, }, }; @@ -38,6 +38,7 @@ pub struct SerializeAlbum<'a> { date: SerdeAlbumDate, seq: u8, musicbrainz: SerializeMbRefOption<'a>, + status: Option, primary_type: Option, secondary_types: Vec, } @@ -97,6 +98,7 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> { date: album.meta.date.into(), seq: album.meta.seq.0, musicbrainz: (&album.meta.id.mb_ref).into(), + status: album.meta.info.status.map(Into::into), primary_type: album.meta.info.primary_type.map(Into::into), secondary_types: album .meta diff --git a/tests/files/database/database.json b/tests/files/database/database.json index ccce86d..9d4d6f7 100644 --- a/tests/files/database/database.json +++ b/tests/files/database/database.json @@ -1 +1 @@ -{"V20250103":[{"name":"Аркона","sort":"Arkona","musicbrainz":{"Some":"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","lib_id":{"Value":7},"date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]}]},{"name":"Eluveitie","sort":null,"musicbrainz":{"Some":"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]","lib_id":{"Value":1},"date":{"year":2004,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Ep","secondary_types":[]},{"title":"Slania","lib_id":{"Value":2},"date":{"year":2008,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]}]},{"name":"Frontside","sort":null,"musicbrainz":{"Some":"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…","lib_id":{"Value":3},"date":{"year":2001,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]}]},{"name":"Heaven’s Basement","sort":"Heaven’s Basement","musicbrainz":{"Some":"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","lib_id":"Singleton","date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":null,"secondary_types":[]},{"title":"Unbreakable","lib_id":{"Value":4},"date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]}]},{"name":"Metallica","sort":null,"musicbrainz":{"Some":"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","lib_id":{"Value":5},"date":{"year":1984,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]},{"title":"S&M","lib_id":{"Value":6},"date":{"year":1999,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":["Live"]}]}]} \ No newline at end of file +{"V20250103":[{"name":"Аркона","sort":"Arkona","musicbrainz":{"Some":"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","lib_id":{"Value":7},"date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]}]},{"name":"Eluveitie","sort":null,"musicbrainz":{"Some":"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]","lib_id":{"Value":1},"date":{"year":2004,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Ep","secondary_types":[]},{"title":"Slania","lib_id":{"Value":2},"date":{"year":2008,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]}]},{"name":"Frontside","sort":null,"musicbrainz":{"Some":"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…","lib_id":{"Value":3},"date":{"year":2001,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]}]},{"name":"Heaven’s Basement","sort":"Heaven’s Basement","musicbrainz":{"Some":"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","lib_id":"Singleton","date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":null,"primary_type":null,"secondary_types":[]},{"title":"Unbreakable","lib_id":{"Value":4},"date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]}]},{"name":"Metallica","sort":null,"musicbrainz":{"Some":"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","lib_id":{"Value":5},"date":{"year":1984,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]},{"title":"S&M","lib_id":{"Value":6},"date":{"year":1999,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":["Live"]}]}]} \ No newline at end of file