diff --git a/src/main.rs b/src/main.rs index a0d303d..3b4635b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ pub mod auth; pub mod config; pub mod metadata; pub mod parser; +pub mod queue; pub mod queued_item; pub mod util; @@ -51,7 +52,7 @@ async fn main() -> Result<(), Box> { println!("Token did not expire"); } - match is_queue_empty(&app).await { + match queue::is_queue_empty(&app).await { Ok((empty, song_queue_item)) => { if !empty { println!("Queue is not empty"); @@ -62,7 +63,8 @@ async fn main() -> Result<(), Box> { match parser::some_work(&app, &song_queue_id, &user_id).await { Ok((song, coverart, _metadata, queued_song, queued_coverart)) => { - match wipe_data_from_queues(&app, &queued_song, &queued_coverart).await + match queue::wipe_data_from_queues(&app, &queued_song, &queued_coverart) + .await { Ok(_) => match parser::cleanup(&song, &coverart).await { Ok(_) => { @@ -94,58 +96,3 @@ async fn main() -> Result<(), Box> { tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await; } } - -async fn wipe_data_from_queues( - app: &config::App, - queued_song: &crate::queued_item::QueuedSong, - queued_coverart: &crate::queued_item::QueuedCoverArt, -) -> Result<(), std::io::Error> { - match api::wipe_data::song_queue::wipe_data(app, queued_song).await { - Ok(response) => match response - .json::() - .await - { - Ok(_resp) => { - match api::wipe_data::coverart_queue::wipe_data(app, queued_coverart).await { - Ok(inner_response) => match inner_response - .json::() - .await - { - Ok(_inner_resp) => { - println!("Wiped data from CoverArt queue"); - println!("Resp: {_inner_resp:?}"); - Ok(()) - } - Err(err) => Err(std::io::Error::other(err.to_string())), - }, - Err(err) => Err(std::io::Error::other(err.to_string())), - } - } - Err(err) => Err(std::io::Error::other(err.to_string())), - }, - Err(err) => Err(std::io::Error::other(err.to_string())), - } -} - -async fn is_queue_empty( - app: &config::App, -) -> Result<(bool, api::fetch_next_queue_item::response::SongQueueItem), reqwest::Error> { - match api::fetch_next_queue_item::fetch_next_queue_item(app).await { - Ok(response) => { - match response - .json::() - .await - { - Ok(response) => { - if response.data.is_empty() { - Ok((true, response)) - } else { - Ok((false, response)) - } - } - Err(err) => Err(err), - } - } - Err(err) => Err(err), - } -} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 0edee95..f4c8260 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -18,7 +18,9 @@ pub async fn some_work( match crate::metadata::apply_metadata(&queued_song, &queued_coverart, &metadata).await { Ok(_applied) => { - match crate::api::update_queued_song::update_queued_song(app, &queued_song).await { + match crate::api::update_queued_song::update_queued_song(app, &queued_song) + .await + { Ok(response) => { match response .json::() diff --git a/src/queue/mod.rs b/src/queue/mod.rs new file mode 100644 index 0000000..8ce5c6a --- /dev/null +++ b/src/queue/mod.rs @@ -0,0 +1,60 @@ +pub async fn wipe_data_from_queues( + app: &crate::config::App, + queued_song: &crate::queued_item::QueuedSong, + queued_coverart: &crate::queued_item::QueuedCoverArt, +) -> Result<(), std::io::Error> { + match crate::api::wipe_data::song_queue::wipe_data(app, queued_song).await { + Ok(response) => match response + .json::() + .await + { + Ok(_resp) => { + match crate::api::wipe_data::coverart_queue::wipe_data(app, queued_coverart).await { + Ok(inner_response) => match inner_response + .json::() + .await + { + Ok(_inner_resp) => { + println!("Wiped data from CoverArt queue"); + println!("Resp: {_inner_resp:?}"); + Ok(()) + } + Err(err) => Err(std::io::Error::other(err.to_string())), + }, + Err(err) => Err(std::io::Error::other(err.to_string())), + } + } + Err(err) => Err(std::io::Error::other(err.to_string())), + }, + Err(err) => Err(std::io::Error::other(err.to_string())), + } +} + +pub async fn is_queue_empty( + app: &crate::config::App, +) -> Result< + ( + bool, + crate::api::fetch_next_queue_item::response::SongQueueItem, + ), + reqwest::Error, +> { + match crate::api::fetch_next_queue_item::fetch_next_queue_item(app).await { + Ok(response) => { + match response + .json::() + .await + { + Ok(response) => { + if response.data.is_empty() { + Ok((true, response)) + } else { + Ok((false, response)) + } + } + Err(err) => Err(err), + } + } + Err(err) => Err(err), + } +}