fetch song queue data #21
48
src/main.rs
48
src/main.rs
@@ -1,6 +1,5 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use futures::StreamExt;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -26,31 +25,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
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...
|
// 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 song's metadata
|
||||||
// TODO: Get queued coverart
|
// TODO: Get queued coverart
|
||||||
@@ -109,6 +91,7 @@ pub async fn save_song_to_fs(directory: &String, filename: &String, data: &Vec<u
|
|||||||
save_path
|
save_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mod responses {
|
mod responses {
|
||||||
pub mod fetch_next_queue_item {
|
pub mod fetch_next_queue_item {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -150,9 +133,24 @@ mod api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
|
use futures::StreamExt;
|
||||||
// use serde::{Deserialize, Serialize};
|
// use serde::{Deserialize, Serialize};
|
||||||
// pub struct Response {
|
// 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user