artifacts: split out each artifact source into a submodule, move archive.rs into artifacts/beets.rs

This commit is contained in:
2026-06-15 15:27:20 +02:00
parent 59a03eb72c
commit 5595b02211
7 changed files with 98 additions and 90 deletions
+77
View File
@@ -0,0 +1,77 @@
use std::process::{Command, Stdio};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::artifacts::{Artifact, SourceID, Track};
#[derive(Debug, Default, Serialize, Deserialize, Clone, JsonSchema)]
pub struct BeatsQueryArgs {
artist: Option<String>,
album: Option<String>,
genre: Option<String>,
title: Option<String>,
year: Option<u32>
}
#[derive(Debug, Default, Deserialize)]
struct BeetsTrack {
album: String,
artist: String,
genres: Option<Vec<String>>,
label: Option<String>,
title: String,
year: u32
}
impl Into<Artifact> for BeetsTrack {
fn into(self) -> Artifact {
Artifact::Track(Track {
title: self.title,
label: self.label,
year: Some(self.year),
genres: self.genres.unwrap_or_default(),
album: Some(self.album),
artist: Some(self.artist),
bpm: None,
sources: vec![SourceID::Beets]
})
}
}
impl BeatsQueryArgs {
pub fn execute(self) -> Result<Vec<Artifact>, ()> {
let mut beets_cmd = Command::new("beet");
beets_cmd.args(["export", "-f", "json", "-i", "title,label,year,genres,album,artist"]);
if let Some(artist) = self.artist {
beets_cmd.arg(format!("artist:{}", artist));
}
if let Some(genre) = self.genre {
beets_cmd.arg(format!("genre:{}", genre));
}
if let Some(album) = self.album {
beets_cmd.arg(format!("album:{}", album));
}
if let Some(title) = self.title {
beets_cmd.arg(format!("title:{}", title));
}
if let Some(year) = self.year {
beets_cmd.arg(format!("year:{}", year));
}
log::debug!("Executing beets: {:?}", beets_cmd);
if let Ok(output) = beets_cmd.stdout(Stdio::piped()).spawn().unwrap().wait_with_output() {
match serde_json::from_str::<Vec<BeetsTrack>>(str::from_utf8(&output.stdout).unwrap()) {
Ok(track) => Ok(track.into_iter().map(|t| { t.into()}).collect()),
Err(err) => {
log::error!("Failed to decode beets json: {:?}", err);
Err(())
}
}
} else {
log::error!("Unable to execute query!");
Err(())
}
}
}