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