musicutil/src/utils/mod.rs

39 lines
987 B
Rust
Raw Normal View History

2022-08-16 09:05:18 +01:00
use crate::types::File;
use std::path::PathBuf;
use walkdir::WalkDir;
pub mod ascii_reduce;
pub mod tag_extractor;
pub mod transcoder;
pub fn is_valid_file_extension(file_path: &PathBuf) -> bool {
let ext = file_path.extension().unwrap().to_str().unwrap().to_string();
if ext == "mp3" {
return true;
} else if ext == "flac" {
return true;
}
return false;
}
pub fn scan_for_music(src_dir: &String) -> Result<Vec<File>, Box<dyn std::error::Error>> {
let mut files: Vec<File> = Vec::new();
for entry in WalkDir::new(&src_dir) {
let entry = entry.unwrap();
let entry_path = entry.into_path();
if entry_path.is_dir() {
continue;
}
if is_valid_file_extension(&entry_path) {
let file = File::from_path(
src_dir.clone(),
entry_path.into_os_string().into_string().unwrap(),
);
files.push(file);
}
}
Ok(files)
}