tsk-45: Identify type of Song #48
@@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user