Saving changes
This commit is contained in:
63
src/main.rs
63
src/main.rs
@@ -1,4 +1,5 @@
|
|||||||
pub mod the_rest;
|
pub mod the_rest;
|
||||||
|
pub mod update_queued_song;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@@ -20,7 +21,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let song_queue_id = song_queue_item.data[0].id;
|
let song_queue_id = song_queue_item.data[0].id;
|
||||||
|
|
||||||
// TODO: Do something with the result later
|
// TODO: Do something with the result later
|
||||||
let _ = process_song(&app_base_url, &song_queue_id).await;
|
let _ = prep_song(&app_base_url, &song_queue_id).await;
|
||||||
|
let _ = some_work(&app_base_url, &song_queue_id).await;
|
||||||
} else {
|
} else {
|
||||||
println!("Queue is empty");
|
println!("Queue is empty");
|
||||||
}
|
}
|
||||||
@@ -58,7 +60,41 @@ async fn is_queue_empty(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<(), reqwest::Error> {
|
async fn some_work(app_base_url: &String, song_queue_id: &uuid::Uuid) -> Result<(), std::io::Error> {
|
||||||
|
match prep_song(app_base_url, song_queue_id).await {
|
||||||
|
Ok((song_queue_path, coverart_queue_path, metadata)) => {
|
||||||
|
match apply_metadata(song_queue_path.clone(), coverart_queue_path, metadata).await {
|
||||||
|
Ok(song_path) => {
|
||||||
|
// let s_path = util::path_buf_to_string(&song_queue_path);
|
||||||
|
Ok(())
|
||||||
|
// Ok((s_path))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_err) => {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// let s_err: reqwest::Error = err.into();
|
||||||
|
// let error = reqwest::Error::new(
|
||||||
|
// reqwest::ErrorKind::Request, // Error kind
|
||||||
|
// err.to_string() // Error message
|
||||||
|
// );
|
||||||
|
// Err(error)
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
async fn prep_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<(String, String, api::get_metadata_queue::response::Metadata), reqwest::Error> {
|
||||||
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
|
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
// Process data here...
|
// Process data here...
|
||||||
@@ -77,8 +113,8 @@ async fn process_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<()
|
|||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let id = &response.data[0].id;
|
let id = &response.data[0].id;
|
||||||
let metadata = &response.data[0].metadata;
|
|
||||||
let created_at = &response.data[0].created_at;
|
let created_at = &response.data[0].created_at;
|
||||||
|
let metadata = &response.data[0].metadata;
|
||||||
println!("Id: {:?}", id);
|
println!("Id: {:?}", id);
|
||||||
println!("Metadata: {:?}", metadata);
|
println!("Metadata: {:?}", metadata);
|
||||||
println!("Created at: {:?}", created_at);
|
println!("Created at: {:?}", created_at);
|
||||||
@@ -100,35 +136,34 @@ async fn process_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<()
|
|||||||
|
|
||||||
println!("Saved coverart queue file at: {:?}", coverart_queue_path);
|
println!("Saved coverart queue file at: {:?}", coverart_queue_path);
|
||||||
|
|
||||||
match apply_metadata(song_queue_path.clone(), coverart_queue_path, metadata).await {
|
let c_path = util::path_buf_to_string(&coverart_queue_path);
|
||||||
Ok(_) => {
|
let s_path = util::path_buf_to_string(&song_queue_path);
|
||||||
let s_path = util::path_buf_to_string(&song_queue_path);
|
Ok((s_path, c_path, metadata.clone()))
|
||||||
the_rest::update_queued_song(&s_path).await;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Error: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {:?}", err);
|
eprintln!("Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {:?}", err);
|
eprintln!("Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {:?}", err);
|
eprintln!("Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {:?}", err);
|
eprintln!("Error: {:?}", err);
|
||||||
|
Err(err)
|
||||||
|
// Err(reqwest::Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
// Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {:?}", err);
|
eprintln!("Error: {:?}", err);
|
||||||
@@ -433,7 +468,7 @@ mod api {
|
|||||||
pub mod response {
|
pub mod response {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
pub song_queue_id: uuid::Uuid,
|
pub song_queue_id: uuid::Uuid,
|
||||||
pub album: String,
|
pub album: String,
|
||||||
|
@@ -1,9 +1,6 @@
|
|||||||
// TODO: Refactor this file when this app is functional
|
// TODO: Refactor this file when this app is functional
|
||||||
|
|
||||||
|
|
||||||
// TODO: Update the queued song with the updated queued song
|
|
||||||
pub async fn update_queued_song(song_path: &String) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Create song
|
// TODO: Create song
|
||||||
// TODO: Create coverart
|
// TODO: Create coverart
|
||||||
|
44
src/update_queued_song.rs
Normal file
44
src/update_queued_song.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
use reqwest::multipart;
|
||||||
|
|
||||||
|
// TODO: Update the queued song with the updated queued song
|
||||||
|
pub async fn update_queued_song(base_url: &String, song_path: &String, song_queue_id: &uuid::Uuid) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
|
|
||||||
|
/*
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
let form = reqwest::multipart::Form::new()
|
||||||
|
.part("file", reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap()).file_name("track01.flac"));
|
||||||
|
|
||||||
|
let method = "PATCH";
|
||||||
|
let url = format!("{}/api/v2/song/queue/{}", base_url, song_queue_id);
|
||||||
|
let request = client.request(reqwest::Method::from_bytes(method.as_bytes()).unwrap(), url)
|
||||||
|
.multipart(form);
|
||||||
|
|
||||||
|
let response = request.send().await?;
|
||||||
|
*/
|
||||||
|
// let body = response.text().await?;
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
let form = reqwest::multipart::Form::new()
|
||||||
|
.part("file",
|
||||||
|
reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap()).file_name("track01.flac"));
|
||||||
|
|
||||||
|
let method = "PATCH";
|
||||||
|
let url = format!("{}/api/v2/song/queue/{}", base_url, song_queue_id);
|
||||||
|
let request = client.request(reqwest::Method::from_bytes(method.as_bytes()).unwrap(), url)
|
||||||
|
.multipart(form);
|
||||||
|
|
||||||
|
let response = request.send().await?;
|
||||||
|
|
||||||
|
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub mod response {
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
}
|
Reference in New Issue
Block a user