tsk-45: Identify type of Song #48

Merged
phoenix merged 15 commits from tsk-45 into main 2025-10-22 02:26:19 +00:00
3 changed files with 16 additions and 10 deletions
Showing only changes of commit 250a009fad - Show all commits

View File

@@ -19,12 +19,14 @@ pub fn file_type_from_data(data: &Vec<u8>) -> Result<String, std::io::Error> {
}
}
pub mod constants {
pub const PNG_TYPE: &str = "png";
pub const JPEG_TYPE: &str = "jpeg";
pub const JPG_TYPE: &str = "jpg";
}
#[cfg(test)]
mod tests {
#[test]
@@ -36,7 +38,7 @@ mod tests {
match super::file_type_from_filepath(&filepath) {
Ok(filetype) => {
assert_eq!(
filetype, "png",
filetype, super::constants::PNG_TYPE,
"The file type of the CoverArt should have been png"
);
}
@@ -56,7 +58,7 @@ mod tests {
match super::file_type_from_data(&data) {
Ok(filetype) => {
assert_eq!(
filetype, "png",
filetype, super::constants::PNG_TYPE,
"The file type of the CoverArt should have been png"
);
}

View File

@@ -2,8 +2,6 @@ pub mod coverart;
pub mod song;
pub struct FileType {
pub mime: String
}
pub enum FileTypeDef {
pub mime: String,
pub file_type: String,
}

View File

@@ -1,9 +1,15 @@
pub fn file_type_from_filepath(filepath: &str) -> Result<String, std::io::Error> {
pub fn file_type_from_filepath(filepath: &str) -> Result<crate::detection::FileType, std::io::Error> {
match infer::get_from_path(filepath) {
Ok(Some(kind)) => {
Ok(String::new())
let mime = kind.mime_type();
if mime == "audio/x-flac" {
Ok(crate::detection::FileType {
mime: String::from(mime),
file_type: String::from(constants::FLAC_TYPE)
})
} else {
Err(std::io::Error::other("Unsupported file type"))
}
}
Ok(None) => {
Err(std::io::Error::other("File type not determined"))