From 580d73eeb88490ab8c1bbada63e82a0a7580435f Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:19:37 -0400 Subject: [PATCH] tsk-44: Added detection module --- src/detection/coverart.rs | 20 ++++++++++++++++++++ src/detection/mod.rs | 1 + src/lib.rs | 1 + 3 files changed, 22 insertions(+) create mode 100644 src/detection/coverart.rs create mode 100644 src/detection/mod.rs 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;