artifacts: add artifact sources
This commit is contained in:
+21
-4
@@ -3,13 +3,22 @@ use schemars::JsonSchema;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlite::OpenFlags;
|
use sqlite::OpenFlags;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum SourceID {
|
||||||
|
Bandcamp(u64),
|
||||||
|
Mixxx,
|
||||||
|
Beets
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
pub struct Artist {
|
pub struct Artist {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub bio: Option<String>,
|
pub bio: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub location: Option<String>
|
pub location: Option<String>,
|
||||||
|
|
||||||
|
pub sources: Vec<SourceID>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Artist {
|
impl PartialEq for Artist {
|
||||||
@@ -36,6 +45,8 @@ pub struct Album {
|
|||||||
pub credits: Option<String>,
|
pub credits: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub release_date: Option<DateTime<Utc>>,
|
pub release_date: Option<DateTime<Utc>>,
|
||||||
|
|
||||||
|
pub sources: Vec<SourceID>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
@@ -53,7 +64,9 @@ pub struct Track {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub artist: Option<String>,
|
pub artist: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub bpm: Option<f64>
|
pub bpm: Option<f64>,
|
||||||
|
|
||||||
|
pub sources: Vec<SourceID>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Track {
|
impl PartialEq for Track {
|
||||||
@@ -122,7 +135,7 @@ impl Artifact {
|
|||||||
|
|
||||||
impl Into<Artifact> for bandcamp::Artist {
|
impl Into<Artifact> for bandcamp::Artist {
|
||||||
fn into(self) -> Artifact {
|
fn into(self) -> Artifact {
|
||||||
Artifact::Artist(Artist { name: self.name, bio: self.bio, location: self.location })
|
Artifact::Artist(Artist { name: self.name, bio: self.bio, location: self.location, sources: vec![SourceID::Bandcamp(self.id)] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +146,8 @@ impl Into<Artifact> for bandcamp::Album {
|
|||||||
title: self.title,
|
title: self.title,
|
||||||
artist: self.band.name,
|
artist: self.band.name,
|
||||||
credits: self.credits,
|
credits: self.credits,
|
||||||
release_date: Some(self.release_date)
|
release_date: Some(self.release_date),
|
||||||
|
sources: vec!{SourceID::Bandcamp(self.id)}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,17 +195,20 @@ impl MixxxDB {
|
|||||||
album: Some(album.into()),
|
album: Some(album.into()),
|
||||||
title: title.into(),
|
title: title.into(),
|
||||||
bpm: Some(bpm),
|
bpm: Some(bpm),
|
||||||
|
sources: vec![SourceID::Mixxx],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ret.push(Artifact::Album(Album {
|
ret.push(Artifact::Album(Album {
|
||||||
artist: artist.into(),
|
artist: artist.into(),
|
||||||
title: album.into(),
|
title: album.into(),
|
||||||
|
sources: vec![SourceID::Mixxx],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ret.push(Artifact::Artist(Artist {
|
ret.push(Artifact::Artist(Artist {
|
||||||
name: artist.into(),
|
name: artist.into(),
|
||||||
|
sources: vec![SourceID::Mixxx],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user