Compare commits
3 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date | |
---|---|---|---|
4e07ee5d0f | |||
eaa3c6f40e | |||
79eea81e28 |
33
Cargo.lock
generated
33
Cargo.lock
generated
@@ -83,6 +83,26 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const_format"
|
||||||
|
version = "0.2.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd"
|
||||||
|
dependencies = [
|
||||||
|
"const_format_proc_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const_format_proc_macros"
|
||||||
|
version = "0.2.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
@@ -450,9 +470,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_envy"
|
name = "icarus_envy"
|
||||||
version = "0.2.0"
|
version = "0.2.2"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.2.0#3ee8c1e573ba9637769aa0538d2c11335e39ed9f"
|
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.2.2-devel-84ea6e4c22-006#84ea6e4c223f19ff96f6b7cae944e831ef4aa831"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"const_format",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1148,13 +1169,13 @@ dependencies = [
|
|||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenvy",
|
|
||||||
"futures",
|
"futures",
|
||||||
"icarus_envy",
|
"icarus_envy",
|
||||||
"icarus_models",
|
"icarus_models",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
@@ -1415,6 +1436,12 @@ version = "1.0.18"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
@@ -10,7 +10,7 @@ futures = { version = "0.3.31" }
|
|||||||
reqwest = { version = "0.12.19", features = ["json", "stream"] }
|
reqwest = { version = "0.12.19", features = ["json", "stream"] }
|
||||||
serde = { version = "1.0.218", features = ["derive"] }
|
serde = { version = "1.0.218", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.139" }
|
serde_json = { version = "1.0.139" }
|
||||||
|
time = { version = "0.3.41", features = ["macros", "serde"] }
|
||||||
uuid = { version = "1.16.0", features = ["v4", "serde"] }
|
uuid = { version = "1.16.0", features = ["v4", "serde"] }
|
||||||
dotenvy = { version = "0.15.7" }
|
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" }
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" }
|
||||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.2.0" }
|
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.2.2-devel-84ea6e4c22-006" }
|
||||||
|
174
src/main.rs
174
src/main.rs
@@ -4,71 +4,107 @@ pub const SECONDS_TO_SLEEP: u64 = 5;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let app_base_url = get_icarus_url().await;
|
let app_base_url = icarus_envy::environment::get_icarus_base_api_url().await;
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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_item.data[0].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) =
|
|
||||||
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 coverart
|
// TODO: Get queued coverart
|
||||||
// TODO: Get queued coverart's data
|
// TODO: Get queued coverart's data
|
||||||
// TODO: Apply metadata to the queued song
|
// 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
|
||||||
// TODO: Create song
|
// TODO: Create song
|
||||||
// TODO: Create coverart
|
// TODO: Create coverart
|
||||||
// TODO: Wipe data from queued song
|
// TODO: Wipe data from queued song
|
||||||
// TODO: Wipe data from queued coverart
|
// TODO: Wipe data from queued coverart
|
||||||
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,9 +195,55 @@ mod api {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_icarus_url() -> String {
|
pub mod get_metadata_queue {
|
||||||
dotenvy::dotenv().ok();
|
pub async fn get(
|
||||||
std::env::var("ICARUS_BASE_API_URL").expect("Could not find url")
|
base_url: &String,
|
||||||
|
song_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let endpoint = String::from("api/v2/song/metadata/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 Metadata {
|
||||||
|
pub id: uuid::Uuid,
|
||||||
|
pub album: String,
|
||||||
|
pub album_artist: String,
|
||||||
|
pub artist: String,
|
||||||
|
pub disc: i32,
|
||||||
|
pub disc_count: i32,
|
||||||
|
pub duration: i64,
|
||||||
|
pub genre: String,
|
||||||
|
pub title: String,
|
||||||
|
pub track: i32,
|
||||||
|
pub track_count: i32,
|
||||||
|
pub year: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct QueueItem {
|
||||||
|
pub id: uuid::Uuid,
|
||||||
|
pub metadata: Metadata,
|
||||||
|
#[serde(with = "time::serde::rfc3339")]
|
||||||
|
pub created_at: time::OffsetDateTime,
|
||||||
|
pub song_queue_id: uuid::Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<QueueItem>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user