Compare commits

...

9 Commits

Author SHA1 Message Date
99bb72ffb2 Removing hard coded user_id (#38)
Some checks failed
Rust Build / Check (push) Failing after 39s
Release Tagging / release (push) Successful in 43s
Rust Build / Test Suite (push) Failing after 36s
Rust Build / Rustfmt (push) Successful in 30s
Rust Build / Clippy (push) Failing after 35s
Rust Build / build (push) Failing after 1m28s
Rust Build / Check (pull_request) Failing after 32s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Failing after 35s
Rust Build / Test Suite (pull_request) Failing after 1m10s
Rust Build / build (pull_request) Failing after 35s
Reviewed-on: #38
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-23 01:18:35 +00:00
111d16515f Wipe data from CoverArt queue (#36)
Some checks failed
Release Tagging / release (push) Successful in 32s
Rust Build / Check (push) Failing after 34s
Rust Build / Test Suite (push) Failing after 37s
Rust Build / Rustfmt (push) Successful in 29s
Rust Build / Clippy (push) Failing after 36s
Rust Build / build (push) Failing after 37s
Rust Build / Check (pull_request) Failing after 1m58s
Rust Build / Test Suite (pull_request) Failing after 1m21s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Failing after 1m7s
Rust Build / build (pull_request) Failing after 2m5s
Reviewed-on: #36
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-15 20:10:12 +00:00
47bf24180b Wipe data from song queue (#35)
Some checks failed
Release Tagging / release (push) Successful in 33s
Rust Build / Check (push) Failing after 35s
Rust Build / Test Suite (push) Failing after 41s
Rust Build / Rustfmt (push) Successful in 30s
Rust Build / Clippy (push) Failing after 41s
Rust Build / build (push) Failing after 40s
Rust Build / Check (pull_request) Failing after 36s
Rust Build / Test Suite (pull_request) Failing after 37s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Failing after 34s
Rust Build / build (pull_request) Failing after 35s
Reviewed-on: #35
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-15 19:49:24 +00:00
c16ad062d4 Create coverArt (#34)
Some checks failed
Release Tagging / release (push) Successful in 30s
Rust Build / Check (push) Failing after 32s
Rust Build / Check (pull_request) Failing after 33s
Rust Build / Test Suite (push) Failing after 34s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Failing after 37s
Rust Build / build (push) Failing after 36s
Rust Build / Test Suite (pull_request) Failing after 38s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Failing after 38s
Rust Build / build (pull_request) Failing after 38s
Reviewed-on: #34
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-15 19:15:26 +00:00
a779e13a77 Create song (#33)
All checks were successful
Release Tagging / release (push) Successful in 28s
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 33s
Rust Build / Rustfmt (push) Successful in 24s
Rust Build / Clippy (push) Successful in 33s
Rust Build / build (push) Successful in 38s
Rust Build / Check (pull_request) Successful in 37s
Rust Build / Test Suite (pull_request) Successful in 38s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Successful in 35s
Rust Build / build (pull_request) Successful in 44s
Reviewed-on: #33
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-15 00:53:12 +00:00
fe61fe3efb Tag release change (#32)
All checks were successful
Release Tagging / release (push) Successful in 31s
Rust Build / Check (push) Successful in 29s
Rust Build / Test Suite (push) Successful in 32s
Rust Build / Rustfmt (push) Successful in 24s
Rust Build / Clippy (push) Successful in 31s
Rust Build / build (push) Successful in 37s
Rust Build / Check (pull_request) Successful in 1m17s
Rust Build / Test Suite (pull_request) Successful in 1m35s
Rust Build / Rustfmt (pull_request) Successful in 25s
Rust Build / Clippy (pull_request) Successful in 1m23s
Rust Build / build (pull_request) Successful in 2m53s
Reviewed-on: #32
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-06-29 22:20:40 +00:00
f9f3dbda36 Refactoring (#31)
All checks were successful
Rust Build / Check (push) Successful in 33s
Rust Build / Check (pull_request) Successful in 35s
Rust Build / build (push) Successful in 41s
Release Tagging / release (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 37s
Rust Build / Rustfmt (push) Successful in 26s
Rust Build / Clippy (push) Successful in 33s
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Rustfmt (pull_request) Successful in 27s
Rust Build / Clippy (pull_request) Successful in 31s
Rust Build / build (pull_request) Successful in 37s
Reviewed-on: #31
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-06-29 22:08:23 +00:00
59ce1c294c Update dependencies (#30)
Some checks failed
Release Tagging / release (push) Successful in 31s
Rust Build / Check (pull_request) Successful in 33s
Rust Build / Check (push) Successful in 33s
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Rustfmt (pull_request) Successful in 24s
Rust Build / Clippy (pull_request) Failing after 32s
Rust Build / build (pull_request) Successful in 54s
Rust Build / Test Suite (push) Successful in 30s
Rust Build / Rustfmt (push) Successful in 24s
Rust Build / Clippy (push) Failing after 29s
Rust Build / build (push) Successful in 34s
Reviewed-on: #30
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-06-29 21:50:34 +00:00
cd1be017e5 rust std change (#29)
Some checks failed
Rust Build / Check (push) Has been cancelled
Release Tagging / release (push) Has been cancelled
Rust Build / Test Suite (push) Has been cancelled
Rust Build / Rustfmt (push) Has been cancelled
Rust Build / Clippy (push) Has been cancelled
Rust Build / build (push) Has been cancelled
Rust Build / Check (pull_request) Successful in 33s
Rust Build / Test Suite (pull_request) Successful in 37s
Rust Build / Rustfmt (pull_request) Successful in 25s
Rust Build / Clippy (pull_request) Failing after 32s
Rust Build / build (pull_request) Successful in 38s
Reviewed-on: #29
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-06-29 21:50:04 +00:00
8 changed files with 436 additions and 211 deletions

View File

@@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
@@ -36,7 +36,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
@@ -54,7 +54,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: rustup component add rustfmt - run: rustup component add rustfmt
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
@@ -73,7 +73,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: rustup component add clippy - run: rustup component add clippy
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
@@ -92,7 +92,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key

25
Cargo.lock generated
View File

@@ -501,8 +501,8 @@ dependencies = [
[[package]] [[package]]
name = "icarus_envy" name = "icarus_envy"
version = "0.2.2" version = "0.3.0"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.2.2-devel-84ea6e4c22-006#84ea6e4c223f19ff96f6b7cae944e831ef4aa831" source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.0-devel-d73fba9899-006#d73fba9899372b0655a90cb426645930135152da"
dependencies = [ dependencies = [
"const_format", "const_format",
"dotenvy", "dotenvy",
@@ -510,16 +510,16 @@ dependencies = [
[[package]] [[package]]
name = "icarus_meta" name = "icarus_meta"
version = "0.2.2" version = "0.3.0"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.2.2-devel-565d361b64-680#565d361b64f23c2a0100b33fceeebacfad3331c4" source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.3.0-devel-f4b71de969-680#f4b71de9692029a706b1ce82c39f6715c560158e"
dependencies = [ dependencies = [
"lofty", "lofty",
] ]
[[package]] [[package]]
name = "icarus_models" name = "icarus_models"
version = "0.4.3" version = "0.4.5"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.4.3#6aa4c3d74142f5fceb4a6e95078bb3ae0a2d99c5" source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.4.5-devel-655d05dabb-111#655d05dabbdadb9b28940564a1eb82470aa4f166"
dependencies = [ dependencies = [
"rand", "rand",
"serde", "serde",
@@ -973,13 +973,12 @@ checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
dependencies = [ dependencies = [
"rand_chacha", "rand_chacha",
"rand_core", "rand_core",
"zerocopy",
] ]
[[package]] [[package]]
@@ -1012,9 +1011,9 @@ dependencies = [
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.12.19" version = "0.12.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2f8e5513d63f2e5b386eb5106dc67eaf3f84e95258e210489136b8b92ad6119" checksum = "eabf4c97d9130e2bf606614eb937e86edac8292eaa6f422f995d7e8de1eb1813"
dependencies = [ dependencies = [
"base64", "base64",
"bytes", "bytes",
@@ -1029,13 +1028,11 @@ dependencies = [
"hyper-rustls", "hyper-rustls",
"hyper-tls", "hyper-tls",
"hyper-util", "hyper-util",
"ipnet",
"js-sys", "js-sys",
"log", "log",
"mime", "mime",
"mime_guess", "mime_guess",
"native-tls", "native-tls",
"once_cell",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"rustls-pki-types", "rustls-pki-types",
@@ -1258,7 +1255,7 @@ dependencies = [
[[package]] [[package]]
name = "songparser" name = "songparser"
version = "0.1.0" version = "0.2.3"
dependencies = [ dependencies = [
"futures", "futures",
"icarus_envy", "icarus_envy",

View File

@@ -1,18 +1,18 @@
[package] [package]
name = "songparser" name = "songparser"
version = "0.1.0" version = "0.2.3"
edition = "2024" edition = "2024"
rust-version = "1.86" rust-version = "1.88"
[dependencies] [dependencies]
tokio = { version = "1.44.1", features = ["full"] } tokio = { version = "1.45.1", features = ["full"] }
futures = { version = "0.3.31" } futures = { version = "0.3.31" }
reqwest = { version = "0.12.19", features = ["json", "stream", "multipart"] } reqwest = { version = "0.12.20", features = ["json", "stream", "multipart"] }
serde = { version = "1.0.218", features = ["derive"] } serde = { version = "1.0.219", features = ["derive"] }
serde_json = { version = "1.0.139" } serde_json = { version = "1.0.140" }
time = { version = "0.3.41", features = ["macros", "serde"] } time = { version = "0.3.41", features = ["macros", "serde"] }
uuid = { version = "1.16.0", features = ["v4", "serde"] } uuid = { version = "1.17.0", features = ["v4", "serde"] }
rand = { version = "0.9" } rand = { version = "0.9.1" }
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.2.2-devel-565d361b64-680" } icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0-devel-f4b71de969-680" }
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.5-devel-655d05dabb-111" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.2.2-devel-84ea6e4c22-006" } icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.0-devel-d73fba9899-006" }

131
src/api.rs Normal file
View File

@@ -0,0 +1,131 @@
pub async fn fetch_next_queue_item(base_url: &String) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let fetch_endpoint = String::from("api/v2/song/queue/next");
let api_url = format!("{base_url}/{fetch_endpoint}");
client.get(api_url).send().await
}
pub mod parsing {
use futures::StreamExt;
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
// large
let mut byte_stream = response.bytes_stream();
let mut all_bytes = Vec::new();
while let Some(chunk) = byte_stream.next().await {
let chunk = chunk?;
all_bytes.extend_from_slice(&chunk);
}
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 {
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/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(Clone, Debug, Deserialize, Serialize)]
pub struct Metadata {
pub song_queue_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>,
}
}
}
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 async fn get_data(
base_url: &String,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let endpoint = String::from("api/v2/coverart/queue/data");
let api_url = format!("{base_url}/{endpoint}/{coverart_queue_id}");
client.get(api_url).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>,
}
}
}

View File

@@ -1,3 +1,5 @@
pub mod api;
pub mod responses;
pub mod the_rest; pub mod the_rest;
pub mod update_queued_song; pub mod update_queued_song;
pub mod util; pub mod util;
@@ -11,20 +13,42 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app_base_url = icarus_envy::environment::get_icarus_base_api_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 is_queue_empty(&app_base_url).await { match is_queue_empty(&app_base_url).await {
Ok((empty, song_queue_item)) => { Ok((empty, song_queue_item)) => {
if !empty { if !empty {
println!("Queue is not empty"); println!("Queue is not empty");
println!("SongQueueItem: {:?}", song_queue_item); println!("SongQueueItem: {song_queue_item:?}");
let song_queue_id = song_queue_item.data[0].id; let song_queue_id = song_queue_item.data[0].id;
let user_id = song_queue_item.data[0].user_id;
// TODO: Do something with the result later // TODO: Do something with the result later
match some_work(&app_base_url, &song_queue_id).await { match some_work(&app_base_url, &song_queue_id, &user_id).await {
Ok(_) => {} Ok((
_song,
_coverart,
(song_queue_id, song_queue_path),
(coverart_queue_id, coverart_queue_path),
)) => {
// TODO: Wipe data from song and coverart queues
match wipe_data_from_queues(
&app_base_url,
&song_queue_id,
&coverart_queue_id,
)
.await
{
Ok(_) => {
// TODO: Cleanup files in local filesystem
}
Err(err) => { Err(err) => {
eprintln!("Error: {:?}", err); eprintln!("Error: {err:?}");
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
} }
} }
} else { } else {
@@ -32,7 +56,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
} }
Err(err) => { Err(err) => {
eprintln!("Error checking if queue is empty: {:?}", err); eprintln!("Error checking if queue is empty: {err:?}");
} }
} }
@@ -41,6 +65,41 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
} }
async fn wipe_data_from_queues(
app_base_url: &String,
song_queue_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> Result<(), std::io::Error> {
match the_rest::wipe_data::song_queue::wipe_data(app_base_url, song_queue_id).await {
Ok(response) => match response
.json::<the_rest::wipe_data::song_queue::response::Response>()
.await
{
Ok(_resp) => match the_rest::wipe_data::coverart_queue::wipe_data(
app_base_url,
coverart_queue_id,
)
.await
{
Ok(inner_response) => match inner_response
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
.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( async fn is_queue_empty(
api_url: &String, api_url: &String,
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> { ) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
@@ -67,9 +126,18 @@ async fn is_queue_empty(
async fn some_work( async fn some_work(
app_base_url: &String, app_base_url: &String,
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
) -> Result<(), std::io::Error> { user_id: &uuid::Uuid,
) -> Result<
(
icarus_models::song::Song,
icarus_models::coverart::CoverArt,
(uuid::Uuid, String),
(uuid::Uuid, String),
),
std::io::Error,
> {
match prep_song(app_base_url, song_queue_id).await { match prep_song(app_base_url, song_queue_id).await {
Ok((song_queue_path, coverart_queue_path, metadata)) => { Ok((song_queue_path, coverart_queue_path, metadata, coverart_queue_id)) => {
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await { match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
Ok(_applied) => { Ok(_applied) => {
match update_queued_song::update_queued_song( match update_queued_song::update_queued_song(
@@ -85,8 +153,48 @@ async fn some_work(
.await .await
{ {
Ok(_inner_response) => { Ok(_inner_response) => {
println!("Response: {:?}", _inner_response); println!("Response: {_inner_response:?}");
Ok(())
// TODO: Place this somewhere else
let song_type = String::from("flac");
match the_rest::create_song::create(
app_base_url,
&metadata,
user_id,
&song_type,
)
.await
{
Ok(response) => match response
.json::<the_rest::create_song::response::Response>()
.await
{
Ok(resp) => {
println!("Response: {resp:?}");
let song = &resp.data[0];
match the_rest::create_coverart::create(app_base_url, &song.id, &coverart_queue_id).await {
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
Ok(resp) => {
println!("CoverArt sent and successfully parsed response");
println!("json: {resp:?}");
let coverart = &resp.data[0];
Ok((song.clone(), coverart.clone(), (metadata.song_queue_id, song_queue_path), (coverart_queue_id, coverart_queue_path)))
}
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())),
}
} }
Err(err) => Err(std::io::Error::other(err.to_string())), Err(err) => Err(std::io::Error::other(err.to_string())),
} }
@@ -104,7 +212,15 @@ async fn some_work(
async fn prep_song( async fn prep_song(
api_url: &String, api_url: &String,
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
) -> Result<(String, String, api::get_metadata_queue::response::Metadata), reqwest::Error> { ) -> Result<
(
String,
String,
api::get_metadata_queue::response::Metadata,
uuid::Uuid,
),
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...
@@ -113,7 +229,7 @@ async fn prep_song(
let (directory, filename) = generate_song_queue_dir_and_filename().await; let (directory, filename) = generate_song_queue_dir_and_filename().await;
let song_queue_path = save_file_to_fs(&directory, &filename, &song_bytes).await; let song_queue_path = save_file_to_fs(&directory, &filename, &song_bytes).await;
println!("Saved at: {:?}", song_queue_path); println!("Saved at: {song_queue_path:?}");
match api::get_metadata_queue::get(api_url, song_queue_id).await { match api::get_metadata_queue::get(api_url, song_queue_id).await {
Ok(response) => { Ok(response) => {
@@ -125,9 +241,9 @@ async fn prep_song(
let id = &response.data[0].id; let id = &response.data[0].id;
let created_at = &response.data[0].created_at; let created_at = &response.data[0].created_at;
let metadata = &response.data[0].metadata; 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:?}");
println!("Getting coverart queue"); println!("Getting coverart queue");
match api::get_coverart_queue::get(api_url, song_queue_id).await match api::get_coverart_queue::get(api_url, song_queue_id).await
@@ -136,7 +252,7 @@ async fn prep_song(
match response.json::<api::get_coverart_queue::response::Response>().await { match response.json::<api::get_coverart_queue::response::Response>().await {
Ok(response) => { Ok(response) => {
let coverart_queue_id = &response.data[0].id; let coverart_queue_id = &response.data[0].id;
println!("Coverart queue Id: {:?}", coverart_queue_id); println!("Coverart queue Id: {coverart_queue_id:?}");
match api::get_coverart_queue::get_data(api_url, coverart_queue_id).await { match api::get_coverart_queue::get_data(api_url, coverart_queue_id).await {
Ok(response) => match api::parsing::parse_response_into_bytes(response).await { Ok(response) => match api::parsing::parse_response_into_bytes(response).await {
@@ -144,11 +260,11 @@ async fn prep_song(
let (directory, filename) = generate_coverart_queue_dir_and_filename().await; let (directory, filename) = generate_coverart_queue_dir_and_filename().await;
let coverart_queue_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await; let coverart_queue_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await;
println!("Saved coverart queue file at: {:?}", coverart_queue_path); println!("Saved coverart queue file at: {coverart_queue_path:?}");
let c_path = util::path_buf_to_string(&coverart_queue_path); let c_path = util::path_buf_to_string(&coverart_queue_path);
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())) Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
} }
Err(err) => { Err(err) => {
Err(err) Err(err)
@@ -350,7 +466,7 @@ pub async fn apply_metadata(
match icarus_meta::meta::coverart::contains_coverart(song_queue_path) { match icarus_meta::meta::coverart::contains_coverart(song_queue_path) {
Ok((exists, size)) => { Ok((exists, size)) => {
if exists { if exists {
println!("Coverart exists: {:?} size", size); println!("Coverart exists: {size:?} size");
match icarus_meta::meta::coverart::remove_coverart(song_queue_path) { match icarus_meta::meta::coverart::remove_coverart(song_queue_path) {
Ok(_data) => {} Ok(_data) => {}
Err(err) => { Err(err) => {
@@ -375,158 +491,3 @@ pub async fn apply_metadata(
Err(err) => Err(err), Err(err) => Err(err),
} }
} }
mod responses {
pub mod fetch_next_queue_item {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct QueueItem {
pub id: uuid::Uuid,
pub filename: String,
pub status: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SongQueueItem {
pub message: String,
pub data: Vec<QueueItem>,
}
}
}
mod api {
pub async fn fetch_next_queue_item(
base_url: &String,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let fetch_endpoint = String::from("api/v2/song/queue/next");
let api_url = format!("{}/{}", base_url, fetch_endpoint);
client.get(api_url).send().await
}
pub mod parsing {
use futures::StreamExt;
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
// large
let mut byte_stream = response.bytes_stream();
let mut all_bytes = Vec::new();
while let Some(chunk) = byte_stream.next().await {
let chunk = chunk?;
all_bytes.extend_from_slice(&chunk);
}
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 {
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/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(Clone, Debug, Deserialize, Serialize)]
pub struct Metadata {
pub song_queue_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>,
}
}
}
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 async fn get_data(
base_url: &String,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let endpoint = String::from("api/v2/coverart/queue/data");
let api_url = format!("{}/{}/{}", base_url, endpoint, coverart_queue_id);
client.get(api_url).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>,
}
}
}
}

17
src/responses.rs Normal file
View File

@@ -0,0 +1,17 @@
pub mod fetch_next_queue_item {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct QueueItem {
pub id: uuid::Uuid,
pub filename: String,
pub status: String,
pub user_id: uuid::Uuid,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SongQueueItem {
pub message: String,
pub data: Vec<QueueItem>,
}
}

View File

@@ -1,6 +1,125 @@
// TODO: Refactor this file when this app is functional // TODO: Refactor this file when this app is functional
// TODO: Create song pub mod create_song {
// TODO: Create coverart pub async fn create(
// TODO: Wipe data from queued song base_url: &String,
metadata_queue: &crate::api::get_metadata_queue::response::Metadata,
user_id: &uuid::Uuid,
song_type: &String,
) -> Result<reqwest::Response, reqwest::Error> {
let payload = serde_json::json!(
{
"album": &metadata_queue.album,
"album_artist": &metadata_queue.album_artist,
"artist": &metadata_queue.artist,
"disc": metadata_queue.disc,
"disc_count": metadata_queue.disc_count,
"duration": metadata_queue.duration,
"genre": &metadata_queue.genre,
"title": &metadata_queue.title,
"track": metadata_queue.track,
"track_count": metadata_queue.track_count,
"date": metadata_queue.year.to_string(),
"audio_type": &song_type,
"user_id": &user_id,
"song_queue_id": &metadata_queue.song_queue_id,
}
);
let client = reqwest::Client::builder().build()?;
let url = format!("{base_url}/api/v2/song");
let request = client.post(url).json(&payload);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::song::Song>,
}
}
}
pub mod create_coverart {
pub async fn create(
base_url: &String,
song_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{base_url}/api/v2/coverart");
let payload = get_payload(song_id, coverart_queue_id);
let request = client.post(url).json(&payload);
request.send().await
}
fn get_payload(song_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid) -> serde_json::Value {
serde_json::json!({
"song_id": &song_id,
"coverart_queue_id": &coverart_queue_id,
})
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::coverart::CoverArt>,
}
}
}
pub mod wipe_data {
pub mod song_queue {
pub async fn wipe_data(
base_url: &String,
song_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{base_url}/api/v2/song/queue/data/wipe");
let payload = serde_json::json!({
"song_queue_id": song_queue_id
});
let request = client.patch(url).json(&payload);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
// TODO: Wipe data from queued coverart // TODO: Wipe data from queued coverart
pub mod coverart_queue {
pub async fn wipe_data(
base_url: &String,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{base_url}/api/v2/coverart/queue/data/wipe");
let payload = serde_json::json!({
"coverart_queue_id": coverart_queue_id
});
let request = client.patch(url).json(&payload);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
}

View File

@@ -5,7 +5,7 @@ pub async fn update_queued_song(
) -> Result<reqwest::Response, reqwest::Error> { ) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?; let client = reqwest::Client::builder().build()?;
println!("Song path: {:?}", song_path); println!("Song path: {song_path:?}");
// TODO: Make the filename random // TODO: Make the filename random
let form = reqwest::multipart::Form::new().part( let form = reqwest::multipart::Form::new().part(
@@ -14,8 +14,8 @@ pub async fn update_queued_song(
.file_name("track01.flac"), .file_name("track01.flac"),
); );
let url = format!("{}/api/v2/song/queue/{}", base_url, song_queue_id); let url = format!("{base_url}/api/v2/song/queue/{song_queue_id}");
println!("Url: {:?}", url); println!("Url: {url:?}");
let request = client.patch(url).multipart(form); let request = client.patch(url).multipart(form);