Compare commits
10 Commits
v0.1.0-dev
...
v0.2.0-dev
Author | SHA1 | Date | |
---|---|---|---|
a779e13a77 | |||
fe61fe3efb | |||
f9f3dbda36 | |||
59ce1c294c | |||
cd1be017e5 | |||
2f05c20d4e | |||
e138bf7a2e | |||
29b806fd02 | |||
557264482f | |||
4e07ee5d0f |
@@ -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
|
||||||
|
120
Cargo.lock
generated
120
Cargo.lock
generated
@@ -62,6 +62,12 @@ version = "3.17.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
|
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.10.1"
|
version = "1.10.1"
|
||||||
@@ -119,6 +125,21 @@ version = "0.8.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crc32fast"
|
||||||
|
version = "1.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "data-encoding"
|
||||||
|
version = "2.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deranged"
|
name = "deranged"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@@ -177,6 +198,16 @@ version = "2.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flate2"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d"
|
||||||
|
dependencies = [
|
||||||
|
"crc32fast",
|
||||||
|
"miniz_oxide",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
@@ -470,17 +501,25 @@ 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",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icarus_meta"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.3.0-devel-f4b71de969-680#f4b71de9692029a706b1ce82c39f6715c560158e"
|
||||||
|
dependencies = [
|
||||||
|
"lofty",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.4.3"
|
version = "0.5.0"
|
||||||
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.5.0-devel-7958b89abc-111#7958b89abc56bc9262015b3e201ea2906cc8a9ff"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -666,6 +705,32 @@ dependencies = [
|
|||||||
"scopeguard",
|
"scopeguard",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lofty"
|
||||||
|
version = "0.22.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca260c51a9c71f823fbfd2e6fbc8eb2ee09834b98c00763d877ca8bfa85cde3e"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"data-encoding",
|
||||||
|
"flate2",
|
||||||
|
"lofty_attr",
|
||||||
|
"log",
|
||||||
|
"ogg_pager",
|
||||||
|
"paste",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lofty_attr"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed9983e64b2358522f745c1251924e3ab7252d55637e80f6a0a3de642d6a9efc"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.27"
|
version = "0.4.27"
|
||||||
@@ -684,6 +749,16 @@ version = "0.3.17"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mime_guess"
|
||||||
|
version = "2.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
|
||||||
|
dependencies = [
|
||||||
|
"mime",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
@@ -736,6 +811,15 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ogg_pager"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e034c10fb5c1c012c1b327b85df89fb0ef98ae66ec28af30f0d1eed804a40c19"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.21.3"
|
version = "1.21.3"
|
||||||
@@ -809,6 +893,12 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.1"
|
version = "2.3.1"
|
||||||
@@ -883,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]]
|
||||||
@@ -922,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",
|
||||||
@@ -939,12 +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",
|
||||||
"native-tls",
|
"native-tls",
|
||||||
"once_cell",
|
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
@@ -1167,11 +1255,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"icarus_envy",
|
"icarus_envy",
|
||||||
|
"icarus_meta",
|
||||||
"icarus_models",
|
"icarus_models",
|
||||||
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -1430,6 +1520,12 @@ version = "0.2.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicase"
|
||||||
|
version = "2.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
|
20
Cargo.toml
20
Cargo.toml
@@ -1,16 +1,18 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
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"] }
|
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"] }
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" }
|
rand = { version = "0.9.1" }
|
||||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.2.2-devel-84ea6e4c22-006" }
|
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.5.0-devel-7958b89abc-111" }
|
||||||
|
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
131
src/api.rs
Normal 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>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
533
src/main.rs
533
src/main.rs
@@ -1,3 +1,9 @@
|
|||||||
|
pub mod api;
|
||||||
|
pub mod responses;
|
||||||
|
pub mod the_rest;
|
||||||
|
pub mod update_queued_song;
|
||||||
|
pub mod util;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
pub const SECONDS_TO_SLEEP: u64 = 5;
|
pub const SECONDS_TO_SLEEP: u64 = 5;
|
||||||
@@ -7,93 +13,216 @@ 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 api::fetch_next_queue_item(&app_base_url).await {
|
match is_queue_empty(&app_base_url).await {
|
||||||
|
Ok((empty, song_queue_item)) => {
|
||||||
|
if !empty {
|
||||||
|
println!("Queue is not empty");
|
||||||
|
println!("SongQueueItem: {song_queue_item:?}");
|
||||||
|
let song_queue_id = song_queue_item.data[0].id;
|
||||||
|
|
||||||
|
// TODO: Do something with the result later
|
||||||
|
match some_work(&app_base_url, &song_queue_id).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Queue is empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(song_queue_item) => {
|
Ok(response) => {
|
||||||
if !song_queue_item.data.is_empty() {
|
if response.data.is_empty() {
|
||||||
println!("Song queue item: {:?}", song_queue_item);
|
Ok((true, response))
|
||||||
let song_queue_id = song_queue_item.data[0].id;
|
} else {
|
||||||
|
Ok((false, response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Fetching song queue data");
|
async fn some_work(
|
||||||
match api::fetch_song_queue_data::get_data(
|
app_base_url: &String,
|
||||||
&app_base_url,
|
song_queue_id: &uuid::Uuid,
|
||||||
&song_queue_id,
|
) -> Result<(), std::io::Error> {
|
||||||
|
match prep_song(app_base_url, song_queue_id).await {
|
||||||
|
Ok((song_queue_path, coverart_queue_path, metadata, coverart_queue_id)) => {
|
||||||
|
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
||||||
|
Ok(_applied) => {
|
||||||
|
match update_queued_song::update_queued_song(
|
||||||
|
app_base_url,
|
||||||
|
&song_queue_path,
|
||||||
|
song_queue_id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
match response
|
||||||
|
.json::<update_queued_song::response::Response>()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_inner_response) => {
|
||||||
|
println!("Response: {_inner_response:?}");
|
||||||
|
|
||||||
|
// TODO: Do not hard code this. Check if one of the existing
|
||||||
|
// endpoints already have the user_id
|
||||||
|
let user_id = uuid::Uuid::new_v4();
|
||||||
|
// TODO: Place this somewhere else
|
||||||
|
let song_type = String::from("flac");
|
||||||
|
// Err(std::io::Error::other(err.to_string()))
|
||||||
|
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];
|
||||||
|
let url = format!("{app_base_url}/api/v2/coverart");
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"song_id": &song.id,
|
||||||
|
"coverart_queue_id": &coverart_queue_id,
|
||||||
|
});
|
||||||
|
println!("Payload: {payload:?}");
|
||||||
|
println!("Url: {url:?}");
|
||||||
|
// println!("Response json: {:?}", response.text().await);
|
||||||
|
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())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn prep_song(
|
||||||
|
api_url: &String,
|
||||||
|
song_queue_id: &uuid::Uuid,
|
||||||
|
) -> 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 {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
// Process data here...
|
// Process data here...
|
||||||
let all_bytes =
|
match api::parsing::parse_response_into_bytes(response).await {
|
||||||
api::fetch_song_queue_data::response::parse_response(
|
Ok(song_bytes) => {
|
||||||
response,
|
let (directory, filename) = generate_song_queue_dir_and_filename().await;
|
||||||
)
|
let song_queue_path = save_file_to_fs(&directory, &filename, &song_bytes).await;
|
||||||
.await?;
|
|
||||||
|
|
||||||
let (directory, filename) =
|
println!("Saved at: {song_queue_path:?}");
|
||||||
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 api::get_metadata_queue::get(
|
match response
|
||||||
&app_base_url,
|
.json::<api::get_metadata_queue::response::Response>()
|
||||||
&song_queue_id,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
|
||||||
match response.json::<api::get_metadata_queue::response::Response>().await {
|
|
||||||
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;
|
||||||
println!("Id: {:?}", id);
|
let metadata = &response.data[0].metadata;
|
||||||
println!("Metadata: {:?}", metadata);
|
println!("Id: {id:?}");
|
||||||
println!("Created at: {:?}", created_at);
|
println!("Metadata: {metadata:?}");
|
||||||
// TODO: Get queued coverart
|
println!("Created at: {created_at:?}");
|
||||||
// TODO: Get queued coverart's data
|
|
||||||
// TODO: Apply metadata to the queued song (modifying file)
|
|
||||||
// TODO: Update the queued song with the updated queued song
|
|
||||||
// TODO: Create song
|
|
||||||
// TODO: Create coverart
|
|
||||||
// TODO: Wipe data from queued song
|
|
||||||
// TODO: Wipe data from queued coverart
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Error: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Error: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Error fetching song queue data: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("No data to fetch");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Error: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => eprintln!("API call failed: {}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Sleeping");
|
println!("Getting coverart queue");
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await;
|
match api::get_coverart_queue::get(api_url, song_queue_id).await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
match response.json::<api::get_coverart_queue::response::Response>().await {
|
||||||
|
Ok(response) => {
|
||||||
|
let coverart_queue_id = &response.data[0].id;
|
||||||
|
println!("Coverart queue Id: {coverart_queue_id:?}");
|
||||||
|
|
||||||
|
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(coverart_queue_bytes) => {
|
||||||
|
let (directory, filename) = generate_coverart_queue_dir_and_filename().await;
|
||||||
|
let coverart_queue_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await;
|
||||||
|
|
||||||
|
println!("Saved coverart queue file at: {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);
|
||||||
|
Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +236,37 @@ pub async fn generate_song_queue_dir_and_filename() -> (String, String) {
|
|||||||
(song.directory, song.filename)
|
(song.directory, song.filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Consider having something like this in icarus_models
|
||||||
|
pub async fn generate_coverart_queue_dir_and_filename() -> (String, String) {
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
let mut filename: String = String::new();
|
||||||
|
let filename_len = 10;
|
||||||
|
|
||||||
|
let some_chars: String = String::from("abcdefghij0123456789");
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
|
||||||
|
for _i in 0..filename_len {
|
||||||
|
let random_number: i32 = rng.random_range(0..=19);
|
||||||
|
let index = random_number as usize;
|
||||||
|
let rando_char = some_chars.chars().nth(index);
|
||||||
|
|
||||||
|
if let Some(c) = rando_char {
|
||||||
|
filename.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Do not hard code the file extension
|
||||||
|
filename += ".jpeg";
|
||||||
|
|
||||||
|
// TODO: Consider separating song and coverart when saving to the filesystem
|
||||||
|
let directory = icarus_envy::environment::get_root_directory().await;
|
||||||
|
|
||||||
|
(directory, filename)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Check to see if this is available in icarus_models
|
// TODO: Check to see if this is available in icarus_models
|
||||||
pub async fn save_song_to_fs(
|
pub async fn save_file_to_fs(
|
||||||
directory: &String,
|
directory: &String,
|
||||||
filename: &String,
|
filename: &String,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
@@ -124,115 +282,142 @@ pub async fn save_song_to_fs(
|
|||||||
save_path
|
save_path
|
||||||
}
|
}
|
||||||
|
|
||||||
mod responses {
|
pub async fn apply_metadata(
|
||||||
pub mod fetch_next_queue_item {
|
song_queue_path: &String,
|
||||||
use serde::{Deserialize, Serialize};
|
coverart_queue_path: &String,
|
||||||
|
metadata: &api::get_metadata_queue::response::Metadata,
|
||||||
|
) -> Result<bool, std::io::Error> {
|
||||||
|
// Apply metadata fields
|
||||||
|
let types = icarus_meta::types::all_metadata_types();
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
for t in types {
|
||||||
pub struct QueueItem {
|
match t {
|
||||||
pub id: uuid::Uuid,
|
icarus_meta::types::Type::Album => {
|
||||||
pub filename: String,
|
let meta_type =
|
||||||
pub status: String,
|
icarus_meta::types::MetadataType::from_string(metadata.album.clone());
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::AlbumArtist => {
|
||||||
|
let meta_type =
|
||||||
|
icarus_meta::types::MetadataType::from_string(metadata.album_artist.clone());
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::Artist => {
|
||||||
|
let meta_type =
|
||||||
|
icarus_meta::types::MetadataType::from_string(metadata.artist.clone());
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::Date => {
|
||||||
|
// TODO: Do something about this discrepancy
|
||||||
|
let meta_type =
|
||||||
|
icarus_meta::types::MetadataType::from_string(metadata.year.to_string());
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::Disc => {
|
||||||
|
let meta_type = icarus_meta::types::MetadataType::from_int(metadata.disc);
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::Genre => {
|
||||||
|
let meta_type =
|
||||||
|
icarus_meta::types::MetadataType::from_string(metadata.genre.clone());
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::Title => {
|
||||||
|
let meta_type =
|
||||||
|
icarus_meta::types::MetadataType::from_string(metadata.title.clone());
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::Track => {
|
||||||
|
let meta_type = icarus_meta::types::MetadataType::from_int(metadata.track);
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::TrackCount => {
|
||||||
|
let meta_type = icarus_meta::types::MetadataType::from_int(metadata.track_count);
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icarus_meta::types::Type::DiscCount => {
|
||||||
|
let meta_type = icarus_meta::types::MetadataType::from_int(metadata.disc_count);
|
||||||
|
match icarus_meta::meta::metadata::set_meta_value(t, song_queue_path, meta_type) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_err) => {
|
||||||
|
return Err(_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
// Apply coverart
|
||||||
pub struct SongQueueItem {
|
match icarus_meta::meta::coverart::contains_coverart(song_queue_path) {
|
||||||
pub message: String,
|
Ok((exists, size)) => {
|
||||||
pub data: Vec<QueueItem>,
|
if exists {
|
||||||
}
|
println!("Coverart exists: {size:?} size");
|
||||||
}
|
match icarus_meta::meta::coverart::remove_coverart(song_queue_path) {
|
||||||
}
|
Ok(_data) => {}
|
||||||
|
Err(err) => {
|
||||||
mod api {
|
return Err(err);
|
||||||
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 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 response {
|
|
||||||
use futures::StreamExt;
|
|
||||||
|
|
||||||
pub async fn parse_response(
|
|
||||||
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 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(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>,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match icarus_meta::meta::coverart::set_coverart(song_queue_path, coverart_queue_path) {
|
||||||
|
Ok(_data) => {
|
||||||
|
if _data.is_empty() {
|
||||||
|
println!("There was an issue");
|
||||||
|
Ok(false)
|
||||||
|
} else {
|
||||||
|
println!("Success in applying coverart to song");
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
16
src/responses.rs
Normal file
16
src/responses.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
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>,
|
||||||
|
}
|
||||||
|
}
|
49
src/the_rest.rs
Normal file
49
src/the_rest.rs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
// TODO: Refactor this file when this app is functional
|
||||||
|
|
||||||
|
// TODO: Create song
|
||||||
|
pub mod create_song {
|
||||||
|
pub async fn create(
|
||||||
|
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>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Create coverart
|
||||||
|
// TODO: Wipe data from queued song
|
||||||
|
// TODO: Wipe data from queued coverart
|
35
src/update_queued_song.rs
Normal file
35
src/update_queued_song.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
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()?;
|
||||||
|
|
||||||
|
println!("Song path: {song_path:?}");
|
||||||
|
|
||||||
|
// TODO: Make the filename random
|
||||||
|
let form = reqwest::multipart::Form::new().part(
|
||||||
|
"file",
|
||||||
|
reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap())
|
||||||
|
.file_name("track01.flac"),
|
||||||
|
);
|
||||||
|
|
||||||
|
let url = format!("{base_url}/api/v2/song/queue/{song_queue_id}");
|
||||||
|
println!("Url: {url:?}");
|
||||||
|
|
||||||
|
let request = client.patch(url).multipart(form);
|
||||||
|
|
||||||
|
let response = request.send().await?;
|
||||||
|
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod response {
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
6
src/util.rs
Normal file
6
src/util.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
pub fn path_buf_to_string(path: &std::path::Path) -> String {
|
||||||
|
match path.to_str() {
|
||||||
|
Some(val) => String::from(val),
|
||||||
|
None => String::new(),
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user