Get queued coverart data #26
34
src/main.rs
34
src/main.rs
@@ -59,10 +59,10 @@ async fn process_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<()
|
|||||||
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
|
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
// Process data here...
|
// Process data here...
|
||||||
match api::fetch_song_queue_data::response::parse_response(response).await {
|
match api::parsing::parse_response_into_bytes(response).await {
|
||||||
Ok(all_bytes) => {
|
Ok(song_bytes) => {
|
||||||
let (directory, filename) = generate_song_queue_dir_and_filename().await;
|
let (directory, filename) = generate_song_queue_dir_and_filename().await;
|
||||||
let save_path = save_song_to_fs(&directory, &filename, &all_bytes).await;
|
let save_path = save_song_to_fs(&directory, &filename, &song_bytes).await;
|
||||||
|
|
||||||
println!("Saved at: {:?}", save_path);
|
println!("Saved at: {:?}", save_path);
|
||||||
|
|
||||||
@@ -182,21 +182,10 @@ mod api {
|
|||||||
client.get(api_url).send().await
|
client.get(api_url).send().await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod fetch_song_queue_data {
|
pub mod parsing {
|
||||||
pub async fn get_data(
|
|
||||||
base_url: &String,
|
|
||||||
id: &uuid::Uuid,
|
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let endpoint = String::from("api/v2/song/queue");
|
|
||||||
let api_url = format!("{}/{}/{}", base_url, endpoint, id);
|
|
||||||
client.get(api_url).send().await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod response {
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
pub async fn parse_response(
|
pub async fn parse_response_into_bytes(
|
||||||
response: reqwest::Response,
|
response: reqwest::Response,
|
||||||
) -> Result<Vec<u8>, reqwest::Error> {
|
) -> Result<Vec<u8>, reqwest::Error> {
|
||||||
// TODO: At some point, handle the flow if the size is small or
|
// TODO: At some point, handle the flow if the size is small or
|
||||||
@@ -212,6 +201,17 @@ mod api {
|
|||||||
Ok(all_bytes)
|
Ok(all_bytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod fetch_song_queue_data {
|
||||||
|
pub async fn get_data(
|
||||||
|
base_url: &String,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let endpoint = String::from("api/v2/song/queue");
|
||||||
|
let api_url = format!("{}/{}/{}", base_url, endpoint, id);
|
||||||
|
client.get(api_url).send().await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod get_metadata_queue {
|
pub mod get_metadata_queue {
|
||||||
@@ -234,7 +234,7 @@ mod api {
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
pub id: uuid::Uuid,
|
pub song_queue_id: uuid::Uuid,
|
||||||
pub album: String,
|
pub album: String,
|
||||||
pub album_artist: String,
|
pub album_artist: String,
|
||||||
pub artist: String,
|
pub artist: String,
|
||||||
|
Reference in New Issue
Block a user