Extracted audio format detection from is_song()

This commit is contained in:
Antoine Gersant 2016-11-13 16:44:31 -08:00
parent 889c3251df
commit d9abb35e4d

View file

@ -1,23 +1,36 @@
use std::path::Path;
pub fn is_song(path: &Path) -> bool {
pub enum AudioFormat {
FLAC,
MP3,
MP4,
MPC,
OGG,
}
pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
let extension = match path.extension() {
Some(e) => e,
_ => return false,
_ => return None,
};
let extension = match extension.to_str() {
Some(e) => e,
_ => return false,
_ => return None,
};
match extension.to_lowercase().as_str() {
"mp3" => true,
"ogg" => true,
"m4a" => true,
"flac" => true,
_ => false,
"flac" => Some(AudioFormat::FLAC),
"mp3" => Some(AudioFormat::MP3),
"m4a" => Some(AudioFormat::MP4),
"mpc" => Some(AudioFormat::MPC),
"ogg" => Some(AudioFormat::OGG),
_ => None,
}
}
pub fn is_song(path: &Path) -> bool {
get_audio_format(path).is_some()
}
pub fn is_image(path: &Path) -> bool {
let extension = match path.extension() {
Some(e) => e,