make parsing mode configurable

This commit is contained in:
🪞👃🪞 2025-04-05 07:27:12 +03:00
parent 0bdca2da01
commit c55f50162d
2 changed files with 14 additions and 6 deletions

View file

@ -38,7 +38,7 @@ impl Entry {
Ok(Some(Self { Ok(Some(Self {
depth, depth,
path: path.to_path_buf().into(), path: path.to_path_buf().into(),
info: Arc::new(RwLock::new(Metadata::new(path)?)), info: Arc::new(RwLock::new(Metadata::new(path, false)?)),
})) }))
} }
pub fn is_directory (&self) -> bool { pub fn is_directory (&self) -> bool {

View file

@ -3,7 +3,12 @@ use std::fs::File;
use std::io::{BufReader, Read}; use std::io::{BufReader, Read};
use std::borrow::Borrow; use std::borrow::Borrow;
use byte_unit::{Byte, Unit::MB}; use byte_unit::{Byte, Unit::MB};
use lofty::{file::TaggedFileExt, probe::Probe, tag::{Accessor, Tag, TagItem, ItemKey, ItemValue}}; use lofty::{
probe::Probe,
file::TaggedFileExt,
config::{ParseOptions, ParsingMode},
tag::{Accessor, Tag, TagItem, ItemKey, ItemValue}
};
pub enum Metadata { pub enum Metadata {
Directory { Directory {
@ -33,10 +38,13 @@ pub enum Metadata {
} }
impl Metadata { impl Metadata {
pub fn new (path: &Path) -> Usually<Self> { pub fn new (path: &Path, strict: bool) -> Usually<Self> {
let reader = BufReader::new(File::open(path)?); let probe = Probe::new(BufReader::new(File::open(path)?))
let probe = Probe::new(reader) .options(ParseOptions::new().parsing_mode(if strict {
//.options(ParseOptions::new().parsing_mode(ParsingMode::Strict)) ParsingMode::Strict
} else {
ParsingMode::BestAttempt
}))
.guess_file_type()?; .guess_file_type()?;
if probe.file_type().is_some() { if probe.file_type().is_some() {
let file = lofty::read_from_path(path)?; let file = lofty::read_from_path(path)?;