use super::{Confidence, IdentifiedDap, Mount};
pub fn identify(mount: &Mount) -> Option<IdentifiedDap> {
let label_up = mount
.label
.as_deref()
.map(|l| l.to_uppercase())
.unwrap_or_default();
if matches!(label_up.as_str(), "FIIO M21" | "FIIO_M21" | "M21") {
return Some(hit(mount, "fiio-m21", Confidence::Exact));
}
if label_up == "FIIO M11"
|| label_up.starts_with("M11")
|| label_up.contains("M11 PLUS")
|| label_up.contains("M11PLUS")
|| label_up.contains("M11_PLUS")
|| label_up.contains("M11 PRO")
|| label_up.contains("M11S")
{
return Some(hit(mount, "generic", Confidence::Heuristic));
}
if matches!(label_up.as_str(), "AK SR35" | "AK_SR35" | "SR35") {
return Some(hit(mount, "ak-sr35", Confidence::Exact));
}
if matches!(
label_up.as_str(),
"HIBY R6" | "HIBY_R6" | "R6" | "HIBY R6 III"
) {
return Some(hit(mount, "hiby-r6", Confidence::Exact));
}
if label_up.contains("FIIO") {
return Some(hit(mount, "fiio-m21", Confidence::Heuristic));
}
if label_up.contains("ASTELL") || label_up.contains("A&K") || label_up.contains("AK") {
return Some(hit(mount, "ak-sr35", Confidence::Heuristic));
}
if label_up.contains("HIBY") {
return Some(hit(mount, "hiby-r6", Confidence::Heuristic));
}
if label_up.contains("SHANLING") || label_up.contains("IBASSO") || label_up.contains("CAYIN") {
return Some(hit(mount, "generic", Confidence::Heuristic));
}
let root = &mount.mount_point;
if root.join(".database_uuid").exists() {
return Some(hit(mount, "fiio-m21", Confidence::Heuristic));
}
if root.join("HiByMusic").exists() {
return Some(hit(mount, "hiby-r6", Confidence::Heuristic));
}
if root.join(".thumbnails").exists() {
return Some(hit(mount, "generic", Confidence::Heuristic));
}
let is_audio_fs = mount
.filesystem
.as_deref()
.map(|fs| matches!(fs, "EXFAT" | "FAT32" | "FAT" | "VFAT"))
.unwrap_or(false);
if is_audio_fs && (root.join("Music").exists() || root.join("MUSIC").exists()) {
return Some(hit(mount, "generic", Confidence::Fallback));
}
None
}
fn hit(mount: &Mount, dap_id: &str, confidence: Confidence) -> IdentifiedDap {
IdentifiedDap {
mount: mount.clone(),
dap_id: dap_id.to_owned(),
confidence,
}
}