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; 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() { let extension = match path.extension() {
Some(e) => e, Some(e) => e,
_ => return false, _ => return None,
}; };
let extension = match extension.to_str() { let extension = match extension.to_str() {
Some(e) => e, Some(e) => e,
_ => return false, _ => return None,
}; };
match extension.to_lowercase().as_str() { match extension.to_lowercase().as_str() {
"mp3" => true, "flac" => Some(AudioFormat::FLAC),
"ogg" => true, "mp3" => Some(AudioFormat::MP3),
"m4a" => true, "m4a" => Some(AudioFormat::MP4),
"flac" => true, "mpc" => Some(AudioFormat::MPC),
_ => false, "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 { pub fn is_image(path: &Path) -> bool {
let extension = match path.extension() { let extension = match path.extension() {
Some(e) => e, Some(e) => e,