add nerdicons and define metadata fields

This commit is contained in:
🪞👃🪞 2025-03-03 22:58:42 +02:00
parent 747abab922
commit c3f826a7d4
2 changed files with 54 additions and 25 deletions

View file

@ -41,16 +41,39 @@ struct Taggart {
editing: Option<(usize, usize)>,
show_hash: bool,
}
#[derive(Ord, Eq, PartialEq, PartialOrd, Default)]
#[derive(Default, Ord, Eq, PartialEq, PartialOrd)]
struct Entry {
path: PathBuf,
is_dir: bool,
is_mus: bool,
is_img: bool,
is_dir: Option<DirInfo>,
is_mus: Option<MusInfo>,
is_img: Option<ImgInfo>,
depth: usize,
hash: Option<String>,
file_type: Option<&'static FileType>,
}
#[derive(Default, Ord, Eq, PartialEq, PartialOrd)]
struct DirInfo {
hash_file: Option<()>,
catalog_file: Option<()>,
artist_file: Option<()>,
release_file: Option<()>,
}
#[derive(Default, Ord, Eq, PartialEq, PartialOrd)]
struct MusInfo {
artist: Option<String>,
release: Option<String>,
track: Option<usize>,
title: Option<String>,
date: Option<String>,
year: Option<String>,
people: Option<Vec<String>>,
publisher: Option<String>,
key: Option<String>,
}
#[derive(Default, Ord, Eq, PartialEq, PartialOrd)]
struct ImgInfo {
author: Option<String>,
}
fn main () -> Usually<()> {
let args = cli().get_matches();
@ -79,13 +102,8 @@ impl Taggart {
}
fn collect (root: &impl AsRef<Path>) -> Usually<Vec<Entry>> {
let mut paths = vec![];
for entry in WalkDir::new(&root)
.into_iter()
.filter_entry(|e|!e
.file_name()
.to_str()
.map(|s|s.starts_with("."))
.unwrap_or(false))
for entry in WalkDir::new(&root).into_iter()
.filter_entry(|e|!e.file_name().to_str().map(|s|s.starts_with(".")).unwrap_or(false))
{
let entry = entry?;
if entry.depth() == 0 {
@ -94,28 +112,28 @@ impl Taggart {
let depth = entry.depth();
let path = entry.into_path();
let (is_dir, is_mus, is_img, hash, file_type) = if path.is_dir() {
(true, false, false, None, None)
(Some(Default::default()), None, None, None, None)
} else {
let bytes = read(&path)?;
let hash = hex::encode(xxh3_64(&bytes).to_be_bytes());
let file_type = FileType::try_from_reader(&*bytes)?;
let mime_type = file_type.media_types().get(0);
let is_mus = match mime_type {
Some(&"audio/mpeg3") => true,
_ => false,
Some(&"audio/mpeg3") => Some(Default::default()),
_ => None,
};
let is_img = match mime_type {
Some(&"image/png") => true,
_ => false,
Some(&"image/png") => Some(Default::default()),
_ => None,
};
println!("{hash} {file_type:?} ({}b)\n{}\n", bytes.len(), path.display());
(false, is_mus, is_img, Some(hash), Some(file_type))
(None, is_mus, is_img, Some(hash), Some(file_type))
};
paths.push(Entry {
path: path.strip_prefix(&root)?.into(),
is_dir: path.is_dir(),
is_mus: false,
is_img: false,
path: path.strip_prefix(&root)?.into(),
is_dir,
is_mus,
is_img,
depth,
hash,
file_type