From c16ad062d4092affe4518f856d259f4747432eff Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 19:15:26 +0000 Subject: [PATCH] Create coverArt (#34) Reviewed-on: https://git.kundeng.us/phoenix/songparser/pulls/34 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 6 +++--- Cargo.toml | 4 ++-- src/main.rs | 45 ++++++++++++++++++++++++++++++++++----------- src/the_rest.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8911f2..68cd5b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -518,8 +518,8 @@ dependencies = [ [[package]] name = "icarus_models" -version = "0.5.0" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.0-devel-7958b89abc-111#7958b89abc56bc9262015b3e201ea2906cc8a9ff" +version = "0.4.5" +source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.4.5-devel-655d05dabb-111#655d05dabbdadb9b28940564a1eb82470aa4f166" dependencies = [ "rand", "serde", @@ -1255,7 +1255,7 @@ dependencies = [ [[package]] name = "songparser" -version = "0.2.0" +version = "0.2.1" dependencies = [ "futures", "icarus_envy", diff --git a/Cargo.toml b/Cargo.toml index b568463..14cc263 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "songparser" -version = "0.2.0" +version = "0.2.1" edition = "2024" rust-version = "1.88" @@ -14,5 +14,5 @@ time = { version = "0.3.41", features = ["macros", "serde"] } uuid = { version = "1.17.0", features = ["v4", "serde"] } rand = { version = "0.9.1" } icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0-devel-f4b71de969-680" } -icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.0-devel-7958b89abc-111" } +icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.5-devel-655d05dabb-111" } icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.0-devel-d73fba9899-006" } diff --git a/src/main.rs b/src/main.rs index 7bb1141..2cd73d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,15 @@ async fn main() -> Result<(), Box> { // TODO: Do something with the result later match some_work(&app_base_url, &song_queue_id).await { - Ok(_) => {} + Ok(( + song, + coverart, + (song_queue_id, song_queue_path), + (coverart_queue_id, coverart_queue_path), + )) => { + // TODO: Wipe data from song and coverart queues + // TODO: Cleanup files in local filesystem + } Err(err) => { eprintln!("Error: {err:?}"); } @@ -69,7 +77,15 @@ async fn is_queue_empty( async fn some_work( app_base_url: &String, song_queue_id: &uuid::Uuid, -) -> Result<(), std::io::Error> { +) -> Result< + ( + icarus_models::song::Song, + icarus_models::coverart::CoverArt, + (uuid::Uuid, String), + (uuid::Uuid, String), + ), + std::io::Error, +> { match prep_song(app_base_url, song_queue_id).await { Ok((song_queue_path, coverart_queue_path, metadata, coverart_queue_id)) => { match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await { @@ -111,15 +127,22 @@ async fn some_work( println!("Response: {resp:?}"); let song = &resp.data[0]; - let url = format!("{app_base_url}/api/v2/coverart"); - let payload = serde_json::json!({ - "song_id": &song.id, - "coverart_queue_id": &coverart_queue_id, - }); - println!("Payload: {payload:?}"); - println!("Url: {url:?}"); - // println!("Response json: {:?}", response.text().await); - Ok(()) + match the_rest::create_coverart::create(app_base_url, &song.id, &coverart_queue_id).await { + Ok(response) => match response.json::().await { + Ok(resp) => { + println!("CoverArt sent and successfully parsed response"); + println!("json: {resp:?}"); + let coverart = &resp.data[0]; + Ok((song.clone(), coverart.clone(), (metadata.song_queue_id, song_queue_path), (coverart_queue_id, coverart_queue_path))) + } + Err(err) => { + Err(std::io::Error::other(err.to_string())) + } + } + Err(err) => { + Err(std::io::Error::other(err.to_string())) + } + } } Err(err) => Err(std::io::Error::other(err.to_string())), }, diff --git a/src/the_rest.rs b/src/the_rest.rs index 8afffe7..8b12392 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -45,5 +45,36 @@ pub mod create_song { } // TODO: Create coverart +pub mod create_coverart { + + pub async fn create( + base_url: &String, + song_id: &uuid::Uuid, + coverart_queue_id: &uuid::Uuid, + ) -> Result { + let client = reqwest::Client::builder().build()?; + let url = format!("{base_url}/api/v2/coverart"); + let payload = get_payload(song_id, coverart_queue_id); + let request = client.post(url).json(&payload); + + request.send().await + } + + fn get_payload(song_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid) -> serde_json::Value { + serde_json::json!({ + "song_id": &song_id, + "coverart_queue_id": &coverart_queue_id, + }) + } + + pub mod response { + #[derive(Debug, serde::Deserialize, serde::Serialize)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } +} + // TODO: Wipe data from queued song // TODO: Wipe data from queued coverart