2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 19:31:35 +00:00
pict-rs/src/discover.rs

46 lines
1.2 KiB
Rust
Raw Permalink Normal View History

mod exiftool;
mod ffmpeg;
mod magick;
2024-03-10 04:53:46 +00:00
use crate::{bytes_stream::BytesStream, formats::InputFile, future::WithPollTimer, state::State};
2023-07-13 19:34:40 +00:00
#[derive(Debug, PartialEq, Eq)]
pub(crate) struct Discovery {
pub(crate) input: InputFile,
pub(crate) width: u16,
pub(crate) height: u16,
pub(crate) frames: Option<u32>,
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum DiscoverError {
#[error("No frames in uploaded media")]
NoFrames,
#[error("Not all frames have same image format")]
FormatMismatch,
#[error("Input file type {0} is unsupported")]
UnsupportedFileType(String),
}
2023-12-16 04:34:45 +00:00
#[tracing::instrument(level = "trace", skip_all)]
2024-02-22 22:02:33 +00:00
pub(crate) async fn discover_bytes_stream<S>(
2024-02-04 00:18:13 +00:00
state: &State<S>,
2024-02-22 22:02:33 +00:00
bytes: BytesStream,
2023-08-05 17:41:06 +00:00
) -> Result<Discovery, crate::error::Error> {
2024-03-10 04:53:46 +00:00
let discovery = ffmpeg::discover_bytes_stream(state, bytes.clone())
.with_poll_timer("discover-ffmpeg")
.await?;
2024-03-10 04:53:46 +00:00
let discovery = magick::confirm_bytes_stream(state, discovery, bytes.clone())
.with_poll_timer("confirm-imagemagick")
.await?;
2024-03-10 04:53:46 +00:00
let discovery = exiftool::check_reorient(discovery, bytes, state.config.media.process_timeout)
.with_poll_timer("reorient-exiftool")
.await?;
Ok(discovery)
}