126 lines
2.5 KiB
Rust
126 lines
2.5 KiB
Rust
mod flac;
|
|
use std::{collections::HashMap, sync::Arc};
|
|
|
|
pub use flac::*;
|
|
|
|
mod id3;
|
|
pub use id3::*;
|
|
|
|
mod fs;
|
|
pub use fs::*;
|
|
|
|
mod epub;
|
|
pub use epub::*;
|
|
|
|
mod exif;
|
|
pub use exif::*;
|
|
|
|
mod pdf;
|
|
pub use pdf::*;
|
|
|
|
mod json;
|
|
pub use json::*;
|
|
|
|
mod toml;
|
|
use pile_config::Label;
|
|
pub use toml::*;
|
|
|
|
mod group;
|
|
pub use group::*;
|
|
|
|
mod text;
|
|
pub use text::*;
|
|
|
|
mod image;
|
|
pub use image::*;
|
|
|
|
use crate::{
|
|
extract::{
|
|
misc::MapExtractor,
|
|
traits::{ExtractState, ObjectExtractor},
|
|
},
|
|
value::{Item, PileValue},
|
|
};
|
|
|
|
pub struct ItemExtractor {
|
|
inner: MapExtractor,
|
|
image: Arc<ImageExtractor>,
|
|
}
|
|
|
|
impl ItemExtractor {
|
|
#[expect(clippy::unwrap_used)]
|
|
pub fn new(item: &Item) -> Self {
|
|
let inner = MapExtractor {
|
|
inner: HashMap::from([
|
|
(
|
|
Label::new("flac").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(FlacExtractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("id3").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(Id3Extractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("fs").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(FsExtractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("epub").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(EpubExtractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("exif").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(ExifExtractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("pdf").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(PdfExtractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("json").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(JsonExtractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("toml").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(TomlExtractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("text").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(TextExtractor::new(item))),
|
|
),
|
|
(
|
|
Label::new("groups").unwrap(),
|
|
PileValue::ObjectExtractor(Arc::new(GroupExtractor::new(item))),
|
|
),
|
|
]),
|
|
};
|
|
|
|
Self {
|
|
inner,
|
|
image: Arc::new(ImageExtractor::new(item)),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[async_trait::async_trait]
|
|
impl ObjectExtractor for ItemExtractor {
|
|
async fn field(
|
|
&self,
|
|
state: &ExtractState,
|
|
name: &pile_config::Label,
|
|
args: Option<&str>,
|
|
) -> Result<Option<PileValue>, std::io::Error> {
|
|
if self.image.fields().await?.contains(name) {
|
|
self.image.field(state, name, args).await
|
|
} else {
|
|
self.inner.field(state, name, args).await
|
|
}
|
|
}
|
|
|
|
async fn fields(&self) -> Result<Vec<Label>, std::io::Error> {
|
|
let mut fields = self.inner.fields().await?;
|
|
fields.extend(self.image.fields().await?);
|
|
Ok(fields)
|
|
}
|
|
}
|