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 mod constants {
|
||||||
pub const PNG_TYPE: &str = "png";
|
pub const PNG_TYPE: &str = "png";
|
||||||
pub const JPEG_TYPE: &str = "jpeg";
|
pub const JPEG_TYPE: &str = "jpeg";
|
||||||
pub const JPG_TYPE: &str = "jpg";
|
pub const JPG_TYPE: &str = "jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
@@ -36,7 +38,7 @@ mod tests {
|
|||||||
match super::file_type_from_filepath(&filepath) {
|
match super::file_type_from_filepath(&filepath) {
|
||||||
Ok(filetype) => {
|
Ok(filetype) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filetype, "png",
|
filetype, super::constants::PNG_TYPE,
|
||||||
"The file type of the CoverArt should have been png"
|
"The file type of the CoverArt should have been png"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -56,7 +58,7 @@ mod tests {
|
|||||||
match super::file_type_from_data(&data) {
|
match super::file_type_from_data(&data) {
|
||||||
Ok(filetype) => {
|
Ok(filetype) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filetype, "png",
|
filetype, super::constants::PNG_TYPE,
|
||||||
"The file type of the CoverArt should have been png"
|
"The file type of the CoverArt should have been png"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ pub mod coverart;
|
|||||||
pub mod song;
|
pub mod song;
|
||||||
|
|
||||||
pub struct FileType {
|
pub struct FileType {
|
||||||
pub mime: String
|
pub mime: String,
|
||||||
}
|
pub file_type: String,
|
||||||
|
|
||||||
pub enum FileTypeDef {
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
|
pub fn file_type_from_filepath(filepath: &str) -> Result<crate::detection::FileType, std::io::Error> {
|
||||||
|
|
||||||
pub fn file_type_from_filepath(filepath: &str) -> Result<String, std::io::Error> {
|
|
||||||
match infer::get_from_path(filepath) {
|
match infer::get_from_path(filepath) {
|
||||||
Ok(Some(kind)) => {
|
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) => {
|
Ok(None) => {
|
||||||
Err(std::io::Error::other("File type not determined"))
|
Err(std::io::Error::other("File type not determined"))
|
||||||
|
|||||||
Reference in New Issue
Block a user