Skip to main content

QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder<'et> { /* private fields */ }
Expand description

查询构建器

Implementations§

Source§

impl<'et> QueryBuilder<'et>

Source

pub fn include_unknown(self, yes: bool) -> Self

包含未知标签

Source

pub fn include_duplicates(self, yes: bool) -> Self

包含重复标签

Source

pub fn raw_values(self, yes: bool) -> Self

显示原始数值(而非格式化后的值)

Source

pub fn group_by_category(self, yes: bool) -> Self

按类别分组(-g1 选项)

Source

pub fn no_composite(self, yes: bool) -> Self

禁用复合标签生成

使用 -e 选项禁用复合标签(Composite tags)的生成。 复合标签是由 ExifTool 根据其他标签计算得出的派生标签。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 只读取原始标签,不生成复合标签
let metadata = exiftool.query("photo.jpg")
    .no_composite(true)
    .execute()?;
Source

pub fn extract_embedded(self, level: Option<u8>) -> Self

提取嵌入文件信息

使用 -ee 选项从文件中提取嵌入的文件信息。 例如从 RAW 文件中提取 JPEG 预览图的元数据。

§级别
  • None - 不提取嵌入文件(默认)
  • Some(1) - -ee 提取直接嵌入的文件
  • Some(2) - -ee2 提取所有层级的嵌入文件
  • Some(3+) - -ee3 及以上更深入的提取
§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 提取嵌入文件信息
let metadata = exiftool.query("photo.raw")
    .extract_embedded(Some(1))
    .execute()?;
Source

pub fn extension(self, ext: impl Into<String>) -> Self

设置文件扩展名过滤

使用 -ext 选项只处理指定扩展名的文件。 可以使用多次来指定多个扩展名。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 只处理 jpg 文件
let metadata = exiftool.query("/photos")
    .extension("jpg")
    .recursive(true)
    .execute()?;

// 处理多个扩展名
let metadata = exiftool.query("/photos")
    .extension("jpg")
    .extension("png")
    .extension("raw")
    .recursive(true)
    .execute()?;
Source

pub fn ignore(self, dir: impl Into<String>) -> Self

设置要忽略的目录

使用 -i 选项忽略指定的目录名称。 在递归处理时,匹配的目录将被跳过。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 忽略 .git 和 node_modules 目录
let metadata = exiftool.query("/project")
    .ignore(".git")
    .ignore("node_modules")
    .recursive(true)
    .execute()?;
Source

pub fn recursive(self, yes: bool) -> Self

递归处理子目录

使用 -r 选项递归处理目录中的所有文件。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 递归处理整个目录树
let metadata = exiftool.query("/photos")
    .recursive(true)
    .extension("jpg")
    .execute()?;
Source

pub fn progress( self, interval: Option<u32>, title: Option<impl Into<String>>, ) -> Self

启用进度显示

使用 -progress 选项在处理文件时显示进度信息。 可以指定间隔(每隔多少文件显示一次)和标题。

§参数
  • interval - 每隔多少文件显示一次进度(None 表示每个文件都显示)
  • title - 进度信息的标题(可选)
§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 每 10 个文件显示一次进度
let metadata = exiftool.query("/photos")
    .recursive(true)
    .progress(Some(10), Some("Processing"))
    .execute()?;
Source

pub fn tag(self, tag: impl Into<String>) -> Self

添加特定标签查询

Source

pub fn tags(self, tags: &[impl AsRef<str>]) -> Self

添加多个标签查询

Source

pub fn tag_id(self, tag: TagId) -> Self

添加特定标签查询(使用 TagId)

Source

pub fn exclude(self, tag: impl Into<String>) -> Self

排除特定标签

Source

pub fn excludes(self, tags: &[impl AsRef<str>]) -> Self

排除多个标签

Source

pub fn exclude_id(self, tag: TagId) -> Self

排除特定标签(使用 TagId)

Source

pub fn charset(self, charset: impl Into<String>) -> Self

使用特定编码

Source

pub fn lang(self, lang: impl Into<String>) -> Self

使用特定语言

Source

pub fn coord_format(self, format: impl Into<String>) -> Self

设置 GPS 坐标格式

