Changes to how song filenames are generated (#63)
Some checks failed
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Check (pull_request) Successful in 38s
Release Tagging / release (pull_request) Successful in 48s
Rust Build / Rustfmt (pull_request) Failing after 33s
Rust Build / Clippy (pull_request) Successful in 34s
Rust Build / build (pull_request) Successful in 35s
Some checks failed
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Check (pull_request) Successful in 38s
Release Tagging / release (pull_request) Successful in 48s
Rust Build / Rustfmt (pull_request) Failing after 33s
Rust Build / Clippy (pull_request) Successful in 34s
Rust Build / build (pull_request) Successful in 35s
Reviewed-on: #63 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.6.0"
|
version = "0.6.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"josekit",
|
"josekit",
|
||||||
"rand",
|
"rand",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.6.0"
|
version = "0.6.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
description = "models used for the icarus project"
|
description = "models used for the icarus project"
|
||||||
|
83
src/song.rs
83
src/song.rs
@@ -7,6 +7,8 @@ use crate::constants;
|
|||||||
use crate::init;
|
use crate::init;
|
||||||
use crate::types;
|
use crate::types;
|
||||||
|
|
||||||
|
const FILENAME_LENGTH: i32 = 16;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
||||||
@@ -90,48 +92,6 @@ impl Song {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make this available as a function
|
|
||||||
pub fn generate_filename(&self, typ: types::MusicTypes, randomize: bool) -> String {
|
|
||||||
let mut filename: String = String::new();
|
|
||||||
let filename_len = 10;
|
|
||||||
|
|
||||||
let file_extension = match typ {
|
|
||||||
types::MusicTypes::DefaultMusicExtension => {
|
|
||||||
String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION)
|
|
||||||
}
|
|
||||||
|
|
||||||
types::MusicTypes::WavExtension => {
|
|
||||||
String::from(constants::file_extensions::audio::WAVEXTENSION)
|
|
||||||
}
|
|
||||||
types::MusicTypes::FlacExtension => {
|
|
||||||
String::from(constants::file_extensions::audio::FLACEXTENSION)
|
|
||||||
}
|
|
||||||
types::MusicTypes::MPThreeExtension => {
|
|
||||||
String::from(constants::file_extensions::audio::MPTHREEEXTENSION)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if randomize {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
filename += "track-output";
|
|
||||||
}
|
|
||||||
|
|
||||||
filename += &file_extension;
|
|
||||||
|
|
||||||
filename
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Saves the song to the filesystem using the song's data
|
/// Saves the song to the filesystem using the song's data
|
||||||
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> {
|
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> {
|
||||||
@@ -150,6 +110,45 @@ impl Song {
|
|||||||
// TODO: Add function to remove file from the filesystem
|
// TODO: Add function to remove file from the filesystem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Generates a filename. In order to save a song to the filesystem, the song must have
|
||||||
|
/// a directory and filename
|
||||||
|
pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
|
||||||
|
let file_extension = match typ {
|
||||||
|
types::MusicTypes::DefaultMusicExtension => {
|
||||||
|
String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION)
|
||||||
|
}
|
||||||
|
|
||||||
|
types::MusicTypes::WavExtension => {
|
||||||
|
String::from(constants::file_extensions::audio::WAVEXTENSION)
|
||||||
|
}
|
||||||
|
types::MusicTypes::FlacExtension => {
|
||||||
|
String::from(constants::file_extensions::audio::FLACEXTENSION)
|
||||||
|
}
|
||||||
|
types::MusicTypes::MPThreeExtension => {
|
||||||
|
String::from(constants::file_extensions::audio::MPTHREEEXTENSION)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if randomize {
|
||||||
|
let mut filename: String = String::new();
|
||||||
|
let some_chars: String = String::from("abcdefghij0123456789");
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
|
||||||
|
for _ in 0..FILENAME_LENGTH {
|
||||||
|
let index = rng.random_range(0..=19);
|
||||||
|
let rando_char = some_chars.chars().nth(index);
|
||||||
|
|
||||||
|
if let Some(c) = rando_char {
|
||||||
|
filename.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filename + &file_extension
|
||||||
|
} else {
|
||||||
|
"track-output".to_string() + &file_extension
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// I/O operations for songs
|
/// I/O operations for songs
|
||||||
pub mod io {
|
pub mod io {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
@@ -107,7 +107,7 @@ mod song_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(song.directory.is_empty(), false);
|
assert_eq!(song.directory.is_empty(), false);
|
||||||
song_cpy.filename = song.generate_filename(types::MusicTypes::FlacExtension, true);
|
song_cpy.filename = song::generate_filename(types::MusicTypes::FlacExtension, true);
|
||||||
println!("Directory: {:?}", song_cpy.directory);
|
println!("Directory: {:?}", song_cpy.directory);
|
||||||
println!("File to be created: {:?}", song_cpy.filename);
|
println!("File to be created: {:?}", song_cpy.filename);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user