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 {
|
||||
Ok(response) => {
|
||||
// Process data here...
|
||||
match api::fetch_song_queue_data::response::parse_response(response).await {
|
||||
Ok(all_bytes) => {
|
||||
match api::parsing::parse_response_into_bytes(response).await {
|
||||
Ok(song_bytes) => {
|
||||
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);
|
||||
|
||||
@@ -182,21 +182,10 @@ mod api {
|
||||
client.get(api_url).send().await
|
||||
}
|
||||
|
||||
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 response {
|
||||
pub mod parsing {
|
||||
use futures::StreamExt;
|
||||
|
||||
pub async fn parse_response(
|
||||
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
|
||||
@@ -212,6 +201,17 @@ mod api {
|
||||
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 {
|
||||
@@ -234,7 +234,7 @@ mod api {
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Metadata {
|
||||
pub id: uuid::Uuid,
|
||||
pub song_queue_id: uuid::Uuid,
|
||||
pub album: String,
|
||||
pub album_artist: String,
|
||||
pub artist: String,
|
||||
|
Reference in New Issue
Block a user