tsk-83: Add None value for MusicTypes and CoverArtTypes (#87)

Closes #83

Reviewed-on: #87
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-10-28 17:05:13 +00:00
committed by phoenix
parent 0a27b8ccb1
commit 432078e3c2
6 changed files with 42 additions and 20 deletions
+11 -5
View File
@@ -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,9 +143,10 @@ 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 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();
@@ -156,10 +160,12 @@ pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String {
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