mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
read id3 tags
This commit is contained in:
parent
72bd6148d6
commit
b29511c23e
6 changed files with 251 additions and 272 deletions
121
src/main.rs
121
src/main.rs
|
|
@ -10,15 +10,14 @@ use tek_tui::tek_output::*;
|
|||
use tek_tui::tek_input::*;
|
||||
use crate::crossterm::event::{Event, KeyEvent, KeyCode, KeyModifiers, KeyEventState, KeyEventKind};
|
||||
|
||||
use clap::{arg, command, value_parser, ArgAction, Command};
|
||||
use clap::{arg, command, value_parser};
|
||||
use walkdir::WalkDir;
|
||||
use sha2::{Sha256, Digest};
|
||||
use xxhash_rust::xxh3::xxh3_64;
|
||||
use base64::prelude::*;
|
||||
use file_type::FileType;
|
||||
|
||||
mod keys;
|
||||
mod view;
|
||||
mod model; pub(crate) use self::model::*;
|
||||
|
||||
pub(crate) type Usually<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||
pub(crate) type Perhaps<T> = Usually<Option<T>>;
|
||||
|
|
@ -31,49 +30,6 @@ fn cli () -> clap::Command {
|
|||
command!()
|
||||
.arg(arg!([path] "Path to root directory").value_parser(value_parser!(PathBuf)))
|
||||
}
|
||||
struct Taggart {
|
||||
root: PathBuf,
|
||||
paths: Vec<Entry>,
|
||||
cursor: usize,
|
||||
offset: usize,
|
||||
column: usize,
|
||||
size: Measure<TuiOut>,
|
||||
editing: Option<(usize, usize)>,
|
||||
show_hash: bool,
|
||||
}
|
||||
#[derive(Default, Ord, Eq, PartialEq, PartialOrd)]
|
||||
struct Entry {
|
||||
path: PathBuf,
|
||||
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();
|
||||
|
|
@ -109,78 +65,11 @@ impl Taggart {
|
|||
if entry.depth() == 0 {
|
||||
continue
|
||||
}
|
||||
let depth = entry.depth();
|
||||
let path = entry.into_path();
|
||||
let short_path: PathBuf = path.strip_prefix(&root)?.into();
|
||||
let (is_dir, is_mus, is_img, hash, file_type) = if path.is_dir() {
|
||||
(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") => Some(Default::default()),
|
||||
_ => None,
|
||||
};
|
||||
let is_img = match mime_type {
|
||||
Some(&"image/png") => Some(Default::default()),
|
||||
_ => None,
|
||||
};
|
||||
println!("{hash} {:>10}b {}", bytes.len(), short_path.display());
|
||||
(None, is_mus, is_img, Some(hash), Some(file_type))
|
||||
};
|
||||
paths.push(Entry {
|
||||
path: short_path,
|
||||
is_dir,
|
||||
is_mus,
|
||||
is_img,
|
||||
depth,
|
||||
hash,
|
||||
file_type
|
||||
});
|
||||
if let Some(entry) = Entry::new(root, &entry)? {
|
||||
paths.push(entry);
|
||||
}
|
||||
}
|
||||
paths.sort();
|
||||
Ok(paths)
|
||||
}
|
||||
}
|
||||
|
||||
//pub enum Entry {
|
||||
//Dir {
|
||||
//path: PathBuf,
|
||||
//name: OsString,
|
||||
//entries: Vec<Box<FileTree>>,
|
||||
//},
|
||||
//File {
|
||||
//path: PathBuf,
|
||||
//name: OsString,
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl Entry {
|
||||
//fn new (path: &impl AsRef<Path>) -> Usually<Self> {
|
||||
//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))
|
||||
//{
|
||||
//let path = entry?.into_path().strip_prefix(&root)?.into();
|
||||
//paths.push(path);
|
||||
//}
|
||||
//paths.sort();
|
||||
//}
|
||||
//}
|
||||
|
||||
//struct FileTree {
|
||||
//path: PathBuf,
|
||||
//name: OsString,
|
||||
//entries: Vec<Box<FileTree>>,
|
||||
//}
|
||||
|
||||
//impl FileTree {
|
||||
|
||||
//}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue