Compare commits
22 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date | |
---|---|---|---|
29b806fd02 | |||
557264482f | |||
4e07ee5d0f | |||
eaa3c6f40e | |||
79eea81e28 | |||
006fa3a2d8 | |||
2f11ff9e89 | |||
5ced62ec7a | |||
817ea9fed2 | |||
ce1d522814 | |||
c04c6cdd6c | |||
f1375f5639 | |||
b41933e05e | |||
d1610d1331 | |||
8bc49e781b | |||
f68d01d50f | |||
41001ec926 | |||
775a62d9cc | |||
a24dd6aba0 | |||
522395f0ad | |||
9bfc0a10ea | |||
cbb286790c |
2
.env.docker.sample
Normal file
2
.env.docker.sample
Normal file
@@ -0,0 +1,2 @@
|
||||
ROOT_DIRECTORY=/home/songparser/mydata
|
||||
ICARUS_BASE_API_URL=http://localhost:3000
|
2
.env.sample
Normal file
2
.env.sample
Normal file
@@ -0,0 +1,2 @@
|
||||
ROOT_DIRECTORY=/home/songparser/mydata
|
||||
ICARUS_BASE_API_URL=http://localhost:3000
|
@@ -5,8 +5,6 @@ on:
|
||||
branches:
|
||||
- main
|
||||
- devel
|
||||
tags:
|
||||
- 'v*' # Trigger on tags matching v*
|
||||
|
||||
jobs:
|
||||
release:
|
||||
@@ -20,7 +18,7 @@ jobs:
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.85.0
|
||||
toolchain: 1.86.0
|
||||
components: cargo
|
||||
|
||||
- name: Extract Version from Cargo.toml
|
||||
@@ -31,7 +29,7 @@ jobs:
|
||||
BRANCH_REF="${GITHUB_REF}"
|
||||
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
||||
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH"
|
||||
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE-111"
|
||||
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE-372"
|
||||
echo "Version: $VERSION"
|
||||
echo "Hash: $PROJECT_COMMIT_HASH"
|
||||
echo "Branch: $BRANCH_NAME"
|
||||
|
@@ -18,58 +18,87 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.85.0
|
||||
- run: cargo check
|
||||
toolchain: 1.86.0
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||
cargo check
|
||||
|
||||
test:
|
||||
name: Test Suite
|
||||
runs-on: ubuntu-24.04
|
||||
needs: setup_ssh
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.85.0
|
||||
- run: cargo test
|
||||
toolchain: 1.86.0
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||
cargo test
|
||||
|
||||
fmt:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-24.04
|
||||
needs: setup_ssh
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.85.0
|
||||
toolchain: 1.86.0
|
||||
- run: rustup component add rustfmt
|
||||
- run: cargo fmt --all -- --check
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||
cargo fmt --all -- --check
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-24.04
|
||||
needs: setup_ssh
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.85.0
|
||||
toolchain: 1.86.0
|
||||
- run: rustup component add clippy
|
||||
- run: cargo clippy -- -D warnings
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||
cargo clippy -- -D warnings
|
||||
|
||||
build:
|
||||
name: build
|
||||
runs-on: ubuntu-24.04
|
||||
needs: setup_ssh
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.85.0
|
||||
toolchain: 1.86.0
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "$EXTREPO_KEY" > ~/.ssh/gitlab_deploy_key
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||
ssh-keyscan git.kundeng.us ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLl/OZiKVDxwnyvMxa+rjKvDpKqTxH1GWuGuDPLmENGQMbTVulajZWr9x8Q1cotoJiHZkt7DA5vczcjB/4lwgWA= >> ~/.ssh/known_hosts
|
||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||
|
||||
cargo build --release
|
||||
env:
|
||||
EXTREPO_KEY: ${{ secrets.MYREPO_TOKEN }}
|
||||
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
.env
|
||||
|
1903
Cargo.lock
generated
Normal file
1903
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
@@ -2,6 +2,16 @@
|
||||
name = "songparser"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.86"
|
||||
|
||||
[dependencies]
|
||||
icarus-models = { git = "ssh://git@git.kundeng.us/phoenix/icarus-models.git", tag = "v0.1.14" }
|
||||
tokio = { version = "1.44.1", features = ["full"] }
|
||||
futures = { version = "0.3.31" }
|
||||
reqwest = { version = "0.12.19", features = ["json", "stream"] }
|
||||
serde = { version = "1.0.218", features = ["derive"] }
|
||||
serde_json = { version = "1.0.139" }
|
||||
time = { version = "0.3.41", features = ["macros", "serde"] }
|
||||
uuid = { version = "1.16.0", features = ["v4", "serde"] }
|
||||
rand = { version = "0.9" }
|
||||
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.2-devel-84ea6e4c22-006" }
|
||||
|
356
src/main.rs
356
src/main.rs
@@ -1,3 +1,355 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::io::Write;
|
||||
|
||||
pub const SECONDS_TO_SLEEP: u64 = 5;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let app_base_url = icarus_envy::environment::get_icarus_base_api_url().await;
|
||||
|
||||
loop {
|
||||
println!("Base URL: {}", app_base_url);
|
||||
|
||||
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
|
||||
let _ = process_song(&app_base_url, &song_queue_id).await;
|
||||
} 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) => {
|
||||
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::parsing::parse_response_into_bytes(response).await {
|
||||
Ok(song_bytes) => {
|
||||
let (directory, filename) = generate_song_queue_dir_and_filename().await;
|
||||
let save_path = save_file_to_fs(&directory, &filename, &song_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) => {
|
||||
let id = &response.data[0].id;
|
||||
let metadata = &response.data[0].metadata;
|
||||
let created_at = &response.data[0].created_at;
|
||||
println!("Id: {:?}", id);
|
||||
println!("Metadata: {:?}", metadata);
|
||||
println!("Created at: {:?}", created_at);
|
||||
|
||||
println!("Getting coverart queue");
|
||||
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 save_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await;
|
||||
|
||||
println!("Saved coverart queue file at: {:?}", save_path);
|
||||
|
||||
// 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: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {:?}", err);
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {:?}", err);
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Consider having something like this in icarus_models
|
||||
pub async fn generate_song_queue_dir_and_filename() -> (String, String) {
|
||||
let mut song = icarus_models::song::Song::default();
|
||||
song.filename = song.generate_filename(icarus_models::types::MusicTypes::FlacExtension, true);
|
||||
|
||||
song.directory = icarus_envy::environment::get_root_directory().await;
|
||||
|
||||
(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
|
||||
pub async fn save_file_to_fs(
|
||||
directory: &String,
|
||||
filename: &String,
|
||||
data: &[u8],
|
||||
) -> std::path::PathBuf {
|
||||
// TODO: Add function to save bytes to a file in icarus_models
|
||||
// repo
|
||||
let dir = std::path::Path::new(directory);
|
||||
let save_path = dir.join(filename);
|
||||
|
||||
let mut file = std::fs::File::create(&save_path).unwrap();
|
||||
file.write_all(data).unwrap();
|
||||
|
||||
save_path
|
||||
}
|
||||
|
||||
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(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>,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user