Compare commits

..

3 Commits

Author SHA1 Message Date
432078e3c2 tsk-83: Add None value for MusicTypes and CoverArtTypes (#87)
All checks were successful
Release Tagging / release (push) Successful in 33s
Rust Build / Check (push) Successful in 34s
Rust Build / Test Suite (push) Successful in 32s
Rust Build / Rustfmt (push) Successful in 32s
Rust Build / Clippy (push) Successful in 32s
Rust Build / build (push) Successful in 32s
Closes #83

Reviewed-on: #87
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-28 17:05:13 +00:00
0a27b8ccb1 filename generation fix (#82)
All checks were successful
Rust Build / Check (push) Successful in 31s
Release Tagging / release (push) Successful in 35s
Rust Build / Test Suite (push) Successful in 42s
Rust Build / Rustfmt (push) Successful in 25s
Rust Build / Clippy (push) Successful in 35s
Rust Build / build (push) Successful in 42s
Reviewed-on: #82
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-24 17:21:07 +00:00
afc4ca21a2 tsk-76: Improve getting path of Song or CoverArt (#81)
All checks were successful
Rust Build / Test Suite (push) Successful in 28s
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 43s
Rust Build / Rustfmt (push) Successful in 24s
Rust Build / build (push) Successful in 26s
Rust Build / Clippy (push) Successful in 35s
Closes #76

Reviewed-on: #81
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-24 16:51:08 +00:00
7 changed files with 51 additions and 27 deletions

2
Cargo.lock generated
View File

@@ -149,7 +149,7 @@ checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
[[package]]
name = "icarus_models"
version = "0.8.2"
version = "0.8.4"
dependencies = [
"josekit",
"rand",

View File

@@ -1,6 +1,6 @@
[package]
name = "icarus_models"
version = "0.8.2"
version = "0.8.4"
edition = "2024"
rust-version = "1.90"
description = "models used for the icarus project"

View File

@@ -1,2 +1,3 @@
A library containing commonly used models and functions that is used throughout
icarus projects. This reduces the amount of duplicated code without a benefit.
A library containing commonly used structs, functions, enums, constants and other code
that is used throughout the icarus projects. Code from this library serves as the model
for other projects in the icarus project.

View File

@@ -1,11 +1,10 @@
use std::io::Write;
use rand::Rng;
use serde::{Deserialize, Serialize};
const FILENAME_LENGTH: i32 = 16;
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct CoverArt {
pub id: uuid::Uuid,
pub title: String,
@@ -18,11 +17,9 @@ pub struct CoverArt {
}
pub mod init {
use super::CoverArt;
/// Initializes the CoverArt with just the directory and filename
pub fn init_coverart_dir_and_filename(directory: &str, filename: &str) -> CoverArt {
CoverArt {
pub fn init_coverart_dir_and_filename(directory: &str, filename: &str) -> super::CoverArt {
super::CoverArt {
directory: String::from(directory),
filename: String::from(filename),
..Default::default()
@@ -80,7 +77,7 @@ impl CoverArt {
let directory = &self.directory;
let last_index = directory.len() - 1;
match crate::util::concatenate_path(&directory, &self.filename, last_index) {
match crate::util::concatenate_path(directory, &self.filename, last_index) {
Ok(path) => Ok(path),
Err(err) => Err(err),
}
@@ -88,7 +85,10 @@ impl CoverArt {
}
/// Generates filename for a CoverArt
pub fn generate_filename(typ: crate::types::CoverArtTypes, randomize: bool) -> String {
pub fn generate_filename(
typ: crate::types::CoverArtTypes,
randomize: bool,
) -> Result<String, std::io::Error> {
let file_extension = match typ {
crate::types::CoverArtTypes::PngExtension => {
String::from(crate::constants::file_extensions::image::PNGEXTENSION)
@@ -99,10 +99,13 @@ pub fn generate_filename(typ: crate::types::CoverArtTypes, randomize: bool) -> S
crate::types::CoverArtTypes::JpgExtension => {
String::from(crate::constants::file_extensions::image::JPGEXTENSION)
}
crate::types::CoverArtTypes::None => {
return Err(std::io::Error::other("Unsupported CoverArtTypes"));
}
};
if randomize {
let mut filename: String = String::new();
let filename: String = if randomize {
let mut filename: String = String::from("coverart-");
let some_chars: String = String::from("abcdefghij0123456789");
let some_chars_length = some_chars.len();
let mut rng = rand::rng();
@@ -115,10 +118,12 @@ pub fn generate_filename(typ: crate::types::CoverArtTypes, randomize: bool) -> S
filename.push(c);
}
}
filename + &file_extension
format!("{filename}{file_extension}")
} else {
"track-output".to_string() + &file_extension
}
format!("coverart-output{file_extension}")
};
Ok(filename)
}
pub mod io {

View File

@@ -84,7 +84,7 @@ impl Song {
let directory = &self.directory;
let last_index = directory.len() - 1;
match crate::util::concatenate_path(&directory, &self.filename, last_index) {
match crate::util::concatenate_path(directory, &self.filename, last_index) {
Ok(path) => Ok(path),
Err(err) => Err(err),
}
@@ -126,7 +126,10 @@ impl Song {
}
/// Generates a filename. In order to save a song to the filesystem
pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
pub fn generate_filename(
typ: types::MusicTypes,
randomize: bool,
) -> Result<String, std::io::Error> {
let file_extension = match typ {
types::MusicTypes::DefaultMusicExtension => {
String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION)
@@ -140,25 +143,29 @@ pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
types::MusicTypes::MPThreeExtension => {
String::from(constants::file_extensions::audio::MPTHREEEXTENSION)
}
types::MusicTypes::None => return Err(std::io::Error::other("Unsupported MusicTypes")),
};
if randomize {
let mut filename: String = String::new();
let filename: String = if randomize {
let mut filename: String = String::from("track-");
let some_chars: String = String::from("abcdefghij0123456789");
let some_chars_length = some_chars.len();
let mut rng = rand::rng();
for _ in 0..FILENAME_LENGTH {
let index = rng.random_range(0..=19);
let index = rng.random_range(0..=some_chars_length);
let rando_char = some_chars.chars().nth(index);
if let Some(c) = rando_char {
filename.push(c);
}
}
filename + &file_extension
format!("{filename}{file_extension}")
} else {
"track-output".to_string() + &file_extension
}
format!("track-output{file_extension}")
};
Ok(filename)
}
/// I/O operations for songs

View File

@@ -4,6 +4,7 @@ pub enum MusicTypes {
WavExtension,
FlacExtension,
MPThreeExtension,
None,
}
#[derive(Debug)]
@@ -11,4 +12,5 @@ pub enum CoverArtTypes {
PngExtension,
JpegExtension,
JpgExtension,
None,
}

View File

@@ -107,12 +107,21 @@ mod song_tests {
};
assert_eq!(song.directory.is_empty(), false);
song_cpy.filename = song::generate_filename(types::MusicTypes::FlacExtension, true);
match song::generate_filename(types::MusicTypes::FlacExtension, true) {
Ok(filename) => {
song_cpy.filename = filename;
}
Err(err) => {
assert!(false, "Error generatig filename: {err:?}");
}
};
println!("Directory: {:?}", song_cpy.directory);
println!("File to be created: {:?}", song_cpy.filename);
match song::io::copy_song(&song, &mut song_cpy) {
Ok(_) => {}
Ok(_) => {
println!("Song copied");
}
Err(err) => {
assert!(false, "Error copying song: Error: {err:?}")
}