使用 -c 选项设置 GPS 坐标的输出格式

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 使用小数度格式
let metadata = exiftool.query("photo.jpg")
    .coord_format("%.6f")
    .execute()?;

// 使用度分秒格式
let metadata = exiftool.query("photo.jpg")
    .coord_format("%d deg %d' %.2f\"")
    .execute()?;
Source

pub fn date_format(self, format: impl Into<String>) -> Self

设置日期/时间格式

使用 -d 选项设置日期/时间值的输出格式

§预设格式
  • "%Y:%m:%d %H:%M:%S" - 标准 EXIF 格式(默认)
  • "%Y-%m-%d" - ISO 日期格式
  • "%c" - 本地时间格式
  • "%F %T" - ISO 8601 格式
§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 使用 ISO 格式
let metadata = exiftool.query("photo.jpg")
    .date_format("%Y-%m-%d %H:%M:%S")
    .execute()?;
Source

pub fn arg(self, arg: impl Into<String>) -> Self

添加原始参数(高级用法)

Source

pub fn print_format(self, format: impl Into<String>) -> Self

设置自定义打印格式

使用 -p 选项按指定格式打印输出。 使用 $TAGNAME 语法引用标签值。

§格式语法
  • $TAGNAME - 插入标签值
  • $TAGNAME# - 插入原始数值(无格式化)
  • ${TAGNAME:FMT} - 使用指定格式
  • $$ - 插入 $ 字符
§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 自定义输出格式
let output = exiftool.query("photo.jpg")
    .print_format("$FileName: $DateTimeOriginal ($Make $Model)")
    .execute_text()?;

println!("{}", output);
Source

pub fn sort(self, yes: bool) -> Self

按字母顺序排序输出

使用 -sort 选项对标签进行字母排序

Source

pub fn separator(self, sep: impl Into<String>) -> Self

设置列表项分隔符

使用 -sep 选项设置列表项的分隔符字符串

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 使用逗号分隔列表项
let metadata = exiftool.query("photo.jpg")
    .separator(", ")
    .execute()?;
Source

pub fn fast(self, level: Option<u8>) -> Self

启用快速模式

使用 -fast 选项提高元数据提取速度。 这会跳过某些处理步骤,可能遗漏某些信息。

§级别
  • None - 不使用快速模式(默认)
  • Some(1) - -fast 基础快速模式
  • Some(2) - -fast2 更激进的快速模式
§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 使用快速模式处理大量文件
let metadata = exiftool.query("photo.jpg")
    .fast(Some(1))
    .execute()?;
Source

pub fn scan_for_xmp(self, yes: bool) -> Self

强制扫描 XMP 数据

使用 -scanForXMP 选项暴力扫描文件中的 XMP 数据

Source

pub fn api_option( self, opt: impl Into<String>, value: Option<impl Into<String>>, ) -> Self

设置 API 选项

使用 -api 选项设置 ExifTool API 选项。 常见选项包括:QuickTimeUTC, SystemTags, largefilesupport

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 启用 QuickTimeUTC
let metadata = exiftool.query("video.mp4")
    .api_option("QuickTimeUTC", None::<&str>)
    .execute()?;
Source

pub fn user_param( self, param: impl Into<String>, value: Option<impl Into<String>>, ) -> Self

设置用户参数

使用 -userParam 选项设置用户参数,可在配置文件中使用

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 设置自定义参数
let metadata = exiftool.query("photo.jpg")
    .user_param("MyParam", Some("value"))
    .execute()?;
Source

pub fn password(self, passwd: impl Into<String>) -> Self

设置密码

使用 -password 选项处理受密码保护的文件

§安全性警告

密码将以纯文本形式传递给 ExifTool 进程。 在多用户系统中使用时请注意安全性。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 读取受密码保护的 PDF
let metadata = exiftool.query("protected.pdf")
    .password("secret123")
    .execute()?;
Source

pub fn decimal(self, yes: bool) -> Self

十进制显示标签 ID

使用 -D 选项以十进制格式显示标签 ID 编号

Source

pub fn escape(self, format: EscapeFormat) -> Self

转义格式

使用 -E-ex-ec 选项转义标签值

Source

pub fn force_print(self, yes: bool) -> Self

强制打印

使用 -f 选项强制打印所有指定标签

Source

