Compare commits
2 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date | |
---|---|---|---|
557264482f | |||
4e07ee5d0f |
165
src/main.rs
165
src/main.rs
@@ -9,55 +9,85 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
loop {
|
loop {
|
||||||
println!("Base URL: {}", app_base_url);
|
println!("Base URL: {}", app_base_url);
|
||||||
|
|
||||||
match api::fetch_next_queue_item(&app_base_url).await {
|
match is_queue_empty(&app_base_url).await {
|
||||||
Ok(response) => {
|
Ok((empty, song_queue_item)) => {
|
||||||
match response
|
if !empty {
|
||||||
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
println!("Queue is not empty");
|
||||||
.await
|
println!("SongQueueItem: {:?}", song_queue_item);
|
||||||
{
|
let song_queue_id = song_queue_item.data[0].id;
|
||||||
Ok(song_queue_item) => {
|
|
||||||
if !song_queue_item.data.is_empty() {
|
|
||||||
println!("Song queue item: {:?}", song_queue_item);
|
|
||||||
let song_queue_id = song_queue_item.data[0].id;
|
|
||||||
|
|
||||||
println!("Fetching song queue data");
|
// TODO: Do something with the result later
|
||||||
match api::fetch_song_queue_data::get_data(
|
let _ = process_song(&app_base_url, &song_queue_id).await;
|
||||||
&app_base_url,
|
} else {
|
||||||
&song_queue_id,
|
println!("Queue is empty");
|
||||||
)
|
}
|
||||||
.await
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error checking if queue is empty: {:?}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Sleeping");
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn is_queue_empty(
|
||||||
|
api_url: &String,
|
||||||
|
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
||||||
|
match api::fetch_next_queue_item(api_url).await {
|
||||||
|
Ok(response) => {
|
||||||
|
match response
|
||||||
|
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
if response.data.is_empty() {
|
||||||
|
Ok((true, response))
|
||||||
|
} else {
|
||||||
|
Ok((false, response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn process_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<(), reqwest::Error> {
|
||||||
|
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) => {
|
||||||
|
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);
|
||||||
|
|
||||||
|
match api::get_metadata_queue::get(api_url, song_queue_id).await {
|
||||||
|
Ok(response) => {
|
||||||
|
match response
|
||||||
|
.json::<api::get_metadata_queue::response::Response>()
|
||||||
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
// Process data here...
|
let id = &response.data[0].id;
|
||||||
let all_bytes =
|
let metadata = &response.data[0].metadata;
|
||||||
api::fetch_song_queue_data::response::parse_response(
|
let created_at = &response.data[0].created_at;
|
||||||
response,
|
println!("Id: {:?}", id);
|
||||||
)
|
println!("Metadata: {:?}", metadata);
|
||||||
.await?;
|
println!("Created at: {:?}", created_at);
|
||||||
|
|
||||||
let (directory, filename) =
|
println!("Getting coverart queue");
|
||||||
generate_song_queue_dir_and_filename().await;
|
match api::get_coverart_queue::get(api_url, song_queue_id).await
|
||||||
let save_path =
|
|
||||||
save_song_to_fs(&directory, &filename, &all_bytes).await;
|
|
||||||
|
|
||||||
println!("Saved at: {:?}", save_path);
|
|
||||||
|
|
||||||
match api::get_metadata_queue::get(
|
|
||||||
&app_base_url,
|
|
||||||
&song_queue_id,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response.json::<api::get_metadata_queue::response::Response>().await {
|
match response.json::<api::get_coverart_queue::response::Response>().await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let id = &response.data[0].id;
|
let coverart_queue_id = &response.data[0].id;
|
||||||
let metadata = &response.data[0].metadata;
|
println!("Coverart queue Id: {:?}", coverart_queue_id);
|
||||||
let created_at = &response.data[0].created_at;
|
|
||||||
println!("Id: {:?}", id);
|
|
||||||
println!("Metadata: {:?}", metadata);
|
|
||||||
println!("Created at: {:?}", created_at);
|
|
||||||
// TODO: Get queued coverart
|
|
||||||
// TODO: Get queued coverart's data
|
// TODO: Get queued coverart's data
|
||||||
// TODO: Apply metadata to the queued song (modifying file)
|
// TODO: Apply metadata to the queued song (modifying file)
|
||||||
// TODO: Update the queued song with the updated queued song
|
// TODO: Update the queued song with the updated queued song
|
||||||
@@ -75,25 +105,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
eprintln!("Error: {:?}", err);
|
eprintln!("Error: {:?}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error fetching song queue data: {:?}", err);
|
eprintln!("Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
println!("No data to fetch");
|
Err(err) => {
|
||||||
|
eprintln!("Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Error: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
Err(e) => eprintln!("API call failed: {}", e),
|
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
println!("Sleeping");
|
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,4 +264,36 @@ mod api {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod get_coverart_queue {
|
||||||
|
pub async fn get(
|
||||||
|
base_url: &String,
|
||||||
|
song_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let endpoint = String::from("api/v2/coverart/queue");
|
||||||
|
let api_url = format!("{}/{}", base_url, endpoint);
|
||||||
|
client
|
||||||
|
.get(api_url)
|
||||||
|
.query(&[("song_queue_id", song_queue_id)])
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod response {
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct CoverArtQueue {
|
||||||
|
pub id: uuid::Uuid,
|
||||||
|
pub song_queue_id: uuid::Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<CoverArtQueue>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user