fetch song queue data #21

Merged
phoenix merged 9 commits from fetch_song_queue_data into devel 2025-06-12 18:57:03 +00:00
Showing only changes of commit 83fc701d24 - Show all commits

View File

@@ -1,6 +1,5 @@
use std::io::Write;
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -26,31 +25,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await
{
Ok(response) => {
// 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);
}
let mut song = icarus_models::song::Song::default();
// song.data = all_bytes;
song.filename = song.generate_filename(
icarus_models::types::MusicTypes::FlacExtension,
true,
);
song.directory =
icarus_envy::environment::get_root_directory().await;
let (directory, filename) = generate_song_queue_dir_and_filename().await;
let _ = save_song_to_fs(&directory, &filename, &all_bytes).await;
// Process data here...
let all_bytes = api::fetch_song_queue_data::response::parse_response(response).await?;
let (directory, filename) = generate_song_queue_dir_and_filename().await;
let save_path = save_song_to_fs(&directory, &filename, &all_bytes).await;
println!("Saved at: {:?}", save_path);
// TODO: Get queued song's metadata
// TODO: Get queued coverart
@@ -109,6 +91,7 @@ pub async fn save_song_to_fs(directory: &String, filename: &String, data: &Vec<u
save_path
}
mod responses {
pub mod fetch_next_queue_item {
use serde::{Deserialize, Serialize};
@@ -150,9 +133,24 @@ mod api {
}
pub mod response {
use futures::StreamExt;
// use serde::{Deserialize, Serialize};
// pub struct Response {
// }
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)
}
}
}
}