pub fn group_names(self, level: Option<u8>) -> Self

打印组名

使用 -G 选项打印每个标签的组名

Source

pub fn html_format(self, yes: bool) -> Self

HTML 格式

使用 -h 选项以 HTML 格式输出

Source

pub fn hex(self, yes: bool) -> Self

十六进制显示

使用 -H 选项以十六进制显示标签 ID

Source

pub fn long_format(self, yes: bool) -> Self

长格式输出

使用 -l 选项以长格式(2行)输出

Source

pub fn latin(self, yes: bool) -> Self

Latin1 编码

使用 -L 选项使用 Windows Latin1 编码

Source

pub fn short_format(self, level: Option<u8>) -> Self

短格式输出

使用 -s-S 选项以短格式输出

Source

pub fn tab_format(self, yes: bool) -> Self

Tab 分隔格式

使用 -t 选项以 Tab 分隔格式输出

Source

pub fn table_format(self, yes: bool) -> Self

表格格式

使用 -T 选项以表格格式输出

Source

pub fn text_out(self, ext: impl Into<String>) -> Self

文本输出到文件

使用 -w 选项将输出写入文件

Source

pub fn tag_out(self, format: impl Into<String>) -> Self

标签输出到文件

使用 -W 选项为每个标签创建输出文件

Source

pub fn tag_out_ext(self, ext: impl Into<String>) -> Self

标签输出扩展名过滤

使用 -Wext 选项指定 -W 输出的文件类型

Source

pub fn list_item(self, index: u32) -> Self

提取列表项

使用 -listItem 选项提取列表中的特定项

Source

pub fn file_order(self, tag: impl Into<String>, descending: bool) -> Self

文件处理顺序

使用 -fileOrder 选项设置文件处理顺序

Source

pub fn quiet(self, yes: bool) -> Self

静默模式

使用 -q 选项减少输出信息

Source

pub fn html_dump(self, offset: Option<u32>) -> Self

HTML二进制转储

使用 -htmlDump 选项生成HTML格式的二进制转储 可以指定可选的偏移量

Source

pub fn php_format(self, yes: bool) -> Self

PHP数组格式输出

使用 -php 选项导出为PHP数组格式

Source

pub fn plot_format(self, yes: bool) -> Self

SVG plot格式输出

使用 -plot 选项输出为SVG plot文件

Source

pub fn args_format(self, yes: bool) -> Self

格式化为exiftool参数

使用 -args 选项将元数据格式化为exiftool参数格式

Source

pub fn common_args(self, args: &[impl AsRef<str>]) -> Self

设置公共参数

使用 -common_args 选项定义在多个命令之间共享的参数

Source

pub fn echo( self, text: impl Into<String>, target: Option<impl Into<String>>, ) -> Self

输出文本到stdout或stderr

使用 -echo 选项在处理期间输出文本

  • text: 要输出的文本
  • target: 输出目标,None表示stdout,Some(“stderr”)表示stderr
Source

pub fn efile(self, filename: impl Into<String>) -> Self

保存错误文件名到文件

使用 -efile 选项将处理失败的文件名保存到指定文件

Source

pub fn execute(self) -> Result<Metadata>

执行查询

Source

pub fn execute_json(self) -> Result<Value>

执行查询并返回 JSON

Source

pub fn execute_as<T: DeserializeOwned>(self) -> Result<T>

执行查询并反序列化为自定义类型

Source

pub fn execute_text(self) -> Result<String>

执行查询并返回纯文本

当使用 -p (print_format) 选项时, 使用此方法获取纯文本输出而非 JSON

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

let output = exiftool.query("photo.jpg")
    .print_format("$FileName: $DateTimeOriginal")
    .execute_text()?;

println!("{}", output);

Auto Trait Implementations§

§

impl<'et> Freeze for QueryBuilder<'et>

§

impl<'et> RefUnwindSafe for QueryBuilder<'et>

§

impl<'et> Send for QueryBuilder<'et>

§

impl<'et> Sync for QueryBuilder<'et>

§

impl<'et> Unpin for QueryBuilder<'et>

§

impl<'et> UnsafeUnpin for QueryBuilder<'et>

§

impl<'et> UnwindSafe for QueryBuilder<'et>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more