use std::collections::HashSet; use std::path::PathBuf; use expanduser::expanduser; use walkdir::WalkDir; use crate::config::Config; pub fn load(config: &Config) -> HashSet { let root = expanduser(&config.music_root).ok().filter(|p| p.is_dir()); let Some(root_path) = root else { return HashSet::new(); }; let mut album_dirs: HashSet = HashSet::new(); for entry in WalkDir::new(&root_path) { let Ok(entry) = entry else { continue }; let path = entry.path(); if path.is_dir() { continue; }; let is_audio_file = path .extension() .and_then(|ext| ext.to_str()) .is_some_and(|ext| config.audio_exts.contains(&ext.to_lowercase())); if is_audio_file && let Some(parent) = path.parent() && parent != root_path { album_dirs.insert(parent.to_path_buf()); } } album_dirs .iter() .filter_map(|p| p.strip_prefix(&root_path).ok()?.to_str().map(String::from)) .collect() }