musicutil/src/utils/mod.rs

35 lines
848 B
Rust
Raw Normal View History

2022-08-16 09:05:18 +01:00
use crate::types::File;
2022-10-22 14:16:02 +01:00
use std::path::{Path};
2022-08-16 09:05:18 +01:00
use walkdir::WalkDir;
pub mod ascii_reduce;
pub mod tag_extractor;
pub mod transcoder;
2022-10-22 14:16:02 +01:00
pub fn is_valid_file_extension(file_path: &Path) -> bool {
let ext = file_path.extension().unwrap().to_str().unwrap();
matches!(ext, "mp3" | "flac")
2022-08-16 09:05:18 +01:00
}
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(),
2022-10-22 14:16:02 +01:00
entry_path,
2022-08-16 09:05:18 +01:00
);
files.push(file);
}
}
Ok(files)
}