Tunal/crates/tunal-thumbs/src/lib.rs

55 lines
1.6 KiB
Rust

//! Thumbnails for images, SVG, embedded album art and video frames, stored in the shared
//! freedesktop thumbnail cache (`$XDG_CACHE_HOME/thumbnails`).
//!
//! [`Thumbnailer::request`] queues a file; the result comes back through a callback on a worker
//! thread as an [`Outcome`] holding the cache path of the PNG.
mod cache;
mod generate;
mod pool;
pub use cache::{cache_path, thumbnail_dir};
pub use generate::{VideoTime, ffmpeg_available};
pub use pool::{Config, Outcome, Priority, Request, Thumbnailer, Ticket};
/// The three cache sizes of the freedesktop spec (longest edge in pixels).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ThumbSize {
Normal,
Large,
XLarge,
}
impl ThumbSize {
pub fn pixels(self) -> u32 {
match self {
Self::Normal => 128,
Self::Large => 256,
Self::XLarge => 512,
}
}
pub(crate) fn dir_name(self) -> &'static str {
match self {
Self::Normal => "normal",
Self::Large => "large",
Self::XLarge => "x-large",
}
}
}
/// Why no thumbnail exists.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Skip {
/// The file type has no generator, or the tool it needs (ffmpeg) is missing, or the audio
/// file has no cover.
Unsupported,
/// A remote location while remote thumbnails are off.
Remote,
/// Larger than [`Config::max_file_size`].
TooLarge,
/// The file lies inside the thumbnail cache.
InCache,
/// An earlier attempt failed and the file is unchanged.
KnownFailure,
}