From d9abb35e4dc69683f9d379e7b489fb8a8913f876 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sun, 13 Nov 2016 16:44:31 -0800 Subject: [PATCH] Extracted audio format detection from is_song() --- src/utils.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index fbb281b..268ad96 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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 { 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,