diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index fc5cc39..e3d757b 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -19,12 +19,14 @@ pub fn file_type_from_data(data: &Vec) -> Result { } } + 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" ); } diff --git a/src/detection/mod.rs b/src/detection/mod.rs index b1ecbb7..df4b487 100644 --- a/src/detection/mod.rs +++ b/src/detection/mod.rs @@ -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, } diff --git a/src/detection/song.rs b/src/detection/song.rs index ed0099e..a6ca378 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -1,9 +1,15 @@ - - -pub fn file_type_from_filepath(filepath: &str) -> Result { +pub fn file_type_from_filepath(filepath: &str) -> Result { 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"))