Get queued coverart data #26
48
src/main.rs
48
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,6 +182,26 @@ mod api {
|
|||||||
client.get(api_url).send().await
|
client.get(api_url).send().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod parsing {
|
||||||
|
use futures::StreamExt;
|
||||||
|
|
||||||
|
pub async fn parse_response_into_bytes(
|
||||||
|
response: reqwest::Response,
|
||||||
|
) -> Result<Vec<u8>, reqwest::Error> {
|
||||||
|
// TODO: At some point, handle the flow if the size is small or
|
||||||
|
// large
|
||||||
|
let mut byte_stream = response.bytes_stream();
|
||||||
|
let mut all_bytes = Vec::new();
|
||||||
|
|
||||||
|
while let Some(chunk) = byte_stream.next().await {
|
||||||
|
let chunk = chunk?;
|
||||||
|
all_bytes.extend_from_slice(&chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(all_bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod fetch_song_queue_data {
|
pub mod fetch_song_queue_data {
|
||||||
pub async fn get_data(
|
pub async fn get_data(
|
||||||
base_url: &String,
|
base_url: &String,
|
||||||
@@ -192,26 +212,6 @@ mod api {
|
|||||||
let api_url = format!("{}/{}/{}", base_url, endpoint, id);
|
let api_url = format!("{}/{}/{}", base_url, endpoint, id);
|
||||||
client.get(api_url).send().await
|
client.get(api_url).send().await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
|
||||||
use futures::StreamExt;
|
|
||||||
|
|
||||||
pub async fn parse_response(
|
|
||||||
response: reqwest::Response,
|
|
||||||
) -> Result<Vec<u8>, reqwest::Error> {
|
|
||||||
// TODO: At some point, handle the flow if the size is small or
|
|
||||||
// large
|
|
||||||
let mut byte_stream = response.bytes_stream();
|
|
||||||
let mut all_bytes = Vec::new();
|
|
||||||
|
|
||||||
while let Some(chunk) = byte_stream.next().await {
|
|
||||||
let chunk = chunk?;
|
|
||||||
all_bytes.extend_from_slice(&chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(all_bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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