Skip to main content

exiftool/
lib.rs

1#![allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
2//! # `ExifTool`
3//!
4//! A Rust wrapper library for Phil Harvey's `ExifTool` command-line application.
5//!
6//! This library allows you to interact with `ExifTool`, enabling reading and writing
7//! metadata tags for a wide variety of file types (images, videos, audio, documents).
8//!
9//! It maintains a long-running `ExifTool` process in stay-open mode for efficiency when
10//! processing multiple files or commands.
11//!
12//! ## Basic Usage
13//!
14//! ```no_run
15//! use exiftool::{ExifTool, ExifToolError};
16//! use std::path::Path;
17//!
18//! fn main() -> Result<(), ExifToolError> {
19//!     let exiftool = ExifTool::new()?; // Starts the background ExifTool process
20//!     let image_path = Path::new("path/to/your/image.jpg");
21//!
22//!     // Read a specific tag as a JSON Value
23//!     let author_value = exiftool.json_tag(image_path, "Author", &[])?;
24//!     if let Some(author) = author_value.as_str() {
25//!         println!("Author: {}", author);
26//!     }
27//!
28//!     // Read all metadata as a JSON Value (grouped by category)
29//!     let metadata_json = exiftool.json(image_path, &["-g1"])?;
30//!     println!("Metadata JSON: {}", metadata_json);
31//!
32//!     // Write a tag
33//!     exiftool.write_tag(image_path, "UserComment", "This is a test comment", &["-overwrite_original"])?;
34//!
35//!     // Read binary data (e.g., thumbnail)
36//!     let thumbnail_bytes = exiftool.read_tag_binary(image_path, "ThumbnailImage")?;
37//!     println!("Read {} bytes for thumbnail", thumbnail_bytes.len());
38//!
39//!     // Remember ExifTool process closes when `exiftool` variable goes out of scope (Drop).
40//!     Ok(())
41//! }
42//! ```
43//!
44//!
45//! ```no_run
46//! use exiftool::{ExifTool, ExifToolError};
47//! use std::path::Path;
48//! use serde::Deserialize;
49//!
50//! #[derive(Deserialize, Debug)]
51//! struct ImageMetadata {
52//!     #[serde(rename = "FileName")]
53//!     file_name: String,
54//!     #[serde(rename = "ImageWidth")]
55//!     width: u32,
56//!     #[serde(rename = "ImageHeight")]
57//!     height: u32,
58//! }
59//!
60//! fn main() -> Result<(), ExifToolError> {
61//!     let exiftool = ExifTool::new()?;
62//!     let image_path = Path::new("path/to/your/image.jpg");
63//!
64//!     // Read specific tags and deserialize into a struct
65//!     let partial_meta: ImageMetadata = exiftool.read_tags(
66//!         image_path,
67//!         &["FileName", "ImageWidth", "ImageHeight"],
68//!         &[]
69//!     )?;
70//!     println!("Partial Metadata: {:?}", partial_meta);
71//!
72//!     // Read all metadata (grouped) and deserialize
73//!     // Note: Requires a struct matching ExifTool's -g/-G output structure
74//!     // let full_meta: YourFullMetadataStruct = exiftool.read_metadata(image_path, &["-g1"])?;
75//!     // println!("Full Metadata: {:?}", full_meta);
76//!
77//!     // Read a single tag and deserialize
78//!     let author: String = exiftool.read_tag(image_path, "Author", &[])?;
79//!     println!("Author: {}", author);
80//!
81//!     Ok(())
82//! }
83//! ```
84
85// Public API
86mod error;
87mod exiftool;
88
89pub use error::ExifToolError;
90pub use exiftool::ExifTool;
91
92pub mod parse_fn;
93mod structs;
94pub use structs::g2;
95
96mod utils;