mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
make parsing mode configurable
This commit is contained in:
parent
0bdca2da01
commit
c55f50162d
2 changed files with 14 additions and 6 deletions
|
|
@ -38,7 +38,7 @@ impl Entry {
|
|||
Ok(Some(Self {
|
||||
depth,
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@ use std::fs::File;
|
|||
use std::io::{BufReader, Read};
|
||||
use std::borrow::Borrow;
|
||||
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 {
|
||||
Directory {
|
||||
|
|
@ -33,10 +38,13 @@ pub enum Metadata {
|
|||
}
|
||||
|
||||
impl Metadata {
|
||||
pub fn new (path: &Path) -> Usually<Self> {
|
||||
let reader = BufReader::new(File::open(path)?);
|
||||
let probe = Probe::new(reader)
|
||||
//.options(ParseOptions::new().parsing_mode(ParsingMode::Strict))
|
||||
pub fn new (path: &Path, strict: bool) -> Usually<Self> {
|
||||
let probe = Probe::new(BufReader::new(File::open(path)?))
|
||||
.options(ParseOptions::new().parsing_mode(if strict {
|
||||
ParsingMode::Strict
|
||||
} else {
|
||||
ParsingMode::BestAttempt
|
||||
}))
|
||||
.guess_file_type()?;
|
||||
if probe.file_type().is_some() {
|
||||
let file = lofty::read_from_path(path)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue