This commit is contained in:
Antoine Gersant 2016-11-13 16:49:45 -08:00
parent f21e4e055f
commit 2150241ae1
8 changed files with 635 additions and 588 deletions

View file

@ -1,51 +1,51 @@
use std::path::Path;
pub enum AudioFormat {
FLAC,
MP3,
MP4,
MPC,
OGG,
FLAC,
MP3,
MP4,
MPC,
OGG,
}
pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
let extension = match path.extension() {
Some(e) => e,
_ => return None,
};
let extension = match extension.to_str() {
Some(e) => e,
_ => return None,
};
match extension.to_lowercase().as_str() {
"flac" => Some(AudioFormat::FLAC),
"mp3" => Some(AudioFormat::MP3),
"m4a" => Some(AudioFormat::MP4),
"mpc" => Some(AudioFormat::MPC),
"ogg" => Some(AudioFormat::OGG),
_ => None,
}
let extension = match path.extension() {
Some(e) => e,
_ => return None,
};
let extension = match extension.to_str() {
Some(e) => e,
_ => return None,
};
match extension.to_lowercase().as_str() {
"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()
get_audio_format(path).is_some()
}
pub fn is_image(path: &Path) -> bool {
let extension = match path.extension() {
Some(e) => e,
_ => return false,
};
let extension = match extension.to_str() {
Some(e) => e,
_ => return false,
};
match extension.to_lowercase().as_str() {
"png" => true,
"gif" => true,
"jpg" => true,
"jpeg" => true,
"bmp" => true,
_ => false,
}
}
let extension = match path.extension() {
Some(e) => e,
_ => return false,
};
let extension = match extension.to_str() {
Some(e) => e,
_ => return false,
};
match extension.to_lowercase().as_str() {
"png" => true,
"gif" => true,
"jpg" => true,
"jpeg" => true,
"bmp" => true,
_ => false,
}
}