diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs new file mode 100644 index 0000000..cdb5a99 --- /dev/null +++ b/src/detection/coverart.rs @@ -0,0 +1,20 @@ +/// Gets the file type of a CoverArt given it's path +pub fn file_type(filepath: &str) -> Result { + match imghdr::from_file(filepath) { + Ok(Some(imghdr::Type::Jpeg)) => { + Ok(String::from("jpeg")) + } + Ok(Some(imghdr::Type::Png)) => { + Ok(String::from("png")) + } + Ok(None) => { + Err(std::io::Error::other("Image file not supported")) + } + Err(err) => { + Err(err) + } + _ => { + Err(std::io::Error::other("Image file not supported")) + } + } +} diff --git a/src/detection/mod.rs b/src/detection/mod.rs new file mode 100644 index 0000000..165fc86 --- /dev/null +++ b/src/detection/mod.rs @@ -0,0 +1 @@ +pub mod coverart; diff --git a/src/lib.rs b/src/lib.rs index bbf790d..16f20a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +pub mod detection; pub mod meta; pub mod properties; pub mod types;