Extracted audio format detection from is_song()
This commit is contained in:
parent
889c3251df
commit
d9abb35e4d
1 changed files with 21 additions and 8 deletions
29
src/utils.rs
29
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<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,
|
||||
|
|
Loading…
Add table
Reference in a new issue