| 1 |
#!/usr/bin/env perl |
| 2 |
#------------------------------------------------------------------------------ |
| 3 |
# File: exiftool |
| 4 |
# |
| 5 |
# Description: Read/write meta information |
| 6 |
# |
| 7 |
# Revisions: Nov. 12/03 - P. Harvey Created |
| 8 |
# (See html/history.html for revision history) |
| 9 |
#------------------------------------------------------------------------------ |
| 10 |
use strict; |
| 11 |
use warnings; |
| 12 |
require 5.004; |
| 13 |
|
| 14 |
my $version = '13.55'; |
| 15 |
|
| 16 |
$^W = 1; # enable global warnings |
| 17 |
|
| 18 |
# add our 'lib' directory to the include list BEFORE 'use Image::ExifTool' |
| 19 |
my $exePath; |
| 20 |
BEGIN { |
| 21 |
# (undocumented -xpath option added in 11.91, must come before other options) |
| 22 |
$exePath = @ARGV && lc($ARGV[0]) eq '-xpath' && shift() ? $^X : $0; |
| 23 |
# get exe directory |
| 24 |
my $exeDir = ($exePath =~ /(.*)[\\\/]/) ? $1 : '.'; |
| 25 |
my $incDir = ($0 =~ /(.*)[\\\/]/) ? "$1/lib" : './lib'; |
| 26 |
if (-l $0) { |
| 27 |
my $lnk = eval { readlink $0 }; |
| 28 |
if (defined $lnk) { |
| 29 |
my $lnkDir = ($lnk =~ /(.*)[\\\/]/) ? $1 : '.'; |
| 30 |
$exeDir = (($lnk =~ m(^/)) ? '' : $exeDir . '/') . $lnkDir; |
| 31 |
$incDir = "$exeDir/lib"; |
| 32 |
} |
| 33 |
} |
| 34 |
$Image::ExifTool::exeDir = $exeDir; # use our exeDir for loading config file |
| 35 |
# add lib directory at start of include path |
| 36 |
unshift @INC, $incDir; |
| 37 |
# load or disable config file if specified |
| 38 |
while (@ARGV and lc($ARGV[0]) eq '-config') { |
| 39 |
shift; |
| 40 |
push @Image::ExifTool::configFiles, shift; |
| 41 |
} |
| 42 |
} |
| 43 |
use Image::ExifTool qw{:Public}; |
| 44 |
|
| 45 |
# function prototypes |
| 46 |
sub SigInt(); |
| 47 |
sub SigCont(); |
| 48 |
sub Cleanup(); |
| 49 |
sub GetImageInfo($$); |
| 50 |
sub SetImageInfo($$$); |
| 51 |
sub DoHardLink($$$$$); |
| 52 |
sub CleanXML($); |
| 53 |
sub EncodeXML($); |
| 54 |
sub FormatXML($$$); |
| 55 |
sub EscapeJSON($;$); |
| 56 |
sub FormatJSON($$$;$); |
| 57 |
sub PrintCSV(;$); |
| 58 |
sub AddGroups($$$$); |
| 59 |
sub ConvertBinary($); |
| 60 |
sub IsEqual($$;$); |
| 61 |
sub Printable($); |
| 62 |
sub LengthUTF8($); |
| 63 |
sub Infile($;$); |
| 64 |
sub AddSetTagsFile($;$); |
| 65 |
sub Warning($$); |
| 66 |
sub DoSetFromFile($$$); |
| 67 |
sub CleanFilename($); |
| 68 |
sub HasWildcards($); |
| 69 |
sub SetWindowTitle($); |
| 70 |
sub ProcessFiles($;$); |
| 71 |
sub ScanDir($$;$); |
| 72 |
sub FindFileWindows($$); |
| 73 |
sub FileNotFound($); |
| 74 |
sub PreserveTime(); |
| 75 |
sub AbsPath($); |
| 76 |
sub MyConvertFileName($$); |
| 77 |
sub SuggestedExtension($$$); |
| 78 |
sub LoadPrintFormat($;$); |
| 79 |
sub FilenameSPrintf($;$@); |
| 80 |
sub NextUnusedFilename($;$); |
| 81 |
sub CreateDirectory($); |
| 82 |
sub OpenOutputFile($;@); |
| 83 |
sub AcceptFile($); |
| 84 |
sub SlurpFile($$); |
| 85 |
sub FilterArgfileLine($); |
| 86 |
sub ReadStayOpen($); |
| 87 |
sub Progress($$); |
| 88 |
sub PrintTagList($@); |
| 89 |
sub PrintErrors($$$); |
| 90 |
sub GetASCII($); |
| 91 |
|
| 92 |
$SIG{INT} = 'SigInt'; # do cleanup on Ctrl-C |
| 93 |
$SIG{CONT} = 'SigCont'; # (allows break-out of delays) |
| 94 |
END { |
| 95 |
Cleanup(); |
| 96 |
} |
| 97 |
|
| 98 |
# declare all static file-scope variables |
| 99 |
my @commonArgs; # arguments common to all commands |
| 100 |
my @condition; # conditional processing of files |
| 101 |
my @csvExclude; # list of tags excluded from CSV import |
| 102 |
my @csvFiles; # list of files when reading with CSV option (in ExifTool Charset) |
| 103 |
my @csvTags; # order of tags for first file with CSV option (lower case) |
| 104 |
my @delFiles; # list of files to delete |
| 105 |
my @dynamicFiles; # list of -tagsFromFile files with dynamic names and -TAG<=FMT pairs |
| 106 |
my (@echo3, @echo4);# stdout and stderr echo after processing is complete |
| 107 |
my @efile; # files for writing list of error/fail/same file names |
| 108 |
my @exclude; # list of excluded tags |
| 109 |
my @files; # list of files and directories to scan |
| 110 |
my @moreArgs; # more arguments to process after -stay_open -@ |
| 111 |
my @newValues; # list of new tag values to set |
| 112 |
my @requestTags; # tags to request (for -p or -if option arguments) |
| 113 |
my @srcFmt; # source file name format strings |
| 114 |
my @tags; # list of tags to extract |
| 115 |
my %altFile; # alternate files to extract information (keyed by lower-case family 8 group) |
| 116 |
my %appended; # list of files appended to |
| 117 |
my %countLink; # count hard and symbolic links made |
| 118 |
my %created; # list of files we created |
| 119 |
my %csvTags; # lookup for all found tags with CSV option (lower case keys) |
| 120 |
my %database; # lookup for database information based on file name (in ExifTool Charset) |
| 121 |
my %filterExt; # lookup for filtered extensions |
| 122 |
my %ignore; # directory names to ignore |
| 123 |
my %outComma; # flag that output text file needs a comma |
| 124 |
my %outTrailer; # trailer for output text file |
| 125 |
my %preserveTime; # preserved timestamps for files |
| 126 |
my %printFmt; # the contents of the print format file |
| 127 |
my %seqFileDir; # file sequence number in each directory |
| 128 |
my %setTags; # hash of list references for tags to set from files |
| 129 |
my %setTagsList; # list of other tag lists for multiple -tagsFromFile from the same file |
| 130 |
my %usedFileName; # lookup for file names we already used in TestName feature |
| 131 |
my %utf8FileName; # lookup for file names that are UTF-8 encoded |
| 132 |
my %warnedOnce; # lookup for once-only warnings |
| 133 |
my %wext; # -W extensions to write |
| 134 |
my %wroteHEAD; # list of output txt files to which we wrote HEAD |
| 135 |
my $allGroup; # show group name for all tags |
| 136 |
my $altEnc; # alternate character encoding if not UTF-8 |
| 137 |
my $argFormat; # use exiftool argument-format output |
| 138 |
my $binaryOutput; # flag for binary output (undef or 1, or 0 for binary XML/PHP) |
| 139 |
my $binaryStdout; # flag set if we output binary to stdout |
| 140 |
my $binSep; # separator used for list items in binary output |
| 141 |
my $binTerm; # terminator used for binary output |
| 142 |
my $comma; # flag set if we need a comma in JSON output |
| 143 |
my $count; # count of files scanned when reading or deleting originals |
| 144 |
my $countBad; # count of files with errors |
| 145 |
my $countBadCr; # count files not created due to errors |
| 146 |
my $countBadWr; # count write errors |
| 147 |
my $countCopyWr; # count of files copied without being changed |
| 148 |
my $countDir; # count of directories scanned |
| 149 |
my $countFailed; # count files that failed condition |
| 150 |
my $countGoodCr; # count files created OK |
| 151 |
my $countGoodWr; # count files written OK |
| 152 |
my $countNewDir; # count of directories created |
| 153 |
my $countSameWr; # count files written OK but not changed |
| 154 |
my $critical; # flag for critical operations (disable CTRL-C) |
| 155 |
my $csv; # flag for CSV option (set to "CSV", or maybe "JSON" when writing) |
| 156 |
my $csvDelim; # delimiter for CSV files |
| 157 |
my $dbAdd; # flag to add CSV/JSON information to existing lists |
| 158 |
my $dbSaveCount; # save counter for last CSV/JSON file loaded |
| 159 |
my $deleteOrig; # 0=restore original files, 1=delete originals, 2=delete w/o asking |
| 160 |
my $diff; # file name for comparing differences |
| 161 |
my $disableOutput; # flag to disable normal output |
| 162 |
my $doSetFileName; # flag set if FileName may be written |
| 163 |
my $doUnzip; # flag to extract info from .gz and .bz2 files |
| 164 |
my ($end,$endDir,%endDir); # flags to end processing |
| 165 |
my $escapeC; # C-style escape |
| 166 |
my $escapeHTML; # flag to escape printed values for html |
| 167 |
my $evalWarning; # warning from eval |
| 168 |
my $executeID; # -execute ID number |
| 169 |
my $failCondition; # flag to fail -if condition |
| 170 |
my $fastCondition; # flag for fast -if condition |
| 171 |
my $fileHeader; # header to print to output file (or console, once) |
| 172 |
my $fileTrailer; # trailer for output file |
| 173 |
my $filtered; # flag indicating file was filtered by name |
| 174 |
my $filterFlag; # file filter flag (0x01=deny extensions, 0x02=allow extensions, 0x04=add ext) |
| 175 |
my $fixLen; # flag to fix description lengths when writing alternate languages |
| 176 |
my $forcePrint; # string to use for missing tag values (undef to not print them) |
| 177 |
my $geoOnly; # flag to extract Geolocation tags only |
| 178 |
my $helped; # flag to avoid printing help if no tags specified |
| 179 |
my $html; # flag for html-formatted output (2=html dump) |
| 180 |
my $ignoreHidden; # flag to ignore hidden files |
| 181 |
my $interrupted; # flag set if CTRL-C is pressed during a critical process |
| 182 |
my $isBinary; # true if value is a SCALAR ref |
| 183 |
my $isWriting; # flag set if we are writing tags |
| 184 |
my $joinLists; # flag set to join list values into a single string |
| 185 |
my $json; # flag for JSON/PHP output format (1=JSON, 2=PHP) |
| 186 |
my $langOpt; # language option |
| 187 |
my $listDir; # treat a directory as a regular file |
| 188 |
my $listItem; # item number for extracting single item from a list |
| 189 |
my $listSep; # list item separator (', ' by default) |
| 190 |
my $mt; # main ExifTool object |
| 191 |
my $multiFile; # non-zero if we are scanning multiple files |
| 192 |
my $noBinary; # flag set to ignore binary tags |
| 193 |
my $outFormat; # -1=Canon format, 0=same-line, 1=tag names, 2=values only |
| 194 |
my $outOpt; # output file or directory name |
| 195 |
my $overwriteOrig; # flag to overwrite original file (1=overwrite, 2=in place) |
| 196 |
my $pause; # pause before returning |
| 197 |
my $plot; # flag for plot output format |
| 198 |
my $preserveTime; # flag to preserve times of updated files (2=preserve FileCreateDate only) |
| 199 |
my $progress; # flag to calculate total files to process (0=calculate but don't display) |
| 200 |
my $progressCount; # count of files processed |
| 201 |
my $progressIncr; # increment for progress counter |
| 202 |
my $progressMax; # total number of files to process |
| 203 |
my $progressNext; # next progress count to output |
| 204 |
my $progStr; # progress message string |
| 205 |
my $purge; # flag to purge memory |
| 206 |
my $quiet; # flag to disable printing of informational messages / warnings |
| 207 |
my $rafStdin; # File::RandomAccess for stdin (if necessary to rewind) |
| 208 |
my $recurse; # recurse into subdirectories (2=also hidden directories) |
| 209 |
my $rtnVal; # command return value (0=success) |
| 210 |
my $rtnValPrev; # previous command return value (0=success) |
| 211 |
my $saveCount; # count the number of times we will/did call SaveNewValues() |
| 212 |
my $scanWritable; # flag to process only writable file types |
| 213 |
my $sectHeader; # current section header for -p option |
| 214 |
my $sectTrailer; # section trailer for -p option |
| 215 |
my $seqFileDir; # sequential file number used for %-C |
| 216 |
my $seqFileNum; # sequential file number used for %C |
| 217 |
my $setCharset; # character set setting ('default' if not set and -csv -b used) |
| 218 |
my $showGroup; # number of group to show (may be zero or '') |
| 219 |
my $showTagID; # non-zero to show tag ID's |
| 220 |
my $stayOpenBuff='';# buffer for -stay_open file |
| 221 |
my $stayOpenFile; # name of the current -stay_open argfile |
| 222 |
my $structOpt; # output structured XMP information (JSON and XML output only) |
| 223 |
my $tabFormat; # non-zero for tab output format |
| 224 |
my $tagOut; # flag for separate text output file for each tag |
| 225 |
my $textOut; # extension for text output file (or undef for no output) |
| 226 |
my $textOut2; # complete file name for single text output file |
| 227 |
my $textOverwrite; # flag to overwrite existing text output file (2=append, 3=over+append) |
| 228 |
my $tmpFile; # temporary file to delete on exit |
| 229 |
my $tmpText; # temporary text file |
| 230 |
my $validFile; # flag indicating we processed a valid file |
| 231 |
my $verbose; # verbose setting |
| 232 |
my $vout; # verbose output file reference (\*STDOUT or \*STDERR by default) |
| 233 |
my $windowTitle; # title for console window |
| 234 |
my $xml; # flag for XML-formatted output |
| 235 |
|
| 236 |
# flag to keep the input -@ argfile open: |
| 237 |
# 0 = normal behaviour |
| 238 |
# 1 = received "-stay_open true" and waiting for argfile to keep open |
| 239 |
# 2 = currently reading from STAYOPEN argfile |
| 240 |
# 3 = waiting for -@ to switch to a new STAYOPEN argfile |
| 241 |
my $stayOpen = 0; |
| 242 |
|
| 243 |
my $rtnValApp = 0; # app return value (0=success) |
| 244 |
my $curTitle = ''; # current window title |
| 245 |
|
| 246 |
# lookup for O/S names which use CR/LF newlines |
| 247 |
my $isCRLF = { MSWin32 => 1, os2 => 1, dos => 1 }->{$^O}; |
| 248 |
|
| 249 |
# lookup for JSON characters that we escape specially |
| 250 |
my %jsonChar = ( '"'=>'"', '\\'=>'\\', "\t"=>'t', "\n"=>'n', "\r"=>'r' ); |
| 251 |
|
| 252 |
# lookup for C-style escape sequences |
| 253 |
my %escC = ( "\n" => '\n', "\r" => '\r', "\t" => '\t', '\\' => '\\\\'); |
| 254 |
my %unescC = ( a => "\a", b => "\b", f => "\f", n => "\n", r => "\r", |
| 255 |
t => "\t", 0 => "\0", '\\' => '\\' ); |
| 256 |
|
| 257 |
# options requiring additional arguments |
| 258 |
# (used only to skip over these arguments when reading -stay_open ARGFILE) |
| 259 |
# (arg is converted to lower case then tested again unless an entry was found with the same case) |
| 260 |
my %optArgs = ( |
| 261 |
'-tagsfromfile' => 1, '-addtagsfromfile' => 1, '-alltagsfromfile' => 1, |
| 262 |
'-@' => 1, |
| 263 |
'-api' => 1, |
| 264 |
'-c' => 1, '-coordformat' => 1, |
| 265 |
'-charset' => 0, # (optional arg; OK because arg cannot begin with "-") |
| 266 |
'-config' => 1, |
| 267 |
'-csvdelim' => 1, |
| 268 |
'-d' => 1, '-dateformat' => 1, |
| 269 |
'-D' => 0, # necessary to avoid matching lower-case equivalent |
| 270 |
'-diff' => 1, |
| 271 |
'-echo' => 1, '-echo#' => 1, |
| 272 |
'-efile' => 1, '-efile#' => 1, '-efile!' => 1, '-efile#!' => 1, |
| 273 |
'-ext' => 1, '--ext' => 1, '-ext+' => 1, '--ext+' => 1, |
| 274 |
'-extension' => 1, '--extension' => 1, '-extension+' => 1, '--extension+' => 1, |
| 275 |
'-fileorder' => 1, '-fileorder#' => 1, |
| 276 |
'-file#' => 1, |
| 277 |
'-geotag' => 1, |
| 278 |
'-globaltimeshift' => 1, |
| 279 |
'-i' => 1, '-ignore' => 1, |
| 280 |
'-if' => 1, '-if#' => 1, |
| 281 |
'-lang' => 0, # (optional arg; cannot begin with "-") |
| 282 |
'-listitem' => 1, |
| 283 |
'-o' => 1, '-out' => 1, |
| 284 |
'-p' => 1, '-printformat' => 1, '-p-' => 1, '-printformat-' => 1, |
| 285 |
'-P' => 0, |
| 286 |
'-password' => 1, |
| 287 |
'-require' => 1, |
| 288 |
'-sep' => 1, '-separator' => 1, |
| 289 |
'-srcfile' => 1, |
| 290 |
'-stay_open' => 1, |
| 291 |
'-use' => 1, |
| 292 |
'-userparam' => 1, |
| 293 |
'-w' => 1, '-w!' => 1, '-w+' => 1, '-w+!' => 1, '-w!+' => 1, |
| 294 |
'-textout' => 1, '-textout!' => 1, '-textout+' => 1, '-textout+!' => 1, '-textout!+' => 1, |
| 295 |
'-tagout' => 1, '-tagout!' => 1, '-tagout+' => 1, '-tagout+!' => 1, '-tagout!+' => 1, |
| 296 |
'-wext' => 1, |
| 297 |
'-wm' => 1, '-writemode' => 1, |
| 298 |
'-x' => 1, '-exclude' => 1, |
| 299 |
'-X' => 0, |
| 300 |
); |
| 301 |
|
| 302 |
# recommended packages and alternatives |
| 303 |
my @recommends = qw( |
| 304 |
Archive::Zip |
| 305 |
Compress::Zlib |
| 306 |
Digest::MD5 |
| 307 |
Digest::SHA |
| 308 |
IO::Compress::Bzip2 |
| 309 |
POSIX::strptime |
| 310 |
Time::Local |
| 311 |
Unicode::LineBreak |
| 312 |
File::StatX |
| 313 |
Compress::Raw::Lzma |
| 314 |
IO::Compress::RawDeflate |
| 315 |
IO::Uncompress::RawInflate |
| 316 |
IO::Compress::Brotli |
| 317 |
IO::Uncompress::Brotli |
| 318 |
Win32::API |
| 319 |
Win32::FindFile |
| 320 |
Win32API::File |
| 321 |
); |
| 322 |
my %altRecommends = ( |
| 323 |
'POSIX::strptime' => 'Time::Piece', # (can use Time::Piece instead of POSIX::strptime) |
| 324 |
); |
| 325 |
|
| 326 |
my %unescapeChar = ( 't'=>"\t", 'n'=>"\n", 'r'=>"\r" ); |
| 327 |
|
| 328 |
# special subroutines used in -if condition |
| 329 |
sub Image::ExifTool::EndDir() { return $endDir = 1 } |
| 330 |
sub Image::ExifTool::End() { return $end = 1 } |
| 331 |
|
| 332 |
# exit routine |
| 333 |
sub Exit { |
| 334 |
if ($pause) { |
| 335 |
if (eval { require Term::ReadKey }) { |
| 336 |
print STDERR "-- press any key --"; |
| 337 |
Term::ReadKey::ReadMode('cbreak'); |
| 338 |
Term::ReadKey::ReadKey(0); |
| 339 |
Term::ReadKey::ReadMode(0); |
| 340 |
print STDERR "\b \b" x 20; |
| 341 |
} else { |
| 342 |
print STDERR "-- press RETURN --\n"; |
| 343 |
<STDIN>; |
| 344 |
} |
| 345 |
} |
| 346 |
exit shift; |
| 347 |
} |
| 348 |
# my warning and error routines (NEVER say "die"!) |
| 349 |
sub Warn { |
| 350 |
if ($quiet < 2 or $_[0] =~ /^Error/) { |
| 351 |
my $oldWarn = $SIG{'__WARN__'}; |
| 352 |
delete $SIG{'__WARN__'}; |
| 353 |
warn(@_); |
| 354 |
$SIG{'__WARN__'} = $oldWarn if defined $oldWarn; |
| 355 |
} |
| 356 |
} |
| 357 |
sub Error { Warn @_; $rtnVal = 1; } |
| 358 |
sub WarnOnce($) { |
| 359 |
Warn(@_) and $warnedOnce{$_[0]} = 1 unless $warnedOnce{$_[0]}; |
| 360 |
} |
| 361 |
|
| 362 |
# define signal handlers and cleanup routine |
| 363 |
sub SigInt() { |
| 364 |
$critical and $interrupted = 1, return; |
| 365 |
Cleanup(); |
| 366 |
exit 1; |
| 367 |
} |
| 368 |
sub SigCont() { } |
| 369 |
sub Cleanup() { |
| 370 |
$mt->Unlink($tmpFile) if defined $tmpFile; |
| 371 |
$mt->Unlink($tmpText) if defined $tmpText; |
| 372 |
undef $tmpFile; |
| 373 |
undef $tmpText; |
| 374 |
PreserveTime() if %preserveTime; |
| 375 |
SetWindowTitle(''); |
| 376 |
} |
| 377 |
|
| 378 |
#------------------------------------------------------------------------------ |
| 379 |
# main script |
| 380 |
# |
| 381 |
|
| 382 |
# isolate arguments common to all commands |
| 383 |
if (grep /^-common_args$/i, @ARGV) { |
| 384 |
my (@newArgs, $common, $end); |
| 385 |
foreach (@ARGV) { |
| 386 |
if (/^-common_args$/i and not $end) { |
| 387 |
$common = 1; |
| 388 |
} elsif ($common) { |
| 389 |
push @commonArgs, $_; |
| 390 |
} else { |
| 391 |
$end = 1 if $_ eq '--'; |
| 392 |
push @newArgs, $_; |
| 393 |
} |
| 394 |
} |
| 395 |
@ARGV = @newArgs if $common; |
| 396 |
} |
| 397 |
|
| 398 |
#.............................................................................. |
| 399 |
# loop over sets of command-line arguments separated by "-execute" |
| 400 |
Command: for (;;) { |
| 401 |
|
| 402 |
if (@echo3) { |
| 403 |
my $str = join("\n", @echo3) . "\n"; |
| 404 |
$str =~ s/\$\{status\}/$rtnVal/ig; |
| 405 |
print STDOUT $str; |
| 406 |
} |
| 407 |
if (@echo4) { |
| 408 |
my $str = join("\n", @echo4) . "\n"; |
| 409 |
$str =~ s/\$\{status\}/$rtnVal/ig; |
| 410 |
print STDERR $str; |
| 411 |
} |
| 412 |
|
| 413 |
$rafStdin->Close() if $rafStdin; |
| 414 |
undef $rafStdin; |
| 415 |
|
| 416 |
# save our previous return codes |
| 417 |
$rtnValPrev = $rtnVal; |
| 418 |
$rtnValApp = $rtnVal if $rtnVal; |
| 419 |
|
| 420 |
# exit Command loop now if we are all done processing commands |
| 421 |
last unless @ARGV or not defined $rtnVal or $stayOpen >= 2 or @commonArgs; |
| 422 |
|
| 423 |
# attempt to restore text mode for STDOUT if necessary |
| 424 |
if ($binaryStdout) { |
| 425 |
binmode(STDOUT,':crlf') if $] >= 5.006 and $isCRLF; |
| 426 |
$binaryStdout = 0; |
| 427 |
} |
| 428 |
|
| 429 |
# flush console and print "{ready}" message if -stay_open is in effect |
| 430 |
if ($stayOpen >= 2) { |
| 431 |
if ($quiet and not defined $executeID) { |
| 432 |
# flush output if possible |
| 433 |
eval { require IO::Handle } and STDERR->flush(), STDOUT->flush(); |
| 434 |
} else { |
| 435 |
eval { require IO::Handle } and STDERR->flush(); |
| 436 |
my $id = defined $executeID ? $executeID : ''; |
| 437 |
my $save = $|; |
| 438 |
$| = 1; # turn on output autoflush for stdout |
| 439 |
print "{ready$id}\n"; |
| 440 |
$| = $save; # restore original autoflush setting |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
# initialize necessary static file-scope variables |
| 445 |
# (not done: @commonArgs, @moreArgs, $critical, $binaryStdout, $helped, |
| 446 |
# $interrupted, $mt, $pause, $rtnValApp, $rtnValPrev, $stayOpen, $stayOpenBuff, $stayOpenFile) |
| 447 |
undef @condition; |
| 448 |
undef @csvExclude; |
| 449 |
undef @csvFiles; |
| 450 |
undef @csvTags; |
| 451 |
undef @delFiles; |
| 452 |
undef @dynamicFiles; |
| 453 |
undef @echo3; |
| 454 |
undef @echo4; |
| 455 |
undef @efile; |
| 456 |
undef @exclude; |
| 457 |
undef @files; |
| 458 |
undef @newValues; |
| 459 |
undef @requestTags; |
| 460 |
undef @srcFmt; |
| 461 |
undef @tags; |
| 462 |
undef %altFile; |
| 463 |
undef %appended; |
| 464 |
undef %countLink; |
| 465 |
undef %created; |
| 466 |
undef %csvTags; |
| 467 |
undef %database; |
| 468 |
undef %endDir; |
| 469 |
undef %filterExt; |
| 470 |
undef %ignore; |
| 471 |
undef %outComma; |
| 472 |
undef %outTrailer; |
| 473 |
undef %preserveTime; |
| 474 |
undef %printFmt; |
| 475 |
undef %seqFileDir; |
| 476 |
undef %setTags; |
| 477 |
undef %setTagsList; |
| 478 |
undef %usedFileName; |
| 479 |
undef %utf8FileName; |
| 480 |
undef %warnedOnce; |
| 481 |
undef %wext; |
| 482 |
undef %wroteHEAD; |
| 483 |
undef $allGroup; |
| 484 |
undef $altEnc; |
| 485 |
undef $argFormat; |
| 486 |
undef $binaryOutput; |
| 487 |
undef $binSep; |
| 488 |
undef $binTerm; |
| 489 |
undef $comma; |
| 490 |
undef $csv; |
| 491 |
undef $dbAdd; |
| 492 |
undef $deleteOrig; |
| 493 |
undef $diff; |
| 494 |
undef $disableOutput; |
| 495 |
undef $doSetFileName; |
| 496 |
undef $doUnzip; |
| 497 |
undef $end; |
| 498 |
undef $endDir; |
| 499 |
undef $escapeC; |
| 500 |
undef $escapeHTML; |
| 501 |
undef $evalWarning; |
| 502 |
undef $executeID; |
| 503 |
undef $failCondition; |
| 504 |
undef $fastCondition; |
| 505 |
undef $fileHeader; |
| 506 |
undef $filtered; |
| 507 |
undef $fixLen; |
| 508 |
undef $forcePrint; |
| 509 |
undef $geoOnly; |
| 510 |
undef $ignoreHidden; |
| 511 |
undef $isBinary; |
| 512 |
undef $joinLists; |
| 513 |
undef $langOpt; |
| 514 |
undef $listDir; |
| 515 |
undef $listItem; |
| 516 |
undef $multiFile; |
| 517 |
undef $noBinary; |
| 518 |
undef $outOpt; |
| 519 |
undef $plot; |
| 520 |
undef $preserveTime; |
| 521 |
undef $progress; |
| 522 |
undef $progressCount; |
| 523 |
undef $progressIncr; |
| 524 |
undef $progressMax; |
| 525 |
undef $progressNext; |
| 526 |
undef $purge; |
| 527 |
undef $rafStdin; |
| 528 |
undef $recurse; |
| 529 |
undef $scanWritable; |
| 530 |
undef $sectHeader; |
| 531 |
undef $setCharset; |
| 532 |
undef $showGroup; |
| 533 |
undef $showTagID; |
| 534 |
undef $structOpt; |
| 535 |
undef $tagOut; |
| 536 |
undef $textOut; |
| 537 |
undef $textOut2; |
| 538 |
undef $textOverwrite; |
| 539 |
undef $tmpFile; |
| 540 |
undef $tmpText; |
| 541 |
undef $validFile; |
| 542 |
undef $verbose; |
| 543 |
undef $windowTitle; |
| 544 |
|
| 545 |
$count = 0; |
| 546 |
$countBad = 0; |
| 547 |
$countBadCr = 0; |
| 548 |
$countBadWr = 0; |
| 549 |
$countCopyWr = 0; |
| 550 |
$countDir = 0; |
| 551 |
$countFailed = 0; |
| 552 |
$countGoodCr = 0; |
| 553 |
$countGoodWr = 0; |
| 554 |
$countNewDir = 0; |
| 555 |
$countSameWr = 0; |
| 556 |
$csvDelim = ','; |
| 557 |
$dbSaveCount = 0; |
| 558 |
$fileTrailer = ''; |
| 559 |
$filterFlag = 0; |
| 560 |
$html = 0; |
| 561 |
$isWriting = 0; |
| 562 |
$json = 0; |
| 563 |
$listSep = ', '; |
| 564 |
$outFormat = 0; |
| 565 |
$overwriteOrig = 0; |
| 566 |
$progStr = ''; |
| 567 |
$quiet = 0; |
| 568 |
$rtnVal = 0; |
| 569 |
$saveCount = 0; |
| 570 |
$sectTrailer = ''; |
| 571 |
$seqFileDir = 0; |
| 572 |
$seqFileNum = 0; |
| 573 |
$tabFormat = 0; |
| 574 |
$vout = \*STDOUT; |
| 575 |
$xml = 0; |
| 576 |
|
| 577 |
# define local variables used only in this command loop |
| 578 |
my @fileOrder; # tags to use for ordering of input files |
| 579 |
my $fileOrderFast; # -fast level for -fileOrder option |
| 580 |
my $addGeotime; # automatically added geotime argument |
| 581 |
my $doGlob; # flag set to do filename wildcard expansion |
| 582 |
my $endOfOpts; # flag set if "--" option encountered |
| 583 |
my $escapeXML; # flag to escape printed values for xml |
| 584 |
my $setTagsFile; # filename for last TagsFromFile option |
| 585 |
my $sortOpt; # sort option is used |
| 586 |
my $srcStdin; # one of the source files is STDIN |
| 587 |
my $tagsFrom = ''; # tags on command line come from 'CSV' or 'File' |
| 588 |
my $useMWG; # flag set if we are using any MWG tag |
| 589 |
|
| 590 |
my ($argsLeft, @nextPass, $badCmd); |
| 591 |
my $pass = 0; |
| 592 |
|
| 593 |
# for Windows, use globbing for wildcard expansion if available - MK/20061010 |
| 594 |
if ($^O eq 'MSWin32' and eval { require File::Glob }) { |
| 595 |
# override the core glob forcing case insensitivity |
| 596 |
import File::Glob qw(:globally :nocase); |
| 597 |
$doGlob = 1; |
| 598 |
} |
| 599 |
|
| 600 |
$mt = Image::ExifTool->new; # create ExifTool object |
| 601 |
|
| 602 |
# don't extract duplicates by default unless set by UserDefined::Options |
| 603 |
$mt->Options(Duplicates => 0) unless %Image::ExifTool::UserDefined::Options |
| 604 |
and defined $Image::ExifTool::UserDefined::Options{Duplicates}; |
| 605 |
|
| 606 |
# default is to join lists if the List option was set to zero in the config file |
| 607 |
$joinLists = 1 if defined $mt->Options('List') and not $mt->Options('List'); |
| 608 |
|
| 609 |
# preserve FileCreateDate if possible |
| 610 |
if (not $preserveTime and $^O eq 'MSWin32') { |
| 611 |
$preserveTime = 2 if eval { require Win32::API } and eval { require Win32API::File }; |
| 612 |
} |
| 613 |
|
| 614 |
# add user-defined command-line arguments |
| 615 |
if (@Image::ExifTool::UserDefined::Arguments) { |
| 616 |
unshift @ARGV, @Image::ExifTool::UserDefined::Arguments; |
| 617 |
} |
| 618 |
|
| 619 |
if ($version ne $Image::ExifTool::VERSION) { |
| 620 |
Warn "Application version $version does not match Image::ExifTool library version $Image::ExifTool::VERSION\n"; |
| 621 |
} |
| 622 |
|
| 623 |
# parse command-line options in 2 passes... |
| 624 |
# pass 1: set all of our ExifTool options |
| 625 |
# pass 2: print all of our help and informational output (-list, -ver, etc) |
| 626 |
for (;;) { |
| 627 |
|
| 628 |
# execute the command now if no more arguments or -execute is used |
| 629 |
if (not @ARGV or ($ARGV[0] =~ /^(-|\xe2\x88\x92)execute(\d+)?$/i and not $endOfOpts)) { |
| 630 |
if (@ARGV) { |
| 631 |
$executeID = $2; # save -execute number for "{ready}" response |
| 632 |
$helped = 1; # don't show help if we used -execute |
| 633 |
$badCmd and shift, $rtnVal=1, next Command; |
| 634 |
} elsif ($stayOpen >= 2) { |
| 635 |
ReadStayOpen(\@ARGV); # read more arguments from -stay_open file |
| 636 |
next; |
| 637 |
} elsif ($badCmd) { |
| 638 |
undef @commonArgs; # all done. Flush common arguments |
| 639 |
$rtnVal = 1; |
| 640 |
next Command; |
| 641 |
} |
| 642 |
if ($pass == 0) { |
| 643 |
# insert common arguments now if not done already |
| 644 |
if (@commonArgs and not defined $argsLeft) { |
| 645 |
# count the number of arguments remaining for subsequent commands |
| 646 |
$argsLeft = scalar(@ARGV) + scalar(@moreArgs); |
| 647 |
unshift @ARGV, @commonArgs; |
| 648 |
# all done with commonArgs if this is the end of the command |
| 649 |
undef @commonArgs unless $argsLeft; |
| 650 |
next; |
| 651 |
} |
| 652 |
# check if we have more arguments now than we did before we processed |
| 653 |
# the common arguments. If so, then we have an infinite processing loop |
| 654 |
if (defined $argsLeft and $argsLeft < scalar(@ARGV) + scalar(@moreArgs)) { |
| 655 |
Warn "Ignoring -common_args from $ARGV[0] onwards to avoid infinite recursion\n"; |
| 656 |
while ($argsLeft < scalar(@ARGV) + scalar(@moreArgs)) { |
| 657 |
@ARGV and shift(@ARGV), next; |
| 658 |
shift @moreArgs; |
| 659 |
} |
| 660 |
} |
| 661 |
# require MWG module if used in any argument |
| 662 |
# (note: doesn't cover the -p option because these tags will be parsed on the 2nd pass) |
| 663 |
$useMWG = 1 if not $useMWG and grep /^([--_0-9A-Z]+:)*1?mwg:/i, @tags, @requestTags; |
| 664 |
if ($useMWG) { |
| 665 |
require Image::ExifTool::MWG; |
| 666 |
Image::ExifTool::MWG::Load(); |
| 667 |
} |
| 668 |
# update necessary variables for 2nd pass |
| 669 |
if (defined $forcePrint) { |
| 670 |
unless (defined $mt->Options('MissingTagValue')) { |
| 671 |
$mt->Options(MissingTagValue => '-'); |
| 672 |
} |
| 673 |
$forcePrint = $mt->Options('MissingTagValue'); |
| 674 |
} |
| 675 |
} |
| 676 |
if (@nextPass) { |
| 677 |
# process arguments which were deferred to the next pass |
| 678 |
unshift @ARGV, @nextPass; |
| 679 |
undef @nextPass; |
| 680 |
undef $endOfOpts; |
| 681 |
++$pass; |
| 682 |
next; |
| 683 |
} |
| 684 |
@ARGV and shift; # remove -execute from argument list |
| 685 |
last; # process the command now |
| 686 |
} |
| 687 |
$_ = shift; |
| 688 |
next if $badCmd; # flush remaining arguments if aborting this command |
| 689 |
|
| 690 |
# allow funny dashes (nroff dash bug for cut-n-paste from pod) |
| 691 |
if (not $endOfOpts and s/^(-|\xe2\x88\x92)//) { |
| 692 |
s/^\xe2\x88\x92/-/; # translate double-dash too |
| 693 |
if ($_ eq '-') { |
| 694 |
$pass or push @nextPass, '--'; |
| 695 |
$endOfOpts = 1; |
| 696 |
next; |
| 697 |
} |
| 698 |
my $a = lc $_; |
| 699 |
if (/^list([wfrdx]|wf|g(\d*)|geo)?$/i) { |
| 700 |
$pass or push @nextPass, "-$_"; |
| 701 |
my $type = lc($1 || ''); |
| 702 |
if (not $type or $type eq 'w' or $type eq 'x') { |
| 703 |
my $group; |
| 704 |
if ($ARGV[0] and $ARGV[0] =~ /^(-|\xe2\x88\x92)(.+):(all|\*)$/i) { |
| 705 |
if ($pass == 0) { |
| 706 |
$useMWG = 1 if lc($2) eq 'mwg'; |
| 707 |
push @nextPass, shift; |
| 708 |
next; |
| 709 |
} |
| 710 |
$group = $2; |
| 711 |
shift; |
| 712 |
$group =~ /IFD/i and Warn("Can't list tags for specific IFD\n"), $helped=1, next; |
| 713 |
$group =~ /^(all|\*)$/ and undef $group; |
| 714 |
} else { |
| 715 |
$pass or next; |
| 716 |
} |
| 717 |
$helped = 1; |
| 718 |
if ($type eq 'x') { |
| 719 |
require Image::ExifTool::TagInfoXML; |
| 720 |
my %opts; |
| 721 |
$opts{Flags} = 1 if defined $forcePrint; |
| 722 |
$opts{NoDesc} = 1 if $outFormat > 0; |
| 723 |
$opts{Lang} = $langOpt; |
| 724 |
Image::ExifTool::TagInfoXML::Write(undef, $group, %opts); |
| 725 |
next; |
| 726 |
} |
| 727 |
my $wr = ($type eq 'w'); |
| 728 |
my $msg = ($wr ? 'Writable' : 'Available') . ($group ? " $group" : '') . ' tags'; |
| 729 |
PrintTagList($msg, $wr ? GetWritableTags($group) : GetAllTags($group)); |
| 730 |
# also print shortcuts if listing all tags |
| 731 |
next if $group or $wr; |
| 732 |
my @tagList = GetShortcuts(); |
| 733 |
PrintTagList('Command-line shortcuts', @tagList) if @tagList; |
| 734 |
next; |
| 735 |
} |
| 736 |
$pass or next; |
| 737 |
$helped = 1; |
| 738 |
if ($type eq 'wf') { |
| 739 |
my @wf; |
| 740 |
CanWrite($_) and push @wf, $_ foreach GetFileType(); |
| 741 |
PrintTagList('Writable file extensions', @wf); |
| 742 |
} elsif ($type eq 'f') { |
| 743 |
PrintTagList('Supported file extensions', GetFileType()); |
| 744 |
} elsif ($type eq 'r') { |
| 745 |
PrintTagList('Recognized file extensions', GetFileType(undef, 0)); |
| 746 |
} elsif ($type eq 'd') { |
| 747 |
PrintTagList('Deletable groups', GetDeleteGroups()); |
| 748 |
} elsif ($type eq 'geo') { |
| 749 |
require Image::ExifTool::Geolocation; |
| 750 |
my ($i, $entry); |
| 751 |
print "Geolocation database:\n" unless $quiet; |
| 752 |
my $isAlt = $mt->Options('GeolocAltNames') ? ',AltNames' : ''; |
| 753 |
$isAlt = '' if $isAlt and not Image::ExifTool::Geolocation::ReadAltNames(); |
| 754 |
print "City,Region,Subregion,CountryCode,Country,TimeZone,FeatureCode,Population,Latitude,Longitude$isAlt\n"; |
| 755 |
Image::ExifTool::Geolocation::SortDatabase('City') if $sortOpt; |
| 756 |
my $minPop = $mt->Options('GeolocMinPop'); |
| 757 |
my $feature = $mt->Options('GeolocFeature') || ''; |
| 758 |
my $neg = $feature =~ s/^-//; |
| 759 |
my %fcodes = map { lc($_) => 1 } split /\s*,\s*/, $feature; |
| 760 |
my @isUTF8 = (0,1,2,4); # items that need converting from UTF8 |
| 761 |
push @isUTF8, 10 if $isAlt; |
| 762 |
for ($i=0; ; ++$i) { |
| 763 |
my @entry = Image::ExifTool::Geolocation::GetEntry($i,$langOpt,1) or last; |
| 764 |
$#entry = 9; # remove everything after latitude (eg. feature type) |
| 765 |
next if $minPop and $entry[7] < $minPop; |
| 766 |
next if %fcodes and $neg ? $fcodes{lc $entry[6]} : not $fcodes{lc $entry[6]}; |
| 767 |
push @entry, Image::ExifTool::Geolocation::GetAltNames($i,1) if $isAlt; |
| 768 |
$_ = defined $_ ? $mt->Decode($_, 'UTF8') : '' foreach @entry[@isUTF8]; |
| 769 |
pop @entry if $isAlt and not $entry[10]; |
| 770 |
print join(',', @entry), "\n"; |
| 771 |
} |
| 772 |
} else { # 'g(\d*)' |
| 773 |
# list all groups in specified family |
| 774 |
my $family = $2 || 0; |
| 775 |
PrintTagList("Groups in family $family", $mt->GetAllGroups($family)); |
| 776 |
} |
| 777 |
next; |
| 778 |
} |
| 779 |
if ($a eq 'ver') { |
| 780 |
$pass or push(@nextPass,'-ver'), next; |
| 781 |
my $libVer = $Image::ExifTool::VERSION; |
| 782 |
my $str = $libVer eq $version ? '' : " [Warning: Library version is $libVer]"; |
| 783 |
if ($verbose) { |
| 784 |
print "ExifTool version $version$str$Image::ExifTool::RELEASE\n"; |
| 785 |
printf "Perl version %s%s\n", $], (defined ${^UNICODE} ? " (-C${^UNICODE})" : ''); |
| 786 |
print "Platform: $^O\n"; |
| 787 |
if ($verbose > 8) { |
| 788 |
print "Current Dir: " . Cwd::getcwd() . "\n" if (eval { require Cwd }); |
| 789 |
print "Script Name: $0\n"; |
| 790 |
print "Exe Name: $^X\n"; |
| 791 |
print "Exe Dir: $Image::ExifTool::exeDir\n"; |
| 792 |
print "Exe Path: $exePath\n"; |
| 793 |
} |
| 794 |
print "Optional libraries:\n"; |
| 795 |
foreach (@recommends) { |
| 796 |
next if /^Win32/ and $^O ne 'MSWin32'; |
| 797 |
next if /StatX/ and $^O ne 'linux'; |
| 798 |
my $ver = eval "require $_ and \$${_}::VERSION"; |
| 799 |
my $alt = $altRecommends{$_}; |
| 800 |
# check for alternative if primary not available |
| 801 |
$ver = eval "require $alt and \$${alt}::VERSION" and $_ = $alt if not $ver and $alt; |
| 802 |
printf " %-28s %s\n", $_, $ver || '(not installed)'; |
| 803 |
} |
| 804 |
if ($verbose > 1) { |
| 805 |
print "Include directories:\n"; |
| 806 |
ref $_ or print " $_\n" foreach @INC; |
| 807 |
} |
| 808 |
} else { |
| 809 |
print "$version$str$Image::ExifTool::RELEASE\n"; |
| 810 |
} |
| 811 |
$helped = 1; |
| 812 |
next; |
| 813 |
} |
| 814 |
if (/^(all|add)?tagsfromfile(=.*)?$/i) { |
| 815 |
$setTagsFile = $2 ? substr($2,1) : (@ARGV ? shift : ''); |
| 816 |
if ($setTagsFile eq '') { |
| 817 |
Error("File must be specified for -tagsFromFile option\n"); |
| 818 |
$badCmd = 1; |
| 819 |
next; |
| 820 |
} |
| 821 |
# create necessary lists, etc for this new -tagsFromFile file |
| 822 |
AddSetTagsFile($setTagsFile, { Replace => ($1 and lc($1) eq 'add') ? 0 : 1 } ); |
| 823 |
$tagsFrom = 'File'; |
| 824 |
next; |
| 825 |
} |
| 826 |
if ($a eq '@') { |
| 827 |
my $argFile = shift or Error("Expecting filename for -\@ option\n"), $badCmd=1, next; |
| 828 |
# switch to new ARGFILE if using chained -stay_open options |
| 829 |
if ($stayOpen == 1) { |
| 830 |
# defer remaining arguments until we close this argfile |
| 831 |
@moreArgs = @ARGV; |
| 832 |
undef @ARGV; |
| 833 |
} elsif ($stayOpen == 3) { |
| 834 |
if ($stayOpenFile and $stayOpenFile ne '-' and $argFile eq $stayOpenFile) { |
| 835 |
# don't allow user to switch to the same -stay_open argfile |
| 836 |
# because it will result in endless recursion |
| 837 |
$stayOpen = 2; |
| 838 |
Warn "Ignoring request to switch to the same -stay_open ARGFILE ($argFile)\n"; |
| 839 |
next; |
| 840 |
} |
| 841 |
close STAYOPEN; |
| 842 |
$stayOpen = 1; # switch to this -stay_open file |
| 843 |
} |
| 844 |
my $fp = ($stayOpen == 1 ? \*STAYOPEN : \*ARGFILE); |
| 845 |
unless ($mt->Open($fp, $argFile)) { |
| 846 |
unless ($argFile !~ /^\// and $mt->Open($fp, "$Image::ExifTool::exeDir/$argFile")) { |
| 847 |
Error "Error opening arg file $argFile\n"; |
| 848 |
$badCmd = 1; |
| 849 |
next |
| 850 |
} |
| 851 |
} |
| 852 |
if ($stayOpen == 1) { |
| 853 |
$stayOpenFile = $argFile; # remember the name of the file we have open |
| 854 |
$stayOpenBuff = ''; # initialize buffer for reading this file |
| 855 |
$stayOpen = 2; |
| 856 |
$helped = 1; |
| 857 |
ReadStayOpen(\@ARGV); |
| 858 |
next; |
| 859 |
} |
| 860 |
my (@newArgs, $didBOM); |
| 861 |
foreach (<ARGFILE>) { |
| 862 |
# filter Byte Order Mark if it exists from start of UTF-8 text file |
| 863 |
unless ($didBOM) { |
| 864 |
s/^\xef\xbb\xbf//; |
| 865 |
$didBOM = 1; |
| 866 |
} |
| 867 |
$_ = FilterArgfileLine($_); |
| 868 |
push @newArgs, $_ if defined $_; |
| 869 |
} |
| 870 |
close ARGFILE; |
| 871 |
unshift @ARGV, @newArgs; |
| 872 |
next; |
| 873 |
} |
| 874 |
/^(-?)(a|duplicates)$/i and $mt->Options(Duplicates => ($1 ? 0 : 1)), next; |
| 875 |
if ($a eq 'api') { |
| 876 |
my $opt = shift; |
| 877 |
if (defined $opt and length $opt) { |
| 878 |
my $val = ($opt =~ s/=(.*)//s) ? $1 : 1; |
| 879 |
# empty string means an undefined value unless ^= is used |
| 880 |
$val = undef unless $opt =~ s/\^$// or length $val; |
| 881 |
$mt->Options($opt => $val); |
| 882 |
} else { |
| 883 |
unless ($pass) { |
| 884 |
push @nextPass, '-api'; |
| 885 |
push @nextPass, $opt if defined $opt; |
| 886 |
next; |
| 887 |
} |
| 888 |
print "Available API Options:\n"; |
| 889 |
my $availableOptions = Image::ExifTool::AvailableOptions(); |
| 890 |
$$_[3] or printf(" %-17s - %s\n", $$_[0], $$_[2]) foreach @$availableOptions; |
| 891 |
$helped = 1; |
| 892 |
} |
| 893 |
next; |
| 894 |
} |
| 895 |
/^arg(s|format)$/i and $argFormat = 1, next; |
| 896 |
if (/^(-?)b(inary)?$/i) { |
| 897 |
($binaryOutput, $noBinary) = $1 ? (undef, 1) : (1, undef); |
| 898 |
$mt->Options(Binary => $binaryOutput, NoPDFList => $binaryOutput); |
| 899 |
next; |
| 900 |
} |
| 901 |
if (/^c(oordFormat)?$/i) { |
| 902 |
my $fmt = shift; |
| 903 |
$fmt or Error("Expecting coordinate format for -c option\n"), $badCmd=1, next; |
| 904 |
$mt->Options('CoordFormat', $fmt); |
| 905 |
next; |
| 906 |
} |
| 907 |
if ($a eq 'charset') { |
| 908 |
my $charset = (@ARGV and $ARGV[0] !~ /^(-|\xe2\x88\x92)/) ? shift : undef; |
| 909 |
if (not $charset) { |
| 910 |
unless ($pass) { |
| 911 |
push @nextPass, '-charset' ; |
| 912 |
push @nextPass, $charset if defined $charset; |
| 913 |
next; |
| 914 |
} |
| 915 |
my %charsets; |
| 916 |
$charsets{$_} = 1 foreach values %Image::ExifTool::charsetName; |
| 917 |
PrintTagList('Available character sets', sort keys %charsets); |
| 918 |
$helped = 1; |
| 919 |
} elsif ($charset !~ s/^(\w+)=// or lc($1) eq 'exiftool') { |
| 920 |
{ |
| 921 |
local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; |
| 922 |
undef $evalWarning; |
| 923 |
$mt->Options(Charset => $charset); |
| 924 |
} |
| 925 |
if ($evalWarning) { |
| 926 |
Warn $evalWarning; |
| 927 |
} else { |
| 928 |
$setCharset = $mt->Options('Charset'); |
| 929 |
} |
| 930 |
} else { |
| 931 |
# set internal encoding of specified metadata type |
| 932 |
my $type = { id3 => 'ID3', iptc => 'IPTC', exif => 'EXIF', filename => 'FileName', |
| 933 |
photoshop => 'Photoshop', quicktime => 'QuickTime', riff=>'RIFF' }->{lc $1}; |
| 934 |
$type or Warn("Unknown type for -charset option: $1\n"), next; |
| 935 |
$mt->Options("Charset$type" => $charset); |
| 936 |
} |
| 937 |
next; |
| 938 |
} |
| 939 |
/^config$/i and Warn("Ignored -config option (not first on command line)\n"), shift, next; |
| 940 |
if (/^(csv|j(son)?)(\+?=.*)?$/i) { |
| 941 |
my $dbFile = $3; |
| 942 |
my $dbType = lc($1) eq 'csv' ? 'CSV' : 'JSON'; |
| 943 |
unless ($dbFile) { |
| 944 |
if ($dbType eq 'CSV') { |
| 945 |
$csv = $dbType; |
| 946 |
} else { |
| 947 |
$json = 1; |
| 948 |
$html = $xml = 0; |
| 949 |
$mt->Options(Duplicates => 1); |
| 950 |
require Image::ExifTool::XMP; # for FixUTF8() |
| 951 |
} |
| 952 |
next; |
| 953 |
} |
| 954 |
# must process on 2nd pass so -f and -charset options are available |
| 955 |
unless ($pass) { |
| 956 |
@tags and Warn("Tag arguments should come after the -$1= option\n"); |
| 957 |
push @nextPass, "-$_"; |
| 958 |
push @newValues, { SaveCount => ++$saveCount }; # marker to save new values now |
| 959 |
$dbSaveCount = $saveCount; |
| 960 |
$tagsFrom = 'CSV'; |
| 961 |
next; |
| 962 |
} |
| 963 |
$dbFile =~ s/^(\+?=)//; |
| 964 |
$dbAdd = 2 if $1 eq '+='; |
| 965 |
$vout = \*STDERR if $srcStdin; |
| 966 |
$verbose and print $vout "Reading $dbType file $dbFile\n"; |
| 967 |
my $msg; |
| 968 |
if ($mt->Open(\*CSVFILE, $dbFile)) { |
| 969 |
binmode CSVFILE; |
| 970 |
require Image::ExifTool::Import; |
| 971 |
if ($dbType eq 'CSV') { |
| 972 |
$msg = Image::ExifTool::Import::ReadCSV(\*CSVFILE, \%database, $forcePrint, $csvDelim); |
| 973 |
} else { |
| 974 |
my $chset = $mt->Options('Charset'); |
| 975 |
$msg = Image::ExifTool::Import::ReadJSON(\*CSVFILE, \%database, $forcePrint, $chset); |
| 976 |
} |
| 977 |
close(CSVFILE); |
| 978 |
} else { |
| 979 |
$msg = "Error opening $dbType file '${dbFile}'"; |
| 980 |
} |
| 981 |
$msg and Warn("$msg\n"); |
| 982 |
$isWriting = 1; |
| 983 |
$csv = $dbType; |
| 984 |
next; |
| 985 |
} |
| 986 |
if (/^csvdelim$/i) { |
| 987 |
$csvDelim = shift; |
| 988 |
defined $csvDelim or Error("Expecting argument for -csvDelim option\n"), $badCmd=1, next; |
| 989 |
$csvDelim =~ /"/ and Error("CSV delimiter can not contain a double quote\n"), $badCmd=1, next; |
| 990 |
my %unescape = ( 't'=>"\t", 'n'=>"\n", 'r'=>"\r", '\\' => '\\' ); |
| 991 |
$csvDelim =~ s/\\(.)/$unescape{$1}||"\\$1"/sge; |
| 992 |
$mt->Options(CSVDelim => $csvDelim); |
| 993 |
next; |
| 994 |
} |
| 995 |
if (/^d$/ or $a eq 'dateformat') { |
| 996 |
my $fmt = shift; |
| 997 |
$fmt or Error("Expecting date format for -d option\n"), $badCmd=1, next; |
| 998 |
$mt->Options('DateFormat', $fmt); |
| 999 |
next; |
| 1000 |
} |
| 1001 |
(/^D$/ or $a eq 'decimal') and $showTagID = 'D', next; |
| 1002 |
if (/^diff$/i) { |
| 1003 |
$diff = shift; |
| 1004 |
defined $diff or Error("Expecting file name for -$_ option\n"), $badCmd=1; |
| 1005 |
CleanFilename($diff); # change to forward slashes if necessary |
| 1006 |
next; |
| 1007 |
} |
| 1008 |
/^delete_original(!?)$/i and $deleteOrig = ($1 ? 2 : 1), next; |
| 1009 |
/^list_dir$/i and $listDir = 1, next; |
| 1010 |
(/^e$/ or $a eq '-composite') and $mt->Options(Composite => 0), next; |
| 1011 |
(/^-e$/ or $a eq 'composite') and $mt->Options(Composite => 1), next; |
| 1012 |
(/^E$/ or $a eq 'escapehtml') and require Image::ExifTool::HTML and $escapeHTML = 1, next; |
| 1013 |
($a eq 'ec' or $a eq 'escapec') and $escapeC = 1, next; |
| 1014 |
($a eq 'ex' or $a eq 'escapexml') and $escapeXML = 1, next; |
| 1015 |
if (/^echo(\d)?$/i) { |
| 1016 |
my $n = $1 || 1; |
| 1017 |
my $arg = shift; |
| 1018 |
next unless defined $arg; |
| 1019 |
$n > 4 and Warn("Invalid -echo number\n"), next; |
| 1020 |
if ($n > 2) { |
| 1021 |
$n == 3 ? push(@echo3, $arg) : push(@echo4, $arg); |
| 1022 |
} else { |
| 1023 |
print {$n==2 ? \*STDERR : \*STDOUT} $arg, "\n"; |
| 1024 |
} |
| 1025 |
$helped = 1; |
| 1026 |
next; |
| 1027 |
} |
| 1028 |
if (/^(ee|extractembedded)(\d*)$/i) { |
| 1029 |
$mt->Options(ExtractEmbedded => $2 || 1); |
| 1030 |
$mt->Options(Duplicates => 1); |
| 1031 |
next; |
| 1032 |
} |
| 1033 |
if (/^efile(\d+)?(!)?$/i) { |
| 1034 |
my $arg = shift; |
| 1035 |
defined $arg or Error("Expecting file name for -$_ option\n"), $badCmd=1, next; |
| 1036 |
$efile[0] = $arg if not $1 or $1 & 0x01;# error |
| 1037 |
$efile[1] = $arg if $1 and $1 & 0x02; # unchanged |
| 1038 |
$efile[2] = $arg if $1 and $1 & 0x04; # failed -if condition |
| 1039 |
$efile[3] = $arg if $1 and $1 & 0x08; # updated |
| 1040 |
$efile[4] = $arg if $1 and $1 & 0x016; # created |
| 1041 |
unlink $arg if $2; |
| 1042 |
next; |
| 1043 |
} |
| 1044 |
# (-execute handled at top of loop) |
| 1045 |
if (/^-?ext(ension)?(\+)?$/i) { |
| 1046 |
my $ext = shift; |
| 1047 |
defined $ext or Error("Expecting extension for -ext option\n"), $badCmd=1, next; |
| 1048 |
my $flag = /^-/ ? 0 : ($2 ? 2 : 1); |
| 1049 |
$filterFlag |= (0x01 << $flag); |
| 1050 |
$ext =~ s/^\.//; # remove leading '.' if it exists |
| 1051 |
$filterExt{uc($ext)} = $flag ? 1 : 0; |
| 1052 |
next; |
| 1053 |
} |
| 1054 |
if (/^f$/ or $a eq 'forceprint') { |
| 1055 |
$forcePrint = 1; |
| 1056 |
next; |
| 1057 |
} |
| 1058 |
if (/^F([-+]?\d*)$/ or /^fixbase([-+]?\d*)$/i) { |
| 1059 |
$mt->Options(FixBase => $1); |
| 1060 |
next; |
| 1061 |
} |
| 1062 |
if (/^fast(\d*)$/i) { |
| 1063 |
$mt->Options(FastScan => (length $1 ? $1 : 1)); |
| 1064 |
next; |
| 1065 |
} |
| 1066 |
if (/^(file\d+)$/i) { |
| 1067 |
$altFile{lc $1} = shift or Error("Expecting file name for -file option\n"), $badCmd=1, next; |
| 1068 |
next; |
| 1069 |
} |
| 1070 |
if (/^fileorder(\d*)$/i) { |
| 1071 |
push @fileOrder, shift if @ARGV; |
| 1072 |
my $num = $1 || 0; |
| 1073 |
$fileOrderFast = $num if not defined $fileOrderFast or $fileOrderFast > $num; |
| 1074 |
next; |
| 1075 |
} |
| 1076 |
$a eq 'globaltimeshift' and $mt->Options(GlobalTimeShift => shift), next; |
| 1077 |
if (/^(g)(roupHeadings|roupNames)?([\d:]*)$/i) { |
| 1078 |
$showGroup = $3 || 0; |
| 1079 |
$allGroup = ($2 ? lc($2) eq 'roupnames' : $1 eq 'G'); |
| 1080 |
$mt->Options(SavePath => 1) if $showGroup =~ /\b5\b/; |
| 1081 |
$mt->Options(SaveFormat => 1) if $showGroup =~ /\b6\b/; |
| 1082 |
next; |
| 1083 |
} |
| 1084 |
if ($a eq 'geotag') { |
| 1085 |
my $trkfile = shift; |
| 1086 |
unless ($pass) { |
| 1087 |
# defer to next pass so the filename charset is available |
| 1088 |
push @nextPass, '-geotag', $trkfile; |
| 1089 |
next; |
| 1090 |
} |
| 1091 |
$trkfile or Error("Expecting file name for -geotag option\n"), $badCmd=1, next; |
| 1092 |
# allow wildcards in filename |
| 1093 |
if (HasWildcards($trkfile)) { |
| 1094 |
# CORE::glob() splits on white space, so use File::Glob if possible |
| 1095 |
my @trks; |
| 1096 |
if ($^O eq 'MSWin32' and eval { require Win32::FindFile }) { |
| 1097 |
# ("-charset filename=UTF8" must be set for this to work with Unicode file names) |
| 1098 |
@trks = FindFileWindows($mt, $trkfile); |
| 1099 |
} elsif (eval { require File::Glob }) { |
| 1100 |
@trks = File::Glob::bsd_glob($trkfile); |
| 1101 |
} else { |
| 1102 |
@trks = glob($trkfile); |
| 1103 |
} |
| 1104 |
@trks or Error("No matching file found for -geotag option\n"), $badCmd=1, next; |
| 1105 |
push @newValues, 'geotag='.shift(@trks) while @trks > 1; |
| 1106 |
$trkfile = pop(@trks); |
| 1107 |
} |
| 1108 |
$_ = "geotag=$trkfile"; |
| 1109 |
# (fall through!) |
| 1110 |
} |
| 1111 |
if (/^h$/ or $a eq 'htmlformat') { |
| 1112 |
require Image::ExifTool::HTML; |
| 1113 |
$html = $escapeHTML = 1; |
| 1114 |
$json = $xml = 0; |
| 1115 |
next; |
| 1116 |
} |
| 1117 |
(/^H$/ or $a eq 'hex') and $showTagID = 'H', next; |
| 1118 |
if (/^htmldump([-+]?\d+)?$/i) { |
| 1119 |
$verbose = ($verbose || 0) + 1; |
| 1120 |
$html = 2; |
| 1121 |
$mt->Options(HtmlDumpBase => $1) if defined $1; |
| 1122 |
next; |
| 1123 |
} |
| 1124 |
if (/^i(gnore)?$/i) { |
| 1125 |
my $dir = shift; |
| 1126 |
defined $dir or Error("Expecting directory name for -i option\n"), $badCmd=1, next; |
| 1127 |
$ignore{$dir} = 1; |
| 1128 |
$dir eq 'HIDDEN' and $ignoreHidden = 1; |
| 1129 |
next; |
| 1130 |
} |
| 1131 |
if (/^if(\d*)$/i) { |
| 1132 |
my $cond = shift; |
| 1133 |
my $fast = length($1) ? $1 : undef; |
| 1134 |
defined $cond or Error("Expecting expression for -if option\n"), $badCmd=1, next; |
| 1135 |
# use lowest -fast setting if multiple conditions |
| 1136 |
if (not @condition or not defined $fast or (defined $fastCondition and $fastCondition > $fast)) { |
| 1137 |
$fastCondition = $fast; |
| 1138 |
} |
| 1139 |
# prevent processing file unnecessarily for simple case of failed '$ok' or 'not $ok' |
| 1140 |
$cond =~ /^\s*(not\s*)\$ok\s*$/i and ($1 xor $rtnValPrev) and $failCondition=1; |
| 1141 |
# add to list of requested tags |
| 1142 |
push @requestTags, $cond =~ /\$\{?((?:[-_0-9A-Z]+:)*[-_0-9A-Z?*]+)/ig; |
| 1143 |
push @condition, $cond; |
| 1144 |
next; |
| 1145 |
} |
| 1146 |
/^(k|pause)$/i and $pause = 1, next; |
| 1147 |
(/^l$/ or $a eq 'long') and --$outFormat, next; |
| 1148 |
(/^L$/ or $a eq 'latin') and $mt->Options(Charset => 'Latin'), next; |
| 1149 |
if ($a eq 'lang') { |
| 1150 |
$langOpt = (@ARGV and $ARGV[0] !~ /^(-|\xe2\x88\x92)/) ? shift : undef; |
| 1151 |
if ($langOpt) { |
| 1152 |
# make lower case and use underline as a separator (eg. 'en_ca') |
| 1153 |
$langOpt =~ tr/-A-Z/_a-z/; |
| 1154 |
$mt->Options(Lang => $langOpt); |
| 1155 |
next if $langOpt eq $mt->Options('Lang'); |
| 1156 |
} elsif (not $pass) { |
| 1157 |
push @nextPass, '-lang'; |
| 1158 |
push @nextPass, $langOpt if defined $langOpt; |
| 1159 |
next; |
| 1160 |
} |
| 1161 |
my $langs = $quiet ? '' : "Available languages:\n"; |
| 1162 |
$langs .= " $_ - $Image::ExifTool::langName{$_}\n" foreach @Image::ExifTool::langs; |
| 1163 |
$langs =~ tr/_/-/; # display dashes instead of underlines in language codes |
| 1164 |
$langs = Image::ExifTool::HTML::EscapeHTML($langs) if $escapeHTML; |
| 1165 |
$langs = $mt->Decode($langs, 'UTF8'); |
| 1166 |
$langOpt and Error("Invalid or unsupported language '${langOpt}'.\n$langs"), $badCmd=1, next; |
| 1167 |
print $langs; |
| 1168 |
$helped = 1; |
| 1169 |
next; |
| 1170 |
} |
| 1171 |
if ($a eq 'listitem') { |
| 1172 |
my $li = shift; |
| 1173 |
defined $li and Image::ExifTool::IsInt($li) or Warn("Expecting integer for -listItem option\n"), next; |
| 1174 |
$mt->Options(ListItem => $li); |
| 1175 |
$listItem = $li; |
| 1176 |
next; |
| 1177 |
} |
| 1178 |
/^(m|ignoreminorerrors)$/i and $mt->Options(IgnoreMinorErrors => 1), next; |
| 1179 |
/^(n|-printconv)$/i and $mt->Options(PrintConv => 0), next; |
| 1180 |
/^(-n|printconv)$/i and $mt->Options(PrintConv => 1), next; |
| 1181 |
$a eq 'nop' and $helped=1, next; # (undocumented) no operation, added in 11.25 |
| 1182 |
if (/^o(ut)?$/i) { |
| 1183 |
$outOpt = shift; |
| 1184 |
defined $outOpt or Error("Expected output file or directory name for -o option\n"), $badCmd=1, next; |
| 1185 |
CleanFilename($outOpt); |
| 1186 |
# verbose messages go to STDERR of output is to console |
| 1187 |
$vout = \*STDERR if $vout =~ /^-(\.\w+)?$/; |
| 1188 |
next; |
| 1189 |
} |
| 1190 |
$a eq 'overwrite_original' and $overwriteOrig = 1, next; |
| 1191 |
$a eq 'overwrite_original_in_place' and $overwriteOrig = 2, next; |
| 1192 |
$a eq 'plot' and require Image::ExifTool::Plot and $plot = Image::ExifTool::Plot->new, next; |
| 1193 |
if (/^p(-?)$/ or /^printformat(-?)$/i) { |
| 1194 |
my $fmt = shift; |
| 1195 |
if ($pass) { |
| 1196 |
LoadPrintFormat($fmt, $1 || $binaryOutput); |
| 1197 |
# load MWG module now if necessary |
| 1198 |
if (not $useMWG and grep /^([-_0-9A-Z]+:)*1?mwg:/i, @requestTags) { |
| 1199 |
$useMWG = 1; |
| 1200 |
require Image::ExifTool::MWG; |
| 1201 |
Image::ExifTool::MWG::Load(); |
| 1202 |
} |
| 1203 |
} else { |
| 1204 |
# defer to next pass so the filename charset is available |
| 1205 |
push @nextPass, "-$_", $fmt; |
| 1206 |
} |
| 1207 |
next; |
| 1208 |
} |
| 1209 |
(/^P$/ or $a eq 'preserve') and $preserveTime = 1, next; |
| 1210 |
$a eq 'password' and $mt->Options(Password => shift), next; |
| 1211 |
if (/^progress(\d*)(:.*)?$/i) { |
| 1212 |
$progressIncr = $1 || 1; |
| 1213 |
$progressNext = 0; # start showing progress at the first file |
| 1214 |
if ($2) { |
| 1215 |
$windowTitle = substr $2, 1; |
| 1216 |
$windowTitle = 'ExifTool %p%%' unless length $windowTitle; |
| 1217 |
$windowTitle =~ /%\d*[bpr]/ and $progress = 0 unless defined $progress; |
| 1218 |
} else { |
| 1219 |
$progress = 1; |
| 1220 |
$verbose = 0 unless defined $verbose; |
| 1221 |
} |
| 1222 |
$progressCount = 0; |
| 1223 |
next; |
| 1224 |
} |
| 1225 |
/^purge(\d*)$/i and $purge = $1||1, Image::ExifTool::Purge($purge), next; # (undocumented) added in 13.53 |
| 1226 |
/^q(uiet)?$/i and ++$quiet, next; |
| 1227 |
/^r(ecurse)?(\.?)$/i and $recurse = ($2 ? 2 : 1), next; |
| 1228 |
if ($a eq 'require') { # (undocumented) added in version 8.65 |
| 1229 |
my $ver = shift; |
| 1230 |
unless (defined $ver and Image::ExifTool::IsFloat($ver)) { |
| 1231 |
Error("Expecting version number for -require option\n"); |
| 1232 |
$badCmd = 1; |
| 1233 |
next; |
| 1234 |
} |
| 1235 |
unless ($Image::ExifTool::VERSION >= $ver) { |
| 1236 |
Error("Requires ExifTool version $ver or later\n"); |
| 1237 |
$badCmd = 1; |
| 1238 |
} |
| 1239 |
next; |
| 1240 |
} |
| 1241 |
$a eq 'restore_original' and $deleteOrig = 0, next; |
| 1242 |
(/^S$/ or $a eq 'veryshort') and $outFormat+=2, next; |
| 1243 |
/^s(hort)?(\d*)$/i and $outFormat = $2 eq '' ? $outFormat + 1 : $2, next; |
| 1244 |
$a eq 'scanforxmp' and $mt->Options(ScanForXMP => 1), next; |
| 1245 |
if (/^sep(arator)?$/i) { |
| 1246 |
my $sep = $listSep = shift; |
| 1247 |
defined $listSep or Error("Expecting list item separator for -sep option\n"), $badCmd=1, next; |
| 1248 |
$sep =~ s/\\(.)/$unescapeChar{$1}||$1/sge; # translate escape sequences |
| 1249 |
(defined $binSep ? $binTerm : $binSep) = $sep; |
| 1250 |
$mt->Options(ListSep => $listSep); |
| 1251 |
$joinLists = 1; |
| 1252 |
# also split when writing values |
| 1253 |
my $listSplit = quotemeta $listSep; |
| 1254 |
# a space in the string matches zero or more whitespace characters |
| 1255 |
$listSplit =~ s/(\\ )+/\\s\*/g; |
| 1256 |
# but a single space alone matches one or more whitespace characters |
| 1257 |
$listSplit = '\\s+' if $listSplit eq '\\s*'; |
| 1258 |
$mt->Options(ListSplit => $listSplit); |
| 1259 |
next; |
| 1260 |
} |
| 1261 |
/^(-)?sort$/i and $sortOpt = $1 ? 0 : 1, next; |
| 1262 |
if ($a eq 'srcfile') { |
| 1263 |
@ARGV or Warn("Expecting FMT for -srcfile option\n"), next; |
| 1264 |
push @srcFmt, shift; |
| 1265 |
next; |
| 1266 |
} |
| 1267 |
if ($a eq 'stay_open') { |
| 1268 |
my $arg = shift; |
| 1269 |
defined $arg or Warn("Expecting argument for -stay_open option\n"), next; |
| 1270 |
if ($arg =~ /^(1|true)$/i) { |
| 1271 |
if (not $stayOpen) { |
| 1272 |
$stayOpen = 1; |
| 1273 |
} elsif ($stayOpen == 2) { |
| 1274 |
$stayOpen = 3; # chained -stay_open options |
| 1275 |
} else { |
| 1276 |
Warn "-stay_open already active\n"; |
| 1277 |
} |
| 1278 |
} elsif ($arg =~ /^(0|false)$/i) { |
| 1279 |
if ($stayOpen >= 2) { |
| 1280 |
# close -stay_open argfile and process arguments up to this point |
| 1281 |
close STAYOPEN; |
| 1282 |
push @ARGV, @moreArgs; |
| 1283 |
undef @moreArgs; |
| 1284 |
} elsif (not $stayOpen) { |
| 1285 |
Warn("-stay_open wasn't active\n"); |
| 1286 |
} |
| 1287 |
$stayOpen = 0; |
| 1288 |
} else { |
| 1289 |
Warn "Invalid argument for -stay_open\n"; |
| 1290 |
} |
| 1291 |
next; |
| 1292 |
} |
| 1293 |
if (/^(-)?struct$/i) { |
| 1294 |
$mt->Options(Struct => $1 ? 0 : 1); |
| 1295 |
next; |
| 1296 |
} |
| 1297 |
/^t(ab)?$/ and $tabFormat = 1, next; |
| 1298 |
if (/^T$/ or $a eq 'table') { |
| 1299 |
$tabFormat = $forcePrint = 1; $outFormat+=2; ++$quiet; |
| 1300 |
next; |
| 1301 |
} |
| 1302 |
if (/^(u)(nknown(2)?)?$/i) { |
| 1303 |
my $inc = ($3 or (not $2 and $1 eq 'U')) ? 2 : 1; |
| 1304 |
$mt->Options(Unknown => $mt->Options('Unknown') + $inc); |
| 1305 |
next; |
| 1306 |
} |
| 1307 |
if ($a eq 'use') { |
| 1308 |
my $module = shift; |
| 1309 |
$module or Error("Expecting module name for -use option\n"), $badCmd=1, next; |
| 1310 |
lc $module eq 'mwg' and $useMWG = 1, next; |
| 1311 |
$module =~ /[^\w:]/ and Error("Invalid module name: $module\n"), $badCmd=1, next; |
| 1312 |
local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; |
| 1313 |
unless (eval "require Image::ExifTool::$module" or |
| 1314 |
eval "require $module" or |
| 1315 |
eval "require '${module}'") |
| 1316 |
{ |
| 1317 |
Error("Error using module $module\n"); |
| 1318 |
$badCmd = 1; |
| 1319 |
} |
| 1320 |
next; |
| 1321 |
} |
| 1322 |
if ($a eq 'userparam') { |
| 1323 |
my $opt = shift; |
| 1324 |
defined $opt or Error("Expected parameter for -userParam option\n"), $badCmd=1, next; |
| 1325 |
$opt =~ /=/ or $opt .= '=1'; |
| 1326 |
$mt->Options(UserParam => $opt); |
| 1327 |
next; |
| 1328 |
} |
| 1329 |
if (/^v(erbose)?(\d*)$/i) { |
| 1330 |
$verbose = ($2 eq '') ? ($verbose || 0) + 1 : $2; |
| 1331 |
next; |
| 1332 |
} |
| 1333 |
if (/^(w|textout|tagout)([!+]*)$/i) { |
| 1334 |
# (note: all logic ignores $textOut of 0 or '') |
| 1335 |
$textOut = shift || Warn("Expecting argument for -$_ option\n"); |
| 1336 |
my ($t1, $t2) = ($1, $2); |
| 1337 |
$textOverwrite = 0; |
| 1338 |
$textOverwrite += 1 if $t2 =~ /!/; # overwrite |
| 1339 |
$textOverwrite += 2 if $t2 =~ /\+/; # append |
| 1340 |
if ($t1 ne 'W' and lc($t1) ne 'tagout') { |
| 1341 |
undef $tagOut; |
| 1342 |
} elsif ($textOverwrite >= 2 and $textOut !~ /%[-+]?\d*[.:]?\d*[lu]?[tgso]/) { |
| 1343 |
$tagOut = 0; # append tags to one file |
| 1344 |
} else { |
| 1345 |
$tagOut = 1; # separate file for each tag |
| 1346 |
} |
| 1347 |
next; |
| 1348 |
} |
| 1349 |
if (/^(-?)(wext|tagoutext)$/i) { |
| 1350 |
my $ext = shift; |
| 1351 |
defined $ext or Error("Expecting extension for -wext option\n"), $badCmd=1, next; |
| 1352 |
my $flag = 1; |
| 1353 |
$1 and $wext{'*'} = 1, $flag = -1; |
| 1354 |
$ext =~ s/^\.//; |
| 1355 |
$wext{lc $ext} = $flag; |
| 1356 |
next; |
| 1357 |
} |
| 1358 |
if ($a eq 'wm' or $a eq 'writemode') { |
| 1359 |
my $wm = shift; |
| 1360 |
defined $wm or Error("Expecting argument for -$_ option\n"), $badCmd=1, next; |
| 1361 |
$wm =~ /^[wcg]*$/i or Error("Invalid argument for -$_ option\n"), $badCmd=1, next; |
| 1362 |
$mt->Options(WriteMode => $wm); |
| 1363 |
next; |
| 1364 |
} |
| 1365 |
if (/^x$/ or $a eq 'exclude') { |
| 1366 |
my $tag = shift; |
| 1367 |
defined $tag or Error("Expecting tag name for -x option\n"), $badCmd=1, next; |
| 1368 |
$tag =~ s/\ball\b/\*/ig; # replace 'all' with '*' in tag names |
| 1369 |
if (not $tagsFrom) { |
| 1370 |
push @exclude, $tag; |
| 1371 |
} elsif ($tagsFrom eq 'CSV') { |
| 1372 |
push @csvExclude, $tag; |
| 1373 |
} else { |
| 1374 |
push @{$setTags{$setTagsFile}}, "-$tag"; |
| 1375 |
} |
| 1376 |
next; |
| 1377 |
} |
| 1378 |
(/^X$/ or $a eq 'xmlformat') and $xml = 1, $html = $json = 0, $mt->Options(Duplicates => 1), next; |
| 1379 |
if ($a eq 'php') { |
| 1380 |
$json = 2; |
| 1381 |
$html = $xml = 0; |
| 1382 |
$mt->Options(Duplicates => 1); |
| 1383 |
next; |
| 1384 |
} |
| 1385 |
if (/^z(ip)?$/i) { |
| 1386 |
$doUnzip = 1; |
| 1387 |
$mt->Options(Compress => 1, XMPShorthand => 1); |
| 1388 |
$mt->Options(Compact => 1) unless $mt->Options('Compact'); |
| 1389 |
next; |
| 1390 |
} |
| 1391 |
$_ eq '' and push(@files, '-'), $srcStdin = 1, next; # read STDIN |
| 1392 |
length $_ eq 1 and $_ ne '*' and Error("Unknown option -$_\n"), $badCmd=1, next; |
| 1393 |
if (/^[^<]+(<?)=(.*)/s) { |
| 1394 |
my $val = $2; |
| 1395 |
if ($1 and length($val) and ($val eq '@' or not defined FilenameSPrintf($val))) { |
| 1396 |
# save count of new values before a dynamic value |
| 1397 |
push @newValues, { SaveCount => ++$saveCount }; |
| 1398 |
} |
| 1399 |
push @newValues, $_; |
| 1400 |
if (/^([-_0-9A-Z]+:)*1?mwg:/i) { |
| 1401 |
$useMWG = 1; |
| 1402 |
} elsif (/^([-_0-9A-Z]+:)*(filename|directory|testname)\b/i) { |
| 1403 |
$doSetFileName = 1; |
| 1404 |
} elsif (/^([-_0-9A-Z]+:)*(geotag|geotime|geosync|geolocate)\b/i) { |
| 1405 |
if (lc $2 eq 'geotime') { |
| 1406 |
$addGeotime = ''; |
| 1407 |
} else { |
| 1408 |
# add geotag/geosync/geolocate commands first |
| 1409 |
unshift @newValues, pop @newValues; |
| 1410 |
if (lc $2 eq 'geotag' and (not defined $addGeotime or $addGeotime) and length $val) { |
| 1411 |
$addGeotime = ($1 || '') . q[Geotime<${DateTimeOriginal#;$_=$self->GetValue('SubSecDateTimeOriginal','ValueConv') || $_}]; |
| 1412 |
} |
| 1413 |
} |
| 1414 |
} |
| 1415 |
} else { |
| 1416 |
# assume '-tagsFromFile @' if tags are being redirected |
| 1417 |
# and not from CSV and -tagsFromFile hasn't already been specified |
| 1418 |
if (not $setTagsFile and $tagsFrom ne 'CSV' and /(<|>)/) { |
| 1419 |
AddSetTagsFile($setTagsFile = '@'); |
| 1420 |
$tagsFrom = 'File'; |
| 1421 |
} |
| 1422 |
if ($tagsFrom eq 'CSV') { |
| 1423 |
my $lst = s/^-// ? \@csvExclude : \@tags; |
| 1424 |
push @$lst, $_; |
| 1425 |
} elsif ($setTagsFile) { |
| 1426 |
push @{$setTags{$setTagsFile}}, $_; |
| 1427 |
if ($1 eq '>') { |
| 1428 |
$useMWG = 1 if /^(.*>\s*)?([-_0-9A-Z]+:)*1?mwg:/si; |
| 1429 |
if (/\b(filename|directory|testname)#?$/i) { |
| 1430 |
$doSetFileName = 1; |
| 1431 |
} elsif (/\bgeotime#?$/i) { |
| 1432 |
$addGeotime = ''; |
| 1433 |
} |
| 1434 |
} else { |
| 1435 |
$useMWG = 1 if /^([^<]+<\s*(.*\$\{?)?)?([-_0-9A-Z]+:)*1?mwg:/si; |
| 1436 |
if (/^([-_0-9A-Z]+:)*(filename|directory|testname)\b/i) { |
| 1437 |
$doSetFileName = 1; |
| 1438 |
} elsif (/^([-_0-9A-Z]+:)*geotime\b/i) { |
| 1439 |
$addGeotime = ''; |
| 1440 |
} |
| 1441 |
} |
| 1442 |
} else { |
| 1443 |
my $lst = s/^-// ? \@exclude : \@tags; |
| 1444 |
Warn(qq(Invalid TAG name: "$_"\n)) unless /^([-_0-9A-Z*]+:)*([-_0-9A-Z*?]+)#?$/i; |
| 1445 |
push @$lst, $_; # (push everything for backward compatibility) |
| 1446 |
} |
| 1447 |
} |
| 1448 |
} else { |
| 1449 |
unless ($pass) { |
| 1450 |
# defer to next pass so the filename charset is available |
| 1451 |
push @nextPass, $_; |
| 1452 |
next; |
| 1453 |
} |
| 1454 |
if ($doGlob and HasWildcards($_)) { |
| 1455 |
if ($^O eq 'MSWin32' and eval { require Win32::FindFile }) { |
| 1456 |
push @files, FindFileWindows($mt, $_); |
| 1457 |
} else { |
| 1458 |
# glob each filespec if necessary - MK/20061010 |
| 1459 |
push @files, File::Glob::bsd_glob($_); |
| 1460 |
} |
| 1461 |
$doGlob = 2; |
| 1462 |
} else { |
| 1463 |
push @files, $_; |
| 1464 |
$srcStdin = 1 if $_ eq '-'; |
| 1465 |
} |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
# set "OK" UserParam based on result of last command |
| 1470 |
$mt->Options(UserParam => 'OK=' . (not $rtnValPrev)); |
| 1471 |
|
| 1472 |
# set verbose output to STDERR if output could be to console |
| 1473 |
$vout = \*STDERR if $srcStdin and ($isWriting or @newValues); |
| 1474 |
$mt->Options(TextOut => $vout) if $vout eq \*STDERR; |
| 1475 |
|
| 1476 |
# change default EXIF string encoding if MWG used |
| 1477 |
if ($useMWG and not defined $mt->Options('CharsetEXIF')) { |
| 1478 |
$mt->Options(CharsetEXIF => 'UTF8'); |
| 1479 |
} |
| 1480 |
|
| 1481 |
# allow geolocation without input file if set to a position |
| 1482 |
if (not @files and not $outOpt and not @newValues) { |
| 1483 |
my $loc = $mt->Options('Geolocation'); |
| 1484 |
# use undocumented feature to input JSON file directly from command line |
| 1485 |
$loc and $loc ne '1' and push(@files, qq(\@JSON:{})), $geoOnly = 1; |
| 1486 |
} |
| 1487 |
|
| 1488 |
# print help |
| 1489 |
unless ((@tags and not $outOpt) or @files or @newValues or $geoOnly) { |
| 1490 |
if ($doGlob and $doGlob == 2) { |
| 1491 |
Error "No matching files\n"; |
| 1492 |
next; |
| 1493 |
} |
| 1494 |
$outOpt and Error("Nothing to write\n"), next; |
| 1495 |
unless ($helped) { |
| 1496 |
# catch warnings if we have problems running perldoc |
| 1497 |
local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; |
| 1498 |
my $dummy = \*SAVEERR; # avoid "used only once" warning |
| 1499 |
unless ($^O eq 'os2') { |
| 1500 |
open SAVEERR, ">&STDERR"; |
| 1501 |
open STDERR, '>/dev/null'; |
| 1502 |
} |
| 1503 |
if (system('perldoc',$0)) { |
| 1504 |
print "Syntax: exiftool [OPTIONS] FILE\n\n"; |
| 1505 |
print "Consult the exiftool documentation for a full list of options.\n"; |
| 1506 |
} |
| 1507 |
unless ($^O eq 'os2') { |
| 1508 |
close STDERR; |
| 1509 |
open STDERR, '>&SAVEERR'; |
| 1510 |
} |
| 1511 |
} |
| 1512 |
next; |
| 1513 |
} |
| 1514 |
|
| 1515 |
# do sanity check on -delete_original and -restore_original |
| 1516 |
if (defined $deleteOrig and (@newValues or @tags)) { |
| 1517 |
if (not @newValues) { |
| 1518 |
my $verb = $deleteOrig ? 'deleting' : 'restoring from'; |
| 1519 |
Error "Can't specify tags when $verb originals\n"; |
| 1520 |
} elsif ($deleteOrig) { |
| 1521 |
Error "Can't use -delete_original when writing.\n"; |
| 1522 |
Error "Maybe you meant -overwrite_original ?\n"; |
| 1523 |
} else { |
| 1524 |
Error "It makes no sense to use -restore_original when writing\n"; |
| 1525 |
} |
| 1526 |
next; |
| 1527 |
} |
| 1528 |
|
| 1529 |
if ($overwriteOrig > 1 and $outOpt) { |
| 1530 |
Error "Can't overwrite in place when -o option is used\n"; |
| 1531 |
next; |
| 1532 |
} |
| 1533 |
|
| 1534 |
if (($tagOut or defined $diff) and ($csv or $json or %printFmt or $tabFormat or $xml or $plot or |
| 1535 |
($verbose and $html))) |
| 1536 |
{ |
| 1537 |
my $opt = $tagOut ? '-W' : '-diff'; |
| 1538 |
Error "Sorry, $opt may not be combined with -csv, -htmlDump, -j, -p, -t or -X\n"; |
| 1539 |
next; |
| 1540 |
} |
| 1541 |
|
| 1542 |
if ($csv and $csv eq 'CSV' and not $isWriting) { |
| 1543 |
$json = 0; # (not compatible) |
| 1544 |
if ($textOut) { |
| 1545 |
$textOut2 = $textOut; |
| 1546 |
undef $textOut; |
| 1547 |
} |
| 1548 |
if ($binaryOutput) { |
| 1549 |
$binaryOutput = 0; |
| 1550 |
$setCharset = 'default' unless defined $setCharset; |
| 1551 |
} |
| 1552 |
if (%printFmt) { |
| 1553 |
Warn "The -csv option has no effect when -p is used\n"; |
| 1554 |
undef $csv; |
| 1555 |
} |
| 1556 |
require Image::ExifTool::XMP if $setCharset; |
| 1557 |
} |
| 1558 |
if ($plot and $textOut) { |
| 1559 |
$textOut2 = $textOut; |
| 1560 |
undef $textOut; |
| 1561 |
} |
| 1562 |
if ($textOut2) { |
| 1563 |
if ($textOverwrite > 1) { |
| 1564 |
Error "Can not append to multi-file output format\n"; |
| 1565 |
undef $textOut2; |
| 1566 |
next; |
| 1567 |
} |
| 1568 |
if (not $textOverwrite and $mt->Exists($textOut2, 1)) { |
| 1569 |
Error "Output file $textOut2 already exists\n"; |
| 1570 |
undef $textOut2; |
| 1571 |
next; |
| 1572 |
} |
| 1573 |
# make sure we can write the output text file before processing all input files |
| 1574 |
CreateDirectory($textOut2); # create directory if necessary |
| 1575 |
if ($mt->Open(\*OUTFILE, $textOut2, '>')) { |
| 1576 |
close(\*OUTFILE); |
| 1577 |
unlink($textOut2); # (this was just a test) |
| 1578 |
} else { |
| 1579 |
Error("Error creating $textOut2\n"); |
| 1580 |
undef $textOut2; |
| 1581 |
next; |
| 1582 |
} |
| 1583 |
} |
| 1584 |
|
| 1585 |
if ($escapeHTML or $json) { |
| 1586 |
# must be UTF8 for HTML conversion and JSON output |
| 1587 |
$mt->Options(Charset => 'UTF8') if $json; |
| 1588 |
# use Escape option to do our HTML escaping unless XML output |
| 1589 |
$mt->Options(Escape => 'HTML') if $escapeHTML and not $xml; |
| 1590 |
} elsif ($escapeXML and not $xml) { |
| 1591 |
$mt->Options(Escape => 'XML'); |
| 1592 |
} |
| 1593 |
|
| 1594 |
# set sort option |
| 1595 |
if ($sortOpt) { |
| 1596 |
# (note that -csv sorts alphabetically by default anyway if more than 1 file) |
| 1597 |
my $sort = ($outFormat > 0 or $xml or $json or $csv or $plot) ? 'Tag' : 'Descr'; |
| 1598 |
$mt->Options(Sort => $sort, Sort2 => $sort); |
| 1599 |
} |
| 1600 |
|
| 1601 |
# set $structOpt in case set by API option |
| 1602 |
if ($mt->Options('Struct') and not $structOpt) { |
| 1603 |
$structOpt = $mt->Options('Struct'); |
| 1604 |
require 'Image/ExifTool/XMPStruct.pl'; |
| 1605 |
} |
| 1606 |
|
| 1607 |
# set up for RDF/XML, JSON and PHP output formats |
| 1608 |
if ($plot) { |
| 1609 |
undef $joinLists; |
| 1610 |
$mt->Options(List => 1); |
| 1611 |
$plot->Settings($mt->Options('Plot')); |
| 1612 |
} elsif ($xml) { |
| 1613 |
require Image::ExifTool::XMP; # for EscapeXML() |
| 1614 |
my $charset = $mt->Options('Charset'); |
| 1615 |
# standard XML encoding names for supported Charset settings |
| 1616 |
# (ref http://www.iana.org/assignments/character-sets) |
| 1617 |
my %encoding = ( |
| 1618 |
UTF8 => 'UTF-8', |
| 1619 |
Latin => 'windows-1252', |
| 1620 |
Latin2 => 'windows-1250', |
| 1621 |
Cyrillic => 'windows-1251', |
| 1622 |
Greek => 'windows-1253', |
| 1623 |
Turkish => 'windows-1254', |
| 1624 |
Hebrew => 'windows-1255', |
| 1625 |
Arabic => 'windows-1256', |
| 1626 |
Baltic => 'windows-1257', |
| 1627 |
Vietnam => 'windows-1258', |
| 1628 |
MacRoman => 'macintosh', |
| 1629 |
); |
| 1630 |
# switch to UTF-8 if we don't have a standard encoding name |
| 1631 |
unless ($encoding{$charset}) { |
| 1632 |
$charset = 'UTF8'; |
| 1633 |
$mt->Options(Charset => $charset); |
| 1634 |
} |
| 1635 |
# set file header/trailer for XML output |
| 1636 |
$fileHeader = "<?xml version='1.0' encoding='$encoding{$charset}'?>\n" . |
| 1637 |
"<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n"; |
| 1638 |
$fileTrailer = "</rdf:RDF>\n"; |
| 1639 |
# extract as a list unless short output format |
| 1640 |
$joinLists = 1 if $outFormat > 0; |
| 1641 |
$mt->Options(List => 1) unless $joinLists; |
| 1642 |
$showGroup = $allGroup = 1; # always show group 1 |
| 1643 |
# set binaryOutput flag to 0 or undef (0 = output encoded binary in XML) |
| 1644 |
$binaryOutput = ($outFormat > 0 ? undef : 0) if $binaryOutput; |
| 1645 |
$showTagID = 'D' if $tabFormat and not $showTagID; |
| 1646 |
} elsif ($json) { |
| 1647 |
if ($json == 1) { # JSON |
| 1648 |
$fileHeader = '['; |
| 1649 |
$fileTrailer = "]\n"; |
| 1650 |
} else { # PHP |
| 1651 |
$fileHeader = 'Array('; |
| 1652 |
$fileTrailer = ");\n"; |
| 1653 |
} |
| 1654 |
# allow binary output in a text-mode file when -php/-json and -b used together |
| 1655 |
# (this works because PHP strings are simple arrays of bytes, and CR/LF |
| 1656 |
# won't be messed up in the text mode output because they are converted |
| 1657 |
# to escape sequences in the strings) |
| 1658 |
if ($binaryOutput) { |
| 1659 |
$binaryOutput = 0; |
| 1660 |
require Image::ExifTool::XMP if $json == 1; # (for EncodeBase64) |
| 1661 |
} |
| 1662 |
$mt->Options(List => 1) unless $joinLists; |
| 1663 |
$showTagID = 'D' if $tabFormat and not $showTagID; |
| 1664 |
} elsif ($structOpt) { |
| 1665 |
$mt->Options(List => 1); |
| 1666 |
} else { |
| 1667 |
$joinLists = 1; # join lists for all other unstructured output formats |
| 1668 |
} |
| 1669 |
|
| 1670 |
if ($argFormat) { |
| 1671 |
$outFormat = 3; |
| 1672 |
$allGroup = 1 if defined $showGroup; |
| 1673 |
} |
| 1674 |
|
| 1675 |
# change to forward slashes if necessary in all filenames (like CleanFilename) |
| 1676 |
if (Image::ExifTool::IsPC()) { |
| 1677 |
tr/\\/\// foreach @files; |
| 1678 |
} |
| 1679 |
|
| 1680 |
# can't do anything if no file specified |
| 1681 |
unless (@files) { |
| 1682 |
unless ($outOpt) { |
| 1683 |
if ($doGlob and $doGlob == 2) { |
| 1684 |
Error "No matching files\n"; |
| 1685 |
} else { |
| 1686 |
Error "No file specified\n"; |
| 1687 |
} |
| 1688 |
next; |
| 1689 |
} |
| 1690 |
push @files, ''; # create file from nothing |
| 1691 |
} |
| 1692 |
|
| 1693 |
# set Verbose and HtmlDump options |
| 1694 |
if ($verbose) { |
| 1695 |
$disableOutput = 1 unless @tags or @exclude or $tagOut; |
| 1696 |
undef $binaryOutput unless $tagOut; # disable conflicting option |
| 1697 |
if ($html) { |
| 1698 |
$html = 2; # flag for html dump |
| 1699 |
$mt->Options(HtmlDump => $verbose); |
| 1700 |
} else { |
| 1701 |
$mt->Options(Verbose => $verbose) unless $tagOut; |
| 1702 |
} |
| 1703 |
} elsif (defined $verbose) { |
| 1704 |
# auto-flush output when -v0 is used |
| 1705 |
require FileHandle; |
| 1706 |
STDOUT->autoflush(1); |
| 1707 |
STDERR->autoflush(1); |
| 1708 |
} |
| 1709 |
|
| 1710 |
# validate all tags we're writing |
| 1711 |
my $needSave = 1; |
| 1712 |
if (@newValues) { |
| 1713 |
# assume -geotime value if -geotag specified without -geotime |
| 1714 |
if ($addGeotime) { |
| 1715 |
AddSetTagsFile($setTagsFile = '@') unless $setTagsFile and $setTagsFile eq '@'; |
| 1716 |
push @{$setTags{$setTagsFile}}, $addGeotime; |
| 1717 |
$verbose and print $vout qq(Using default "-$addGeotime"\n); |
| 1718 |
} |
| 1719 |
my %setTagsIndex; |
| 1720 |
# add/delete option lookup |
| 1721 |
my %addDelOpt = ( '+' => 'AddValue', '-' => 'DelValue', "\xe2\x88\x92" => 'DelValue' ); |
| 1722 |
$saveCount = 0; |
| 1723 |
foreach (@newValues) { |
| 1724 |
if (ref $_ eq 'HASH') { |
| 1725 |
# save new values now if we stored a "SaveCount" marker |
| 1726 |
if ($$_{SaveCount}) { |
| 1727 |
$saveCount = $mt->SaveNewValues(); |
| 1728 |
$needSave = 0; |
| 1729 |
# insert marker to load values from CSV file now if this was the CSV file |
| 1730 |
push @dynamicFiles, \$csv if $$_{SaveCount} == $dbSaveCount; |
| 1731 |
} |
| 1732 |
next; |
| 1733 |
} |
| 1734 |
/(.*?)=(.*)/s or next; |
| 1735 |
my ($tag, $newVal) = ($1, $2); |
| 1736 |
$tag =~ s/\ball\b/\*/ig; # replace 'all' with '*' in tag names |
| 1737 |
$newVal eq '' and undef $newVal unless $tag =~ s/\^([-+]*)$/$1/; # undefined to delete tag |
| 1738 |
if ($tag =~ /^(All)?TagsFromFile$/i) { |
| 1739 |
defined $newVal or Error("Need file name for -tagsFromFile\n"), next Command; |
| 1740 |
++$isWriting; |
| 1741 |
if ($newVal eq '@' or not defined FilenameSPrintf($newVal) or |
| 1742 |
# can't set tags yet if we are using tags from other files with the -fileNUM option |
| 1743 |
grep /\bfile\d+:/i, @{$setTags{$newVal}}) |
| 1744 |
{ |
| 1745 |
push @dynamicFiles, $newVal; |
| 1746 |
next; # set tags from dynamic file later |
| 1747 |
} |
| 1748 |
unless ($mt->Exists($newVal) or $newVal eq '-') { |
| 1749 |
Error "File '${newVal}' does not exist for -tagsFromFile option\n"; |
| 1750 |
next Command; |
| 1751 |
} |
| 1752 |
my $setTags = $setTags{$newVal}; |
| 1753 |
# do we have multiple -tagsFromFile options with this file? |
| 1754 |
if ($setTagsList{$newVal}) { |
| 1755 |
# use the tags set in the i-th occurrence |
| 1756 |
my $i = $setTagsIndex{$newVal} || 0; |
| 1757 |
$setTagsIndex{$newVal} = $i + 1; |
| 1758 |
$setTags = $setTagsList{$newVal}[$i] if $setTagsList{$newVal}[$i]; |
| 1759 |
} |
| 1760 |
# set specified tags from this file |
| 1761 |
unless (DoSetFromFile($mt, $newVal, $setTags)) { |
| 1762 |
$rtnVal = 1; |
| 1763 |
next Command; |
| 1764 |
} |
| 1765 |
$needSave = 1; |
| 1766 |
next; |
| 1767 |
} |
| 1768 |
my %opts = ( Shift => 0 ); # shift values if possible instead of adding/deleting |
| 1769 |
# allow writing of 'Unsafe' tags unless specified by wildcard |
| 1770 |
$opts{Protected} = 1 unless $tag =~ /[?*]/; |
| 1771 |
|
| 1772 |
if ($tag =~ s/<// and defined $newVal) { |
| 1773 |
if (defined FilenameSPrintf($newVal)) { |
| 1774 |
SlurpFile($newVal, \$newVal) or next; # read file data into $newVal |
| 1775 |
} else { |
| 1776 |
$tag =~ s/([-+]|\xe2\x88\x92)$// and $opts{$addDelOpt{$1}} = 1; |
| 1777 |
# verify that this tag can be written |
| 1778 |
my $result = Image::ExifTool::IsWritable($tag); |
| 1779 |
if ($result) { |
| 1780 |
$opts{ProtectSaved} = $saveCount; # protect new values set after this |
| 1781 |
# add to list of dynamic tag values |
| 1782 |
push @dynamicFiles, [ $tag, $newVal, \%opts ]; |
| 1783 |
++$isWriting; |
| 1784 |
} elsif (defined $result) { |
| 1785 |
Warn "Tag '${tag}' is not writable\n"; |
| 1786 |
} else { |
| 1787 |
Warn "Tag '${tag}' does not exist\n"; |
| 1788 |
} |
| 1789 |
next; |
| 1790 |
} |
| 1791 |
} |
| 1792 |
if ($tag =~ s/([-+]|\xe2\x88\x92)$//) { |
| 1793 |
$opts{$addDelOpt{$1}} = 1; # set AddValue or DelValue option |
| 1794 |
# set $newVal to '' if deleting nothing |
| 1795 |
$newVal = '' if $1 eq '-' and not defined $newVal; |
| 1796 |
} |
| 1797 |
if ($escapeC and defined $newVal) { |
| 1798 |
$newVal =~ s/\\(x([0-9a-fA-F]{2})|.)/$2 ? chr(hex($2)) : $unescC{$1} || $1/seg; |
| 1799 |
} |
| 1800 |
my ($rtn, $wrn) = $mt->SetNewValue($tag, $newVal, %opts); |
| 1801 |
$needSave = 1; |
| 1802 |
++$isWriting if $rtn; |
| 1803 |
$wrn and Warning($mt, $wrn); |
| 1804 |
} |
| 1805 |
# exclude specified tags |
| 1806 |
foreach (@exclude) { |
| 1807 |
$mt->SetNewValue($_, undef, Replace => 2); |
| 1808 |
$needSave = 1; |
| 1809 |
} |
| 1810 |
unless ($isWriting or $outOpt or @tags) { |
| 1811 |
Error "Nothing to do.\n"; |
| 1812 |
next; |
| 1813 |
} |
| 1814 |
} elsif (grep /^(\*:)?\*$/, @exclude) { |
| 1815 |
Error "All tags excluded -- nothing to do.\n"; |
| 1816 |
next; |
| 1817 |
} |
| 1818 |
if ($isWriting) { |
| 1819 |
if (defined $diff) { |
| 1820 |
Error "Can't use -diff option when writing tags\n"; |
| 1821 |
next; |
| 1822 |
} elsif ($plot) { |
| 1823 |
Error "Can't use -plot option when writing tags\n"; |
| 1824 |
next; |
| 1825 |
} elsif (@tags and not $outOpt and not $csv) { |
| 1826 |
my ($tg, $s) = @tags > 1 ? ("$tags[0] ...", 's') : ($tags[0], ''); |
| 1827 |
Warn "Ignored superfluous tag name$s or invalid option$s: -$tg\n"; |
| 1828 |
} |
| 1829 |
} |
| 1830 |
# save current state of new values if setting values from target file |
| 1831 |
# or if we may be translating to a different format |
| 1832 |
$mt->SaveNewValues() if $outOpt or (@dynamicFiles and $needSave); |
| 1833 |
|
| 1834 |
$multiFile = 1 if @files > 1; |
| 1835 |
@exclude and $mt->Options(Exclude => \@exclude); |
| 1836 |
|
| 1837 |
undef $binaryOutput if $html; |
| 1838 |
|
| 1839 |
if ($binaryOutput) { |
| 1840 |
$outFormat = 99; # shortest possible output format |
| 1841 |
$mt->Options(PrintConv => 0); |
| 1842 |
unless ($textOut or $binaryStdout) { |
| 1843 |
binmode(STDOUT); |
| 1844 |
$binaryStdout = 1; |
| 1845 |
$mt->Options(TextOut => ($vout = \*STDERR)); |
| 1846 |
} |
| 1847 |
# disable conflicting options |
| 1848 |
undef $showGroup; |
| 1849 |
} |
| 1850 |
|
| 1851 |
# sort by groups to look nicer depending on options |
| 1852 |
if (defined $showGroup and not (@tags and ($allGroup or $csv)) and ($sortOpt or not defined $sortOpt)) { |
| 1853 |
$mt->Options(Sort => "Group$showGroup"); |
| 1854 |
} |
| 1855 |
|
| 1856 |
if ($textOut) { |
| 1857 |
CleanFilename($textOut); # make all forward slashes |
| 1858 |
# add '.' before output extension if necessary |
| 1859 |
$textOut = ".$textOut" unless $textOut =~ /[.%]/ or defined $tagOut; |
| 1860 |
} |
| 1861 |
|
| 1862 |
# determine if we should scan for only writable files |
| 1863 |
if ($outOpt) { |
| 1864 |
my $type = GetFileType($outOpt); |
| 1865 |
if ($type) { |
| 1866 |
# (must test original file name because we can write .webp but not other RIFF types) |
| 1867 |
my $canWrite = CanWrite($outOpt); |
| 1868 |
unless ($canWrite) { |
| 1869 |
if (defined $canWrite and $canWrite eq '') { |
| 1870 |
$type = Image::ExifTool::GetFileExtension($outOpt); |
| 1871 |
$type = uc($outOpt) unless defined $type; |
| 1872 |
} |
| 1873 |
Error "Can't write $type files\n"; |
| 1874 |
next; |
| 1875 |
} |
| 1876 |
$scanWritable = $type unless CanCreate($type); |
| 1877 |
} else { |
| 1878 |
$scanWritable = 1; |
| 1879 |
} |
| 1880 |
$isWriting = 1; # set writing flag |
| 1881 |
} elsif ($isWriting or defined $deleteOrig) { |
| 1882 |
$scanWritable = 1; |
| 1883 |
} |
| 1884 |
|
| 1885 |
# initialize alternate encoding flag |
| 1886 |
$altEnc = $mt->Options('Charset'); |
| 1887 |
undef $altEnc if $altEnc eq 'UTF8'; |
| 1888 |
|
| 1889 |
# set flag to fix description lengths if necessary |
| 1890 |
if (not $altEnc and $mt->Options('Lang') ne 'en') { |
| 1891 |
# (note that Unicode::GCString is part of the Unicode::LineBreak package) |
| 1892 |
$fixLen = eval { require Unicode::GCString } ? 2 : 1; |
| 1893 |
} |
| 1894 |
|
| 1895 |
# sort input files if specified |
| 1896 |
if (@fileOrder) { |
| 1897 |
my @allFiles; |
| 1898 |
ProcessFiles($mt, \@allFiles); |
| 1899 |
my $sortTool = Image::ExifTool->new; |
| 1900 |
$sortTool->Options(FastScan => $fileOrderFast) if $fileOrderFast; |
| 1901 |
$sortTool->Options(PrintConv => $mt->Options('PrintConv')); |
| 1902 |
$sortTool->Options(Duplicates => 0); |
| 1903 |
my (%sortBy, %isFloat, @rev, $file); |
| 1904 |
# save reverse sort flags |
| 1905 |
push @rev, (s/^-// ? 1 : 0) foreach @fileOrder; |
| 1906 |
foreach $file (@allFiles) { |
| 1907 |
my @tags; |
| 1908 |
my $info = $sortTool->ImageInfo(Infile($file,1), @fileOrder, \@tags); |
| 1909 |
# get values of all tags (or '~' to sort last if not defined) |
| 1910 |
foreach (@tags) { |
| 1911 |
$_ = $$info{$_}; # put tag value into @tag list |
| 1912 |
defined $_ or $_ = '~', next; |
| 1913 |
$isFloat{$_} = Image::ExifTool::IsFloat($_); |
| 1914 |
# pad numbers to 12 digits to keep them sequential |
| 1915 |
s/(\d+)/(length($1) < 12 ? '0'x(12-length($1)) : '') . $1/eg unless $isFloat{$_}; |
| 1916 |
} |
| 1917 |
$sortBy{$file} = \@tags; # save tag values for each file |
| 1918 |
} |
| 1919 |
# sort in specified order |
| 1920 |
@files = sort { |
| 1921 |
my ($i, $cmp); |
| 1922 |
for ($i=0; $i<@rev; ++$i) { |
| 1923 |
my $u = $sortBy{$a}[$i]; |
| 1924 |
my $v = $sortBy{$b}[$i]; |
| 1925 |
if (not $isFloat{$u} and not $isFloat{$v}) { |
| 1926 |
$cmp = $u cmp $v; # alphabetically |
| 1927 |
} elsif ($isFloat{$u} and $isFloat{$v}) { |
| 1928 |
$cmp = $u <=> $v; # numerically |
| 1929 |
} else { |
| 1930 |
$cmp = $isFloat{$u} ? -1 : 1; # numbers first |
| 1931 |
} |
| 1932 |
return $rev[$i] ? -$cmp : $cmp if $cmp; |
| 1933 |
} |
| 1934 |
return $a cmp $b; # default to sort by name |
| 1935 |
} @allFiles; |
| 1936 |
} elsif (defined $progress) { |
| 1937 |
# expand FILE argument to count the number of files to process |
| 1938 |
my @allFiles; |
| 1939 |
ProcessFiles($mt, \@allFiles); |
| 1940 |
@files = @allFiles; |
| 1941 |
} |
| 1942 |
# set file count for progress message |
| 1943 |
$progressMax = scalar @files if defined $progress; |
| 1944 |
|
| 1945 |
# store duplicate database information under absolute path and with standardized case |
| 1946 |
my @dbKeys = keys %database; |
| 1947 |
if (@dbKeys) { |
| 1948 |
if (eval { require Cwd }) { |
| 1949 |
undef $evalWarning; |
| 1950 |
local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; |
| 1951 |
foreach (@dbKeys) { |
| 1952 |
my $db = $database{$_}; |
| 1953 |
tr/\\/\// and $database{$_} = $db; # allow for backslashes in SourceFile |
| 1954 |
$database{lc} = $db unless $database{lc}; # duplicate entry with lower case |
| 1955 |
# (punt on using ConvertFileName here, so $absPath may be a mix of encodings) |
| 1956 |
my $absPath = AbsPath($_); |
| 1957 |
if (defined $absPath) { |
| 1958 |
$database{$absPath} = $db unless $database{$absPath}; |
| 1959 |
if ($verbose and $verbose > 1) { |
| 1960 |
print $vout "Imported entry for '${_}' (full path: '${absPath}')\n"; |
| 1961 |
} |
| 1962 |
$database{lc $absPath} = $db unless $database{lc $absPath}; |
| 1963 |
} elsif ($verbose and $verbose > 1) { |
| 1964 |
print $vout "Imported entry for '${_}' (no full path)\n"; |
| 1965 |
} |
| 1966 |
} |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
# process all specified files |
| 1971 |
ProcessFiles($mt); |
| 1972 |
|
| 1973 |
Error "No file with specified extension\n" if $filtered and not $validFile; |
| 1974 |
|
| 1975 |
# print folder/file trailer if necessary |
| 1976 |
if ($textOut) { |
| 1977 |
foreach (keys %outTrailer) { |
| 1978 |
next unless $outTrailer{$_}; |
| 1979 |
if ($mt->Open(\*OUTTRAIL, $_, '>>')) { |
| 1980 |
my $fp = \*OUTTRAIL; |
| 1981 |
print $fp $outTrailer{$_}; |
| 1982 |
close $fp; |
| 1983 |
} else { |
| 1984 |
Error("Error appending to $_\n"); |
| 1985 |
} |
| 1986 |
} |
| 1987 |
} else { |
| 1988 |
print $sectTrailer if $sectTrailer; |
| 1989 |
print $fileTrailer if $fileTrailer and not $fileHeader; |
| 1990 |
# print CSV or SVG output file if necessary |
| 1991 |
my ($fp, $err); |
| 1992 |
if ($textOut2) { |
| 1993 |
if ($mt->Open(\*OUTFILE, $textOut2, '>')) { |
| 1994 |
$fp = \*OUTFILE; |
| 1995 |
} else { |
| 1996 |
Error("Error creating $textOut2\n"); |
| 1997 |
$err = 1; |
| 1998 |
} |
| 1999 |
} |
| 2000 |
unless ($err) { |
| 2001 |
PrintCSV($fp) if $csv and not $isWriting; |
| 2002 |
# print SVG plot |
| 2003 |
if ($plot) { |
| 2004 |
$plot->Draw($fp || \*STDOUT); |
| 2005 |
if ($$plot{Error}) { |
| 2006 |
Error("Error: $$plot{Error}\n"); |
| 2007 |
$err = 1; |
| 2008 |
} elsif ($$plot{Warn}) { |
| 2009 |
Warn("Warning: $$plot{Warn}\n"); |
| 2010 |
} |
| 2011 |
} |
| 2012 |
} |
| 2013 |
if ($fp) { |
| 2014 |
close($fp) or $err = 1; |
| 2015 |
if ($err) { |
| 2016 |
$mt->Unlink($textOut2); |
| 2017 |
} else { |
| 2018 |
$created{$textOut2} = 1; |
| 2019 |
} |
| 2020 |
} |
| 2021 |
} |
| 2022 |
|
| 2023 |
my $totWr = $countGoodWr + $countBadWr + $countSameWr + $countCopyWr + |
| 2024 |
$countGoodCr + $countBadCr; |
| 2025 |
|
| 2026 |
if (defined $deleteOrig) { |
| 2027 |
|
| 2028 |
# print summary and delete requested files |
| 2029 |
unless ($quiet) { |
| 2030 |
printf "%5d directories scanned\n", $countDir if $countDir; |
| 2031 |
printf "%5d directories created\n", $countNewDir if $countNewDir; |
| 2032 |
printf "%5d files failed condition\n", $countFailed if $countFailed; |
| 2033 |
printf "%5d image files found\n", $count; |
| 2034 |
} |
| 2035 |
if (@delFiles) { |
| 2036 |
# verify deletion unless "-delete_original!" was specified |
| 2037 |
if ($deleteOrig == 1) { |
| 2038 |
printf '%5d originals will be deleted! Are you sure [y/n]? ', scalar(@delFiles); |
| 2039 |
my $response = <STDIN>; |
| 2040 |
unless ($response =~ /^(y|yes)\s*$/i) { |
| 2041 |
Warn "Originals not deleted.\n"; |
| 2042 |
next; |
| 2043 |
} |
| 2044 |
} |
| 2045 |
$countGoodWr = $mt->Unlink(@delFiles); |
| 2046 |
$countBad = scalar(@delFiles) - $countGoodWr; |
| 2047 |
} |
| 2048 |
if ($quiet) { |
| 2049 |
# no more messages |
| 2050 |
} elsif ($count and not $countGoodWr and not $countBad) { |
| 2051 |
printf "%5d original files found\n", $countGoodWr; # (this will be 0) |
| 2052 |
} elsif ($deleteOrig) { |
| 2053 |
printf "%5d original files deleted\n", $countGoodWr if $count; |
| 2054 |
printf "%5d originals not deleted due to errors\n", $countBad if $countBad; |
| 2055 |
} else { |
| 2056 |
printf "%5d image files restored from original\n", $countGoodWr if $count; |
| 2057 |
printf "%5d files not restored due to errors\n", $countBad if $countBad; |
| 2058 |
} |
| 2059 |
|
| 2060 |
} elsif ((not $binaryStdout or $verbose) and not $quiet) { |
| 2061 |
|
| 2062 |
# print summary |
| 2063 |
my $tot = $count + $countBad; |
| 2064 |
if ($countDir or $totWr or $countFailed or $tot > 1 or $textOut or %countLink) { |
| 2065 |
my $o = (($html or $json or $xml or %printFmt or $csv or $plot) and not $textOut) ? \*STDERR : $vout; |
| 2066 |
printf($o "%5d directories scanned\n", $countDir) if $countDir; |
| 2067 |
printf($o "%5d directories created\n", $countNewDir) if $countNewDir; |
| 2068 |
printf($o "%5d files failed condition\n", $countFailed) if $countFailed; |
| 2069 |
printf($o "%5d image files created\n", $countGoodCr) if $countGoodCr; |
| 2070 |
printf($o "%5d image files updated\n", $countGoodWr) if $totWr - $countGoodCr - $countBadCr - $countCopyWr; |
| 2071 |
printf($o "%5d image files unchanged\n", $countSameWr) if $countSameWr; |
| 2072 |
printf($o "%5d image files %s\n", $countCopyWr, $overwriteOrig ? 'moved' : 'copied') if $countCopyWr; |
| 2073 |
printf($o "%5d files weren't updated due to errors\n", $countBadWr) if $countBadWr; |
| 2074 |
printf($o "%5d files weren't created due to errors\n", $countBadCr) if $countBadCr; |
| 2075 |
printf($o "%5d image files read\n", $count) if ($tot+$countFailed)>1 or ($countDir and not $totWr); |
| 2076 |
printf($o "%5d files could not be read\n", $countBad) if $countBad; |
| 2077 |
printf($o "%5d output files created\n", scalar(keys %created)) if $textOut or $textOut2; |
| 2078 |
printf($o "%5d output files appended\n", scalar(keys %appended)) if %appended; |
| 2079 |
printf($o "%5d hard links created\n", $countLink{Hard} || 0) if $countLink{Hard} or $countLink{BadHard}; |
| 2080 |
printf($o "%5d hard links could not be created\n", $countLink{BadHard}) if $countLink{BadHard}; |
| 2081 |
printf($o "%5d symbolic links created\n", $countLink{Sym} || 0) if $countLink{Sym} or $countLink{BadSym}; |
| 2082 |
printf($o "%5d symbolic links could not be created\n", $countLink{BadSym}) if $countLink{BadSym}; |
| 2083 |
} |
| 2084 |
} |
| 2085 |
|
| 2086 |
# set error status if we had any errors or if all files failed the "-if" condition |
| 2087 |
if ($countBadWr or $countBadCr or $countBad) { |
| 2088 |
$rtnVal = 1; |
| 2089 |
} elsif ($countFailed and not ($count or $totWr) and not $rtnVal) { |
| 2090 |
$rtnVal = 2; |
| 2091 |
} |
| 2092 |
|
| 2093 |
Image::ExifTool::Purge(0) if $purge; # do final purging |
| 2094 |
|
| 2095 |
# clean up after each command |
| 2096 |
Cleanup(); |
| 2097 |
|
| 2098 |
} # end "Command" loop ........................................................ |
| 2099 |
|
| 2100 |
close STAYOPEN if $stayOpen >= 2; |
| 2101 |
|
| 2102 |
Exit $rtnValApp; # all done |
| 2103 |
|
| 2104 |
|
| 2105 |
#------------------------------------------------------------------------------ |
| 2106 |
# Get image information from EXIF data in file (or write file if writing) |
| 2107 |
# Inputs: 0) ExifTool object reference, 1) file name |
| 2108 |
sub GetImageInfo($$) |
| 2109 |
{ |
| 2110 |
my ($et, $orig) = @_; |
| 2111 |
my (@foundTags, @found2, $info, $info2, $et2, $file, $file2, $ind, $g8); |
| 2112 |
|
| 2113 |
# set window title for this file if necessary |
| 2114 |
if (defined $windowTitle) { |
| 2115 |
if ($progressCount >= $progressNext) { |
| 2116 |
my $prog = $progressMax ? "$progressCount/$progressMax" : '0/0'; |
| 2117 |
my $title = $windowTitle; |
| 2118 |
my ($num, $denom) = split '/', $prog; |
| 2119 |
my $frac = $num / ($denom || 1); |
| 2120 |
my $n = $title =~ s/%(\d+)b/%b/ ? $1 : 20; # length of bar |
| 2121 |
my $bar = int($frac * $n + 0.5); |
| 2122 |
my %lkup = ( |
| 2123 |
b => ('I' x $bar) . ('.' x ($n - $bar)), |
| 2124 |
f => $orig, |
| 2125 |
p => int(100 * $frac + 0.5), |
| 2126 |
r => $prog, |
| 2127 |
'%'=> '%', |
| 2128 |
); |
| 2129 |
$title =~ s/%([%bfpr])/$lkup{$1}/eg; |
| 2130 |
SetWindowTitle($title); |
| 2131 |
if (defined $progressMax) { |
| 2132 |
undef $progressNext; |
| 2133 |
} else { |
| 2134 |
$progressNext += $progressIncr; |
| 2135 |
} |
| 2136 |
} |
| 2137 |
# ($progressMax is not defined for "-progress:%f") |
| 2138 |
++$progressCount unless defined $progressMax; |
| 2139 |
} |
| 2140 |
unless (length $orig or $outOpt) { |
| 2141 |
Warn qq(Error: Zero-length file name - ""\n); |
| 2142 |
++$countBad; |
| 2143 |
return; |
| 2144 |
} |
| 2145 |
# determine the name of the source file based on the original input file name |
| 2146 |
if (@srcFmt) { |
| 2147 |
my ($fmt, $first); |
| 2148 |
foreach $fmt (@srcFmt) { |
| 2149 |
$file = $fmt eq '@' ? $orig : FilenameSPrintf($fmt, $orig); |
| 2150 |
# use this file if it exists |
| 2151 |
$et->Exists($file) and undef($first), last; |
| 2152 |
$verbose and print $vout "Source file $file does not exist\n"; |
| 2153 |
$first = $file unless defined $first; |
| 2154 |
} |
| 2155 |
$file = $first if defined $first; |
| 2156 |
my ($d, $f) = Image::ExifTool::SplitFileName($orig); |
| 2157 |
$et->Options(UserParam => "OriginalDirectory#=$d"); |
| 2158 |
$et->Options(UserParam => "OriginalFileName#=$f"); |
| 2159 |
} else { |
| 2160 |
$file = $orig; |
| 2161 |
} |
| 2162 |
# set alternate file names |
| 2163 |
foreach $g8 (sort keys %altFile) { |
| 2164 |
my $altName = $orig; |
| 2165 |
unless ($altFile{$g8} eq '@') { |
| 2166 |
# must double any '$' symbols in the original file name because |
| 2167 |
# they are used for tag names in a -fileNUM argument |
| 2168 |
$altName =~ s/\$/\$\$/g; |
| 2169 |
$altName = FilenameSPrintf($altFile{$g8}, $altName); |
| 2170 |
} |
| 2171 |
$et->SetAlternateFile($g8, $altName); |
| 2172 |
} |
| 2173 |
|
| 2174 |
my $pipe = $file; |
| 2175 |
if ($doUnzip) { |
| 2176 |
# pipe through gzip or bzip2 if necessary |
| 2177 |
if ($file =~ /\.(gz|bz2)$/i) { |
| 2178 |
my $type = lc $1; |
| 2179 |
if ($file =~ /[^-_.'A-Za-z0-9\/\\]/) { |
| 2180 |
Warn "Error: Insecure zip file name. Skipped\n"; |
| 2181 |
EFile($file); |
| 2182 |
++$countBad; |
| 2183 |
return; |
| 2184 |
} |
| 2185 |
if ($type eq 'gz') { |
| 2186 |
$pipe = qq{gzip -dc "$file" |}; |
| 2187 |
} else { |
| 2188 |
$pipe = qq{bzip2 -dc "$file" |}; |
| 2189 |
} |
| 2190 |
$$et{TRUST_PIPE} = 1; |
| 2191 |
} |
| 2192 |
} |
| 2193 |
# evaluate -if expression for conditional processing |
| 2194 |
if (@condition) { |
| 2195 |
my $result; |
| 2196 |
unless ($failCondition) { |
| 2197 |
# catch run time errors as well as compile errors |
| 2198 |
undef $evalWarning; |
| 2199 |
local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; |
| 2200 |
|
| 2201 |
my (%info, $condition); |
| 2202 |
# extract information and build expression for evaluation |
| 2203 |
my $opts = { Duplicates => 1, RequestTags => \@requestTags, Verbose => 0, HtmlDump => 0 }; |
| 2204 |
$$opts{FastScan} = $fastCondition if defined $fastCondition; |
| 2205 |
# return all tags but explicitly mention tags on command line so |
| 2206 |
# requested images will generate the appropriate warnings |
| 2207 |
@foundTags = ('*', @tags) if @tags; |
| 2208 |
$info = $et->ImageInfo(Infile($pipe,$isWriting), \@foundTags, $opts); |
| 2209 |
foreach $condition (@condition) { |
| 2210 |
my $cond = $et->InsertTagValues($condition, \@foundTags, \%info); |
| 2211 |
{ |
| 2212 |
# set package so eval'd functions are in Image::ExifTool namespace |
| 2213 |
package Image::ExifTool; |
| 2214 |
|
| 2215 |
my $self = $et; |
| 2216 |
#### eval "-if" condition (%info, $self) |
| 2217 |
$result = eval $cond; |
| 2218 |
|
| 2219 |
$@ and $evalWarning = $@; |
| 2220 |
} |
| 2221 |
if ($evalWarning) { |
| 2222 |
# fail condition if warning is issued |
| 2223 |
undef $result; |
| 2224 |
if ($verbose) { |
| 2225 |
chomp $evalWarning; |
| 2226 |
$evalWarning =~ s/ at \(eval .*//s; |
| 2227 |
Warn "Condition: $evalWarning - $file\n"; |
| 2228 |
} |
| 2229 |
} |
| 2230 |
last unless $result; |
| 2231 |
} |
| 2232 |
undef @foundTags if $fastCondition; # ignore if we didn't get all tags |
| 2233 |
} |
| 2234 |
if ($result) { |
| 2235 |
# discard $info for non-existent file |
| 2236 |
undef $info unless $file eq '-' or $et->Exists($file); |
| 2237 |
} else { |
| 2238 |
Progress($vout, "-------- $file (failed condition)") if $verbose; |
| 2239 |
EFile($file, 2); |
| 2240 |
++$countFailed; |
| 2241 |
return; |
| 2242 |
} |
| 2243 |
# can't make use of $info if verbose because we must reprocess |
| 2244 |
# the file anyway to generate the verbose output |
| 2245 |
# (also if writing just to avoid double-incrementing FileSequence) |
| 2246 |
if ($isWriting or $verbose or defined $fastCondition or defined $diff) { |
| 2247 |
undef $info; |
| 2248 |
--$$et{FILE_SEQUENCE}; |
| 2249 |
} |
| 2250 |
} elsif ($file =~ s/^(\@JSON:)(.*)/$1/) { |
| 2251 |
# read JSON file from command line |
| 2252 |
my $dat = $2; |
| 2253 |
$info = $et->ImageInfo(\$dat, \@foundTags); |
| 2254 |
if ($geoOnly) { /^Geolocation/ or delete $$info{$_} foreach keys %$info; $file = ' ' } |
| 2255 |
} |
| 2256 |
if (defined $deleteOrig) { |
| 2257 |
Progress($vout, "======== $file") if defined $verbose; |
| 2258 |
++$count; |
| 2259 |
my $original = "${file}_original"; |
| 2260 |
$et->Exists($original) or return; |
| 2261 |
if ($deleteOrig) { |
| 2262 |
$verbose and print $vout "Scheduled for deletion: $original\n"; |
| 2263 |
push @delFiles, $original; |
| 2264 |
} elsif ($et->Rename($original, $file)) { |
| 2265 |
$verbose and print $vout "Restored from $original\n"; |
| 2266 |
EFile($file, 3); |
| 2267 |
++$countGoodWr; |
| 2268 |
} else { |
| 2269 |
Warn "Error renaming $original\n"; |
| 2270 |
EFile($file); |
| 2271 |
++$countBad; |
| 2272 |
} |
| 2273 |
return; |
| 2274 |
} |
| 2275 |
++$seqFileNum; # increment our file counter |
| 2276 |
my ($dir) = Image::ExifTool::SplitFileName($orig); |
| 2277 |
$seqFileDir = $seqFileDir{$dir} = ($seqFileDir{$dir} || 0) + 1; |
| 2278 |
|
| 2279 |
my $lineCount = 0; |
| 2280 |
my ($fp, $outfile, $append); |
| 2281 |
if ($textOut and ($verbose or $et->Options('PrintCSV')) and not ($tagOut or defined $diff or $plot)) { |
| 2282 |
($fp, $outfile, $append) = OpenOutputFile($orig); |
| 2283 |
$fp or EFile($file), ++$countBad, return; |
| 2284 |
# delete file if we exit prematurely (unless appending) |
| 2285 |
$tmpText = $outfile unless $append; |
| 2286 |
$et->Options(TextOut => $fp); |
| 2287 |
} |
| 2288 |
|
| 2289 |
if ($isWriting) { |
| 2290 |
Progress($vout, "======== $file") if defined $verbose; |
| 2291 |
SetImageInfo($et, $file, $orig); |
| 2292 |
$info = $et->GetInfo('Warning', 'Error'); |
| 2293 |
PrintErrors($et, $info, $file); |
| 2294 |
# close output text file if necessary |
| 2295 |
if (defined $outfile) { |
| 2296 |
undef $tmpText; |
| 2297 |
close($fp); |
| 2298 |
$et->Options(TextOut => $vout); |
| 2299 |
if ($info->{Error}) { |
| 2300 |
$et->Unlink($outfile); # erase bad file |
| 2301 |
} elsif ($append) { |
| 2302 |
$appended{$outfile} = 1 unless $created{$outfile}; |
| 2303 |
} else { |
| 2304 |
$created{$outfile} = 1; |
| 2305 |
} |
| 2306 |
} |
| 2307 |
return; |
| 2308 |
} |
| 2309 |
|
| 2310 |
# extract information from this file |
| 2311 |
unless ($file eq '-' or $et->Exists($file) or $info) { |
| 2312 |
Warn "Error: File not found - $file\n"; |
| 2313 |
FileNotFound($file); |
| 2314 |
defined $outfile and close($fp), undef($tmpText), $et->Unlink($outfile); |
| 2315 |
EFile($file); |
| 2316 |
++$countBad; |
| 2317 |
return; |
| 2318 |
} |
| 2319 |
# print file/progress message |
| 2320 |
my $o; |
| 2321 |
unless ($binaryOutput or $textOut or %printFmt or $html > 1 or $csv or $plot) { |
| 2322 |
if ($html) { |
| 2323 |
require Image::ExifTool::HTML; |
| 2324 |
my $f = Image::ExifTool::HTML::EscapeHTML($file); |
| 2325 |
print "<!-- $f -->\n"; |
| 2326 |
} elsif (not ($json or $xml or defined $diff)) { |
| 2327 |
$o = \*STDOUT if ($multiFile and not $quiet) or $progress; |
| 2328 |
} |
| 2329 |
} |
| 2330 |
$o = \*STDERR if $progress and not $o; |
| 2331 |
Progress($o, "======== $file") if $o; |
| 2332 |
if ($info) { |
| 2333 |
# get the information we wanted |
| 2334 |
if (@tags and not %printFmt) { |
| 2335 |
@foundTags = @tags; |
| 2336 |
$info = $et->GetInfo(\@foundTags); |
| 2337 |
} |
| 2338 |
} else { |
| 2339 |
# request specified tags unless using print format option |
| 2340 |
my $oldDups = $et->Options('Duplicates'); |
| 2341 |
if (%printFmt) { |
| 2342 |
$et->Options(Duplicates => 1); |
| 2343 |
$et->Options(RequestTags => \@requestTags); |
| 2344 |
if ($printFmt{SetTags}) { |
| 2345 |
# initialize options so we can set any tags we want |
| 2346 |
$$et{TAGS_FROM_FILE} = 1; |
| 2347 |
$et->Options(MakerNotes => 1); |
| 2348 |
$et->Options(Struct => 2); |
| 2349 |
$et->Options(List => 1); |
| 2350 |
$et->Options(CoordFormat => '%d %d %.8f') unless $et->Options('CoordFormat'); |
| 2351 |
} |
| 2352 |
} else { |
| 2353 |
@foundTags = @tags; |
| 2354 |
} |
| 2355 |
if (defined $diff) { |
| 2356 |
$file2 = FilenameSPrintf($diff, $orig); |
| 2357 |
if ($file eq $file2) { |
| 2358 |
Warn "Error: Diffing file with itself - $file2\n"; |
| 2359 |
EFile($file); |
| 2360 |
++$countBad; |
| 2361 |
return; |
| 2362 |
} |
| 2363 |
if ($et->Exists($file2)) { |
| 2364 |
$showGroup = 1 unless defined $showGroup; |
| 2365 |
$allGroup = 1 unless defined $allGroup; |
| 2366 |
$et->Options(Duplicates => 1, Sort => "Group$showGroup", Verbose => 0); |
| 2367 |
$et2 = Image::ExifTool->new; |
| 2368 |
$et2->Options(%{$$et{OPTIONS}}); |
| 2369 |
# must set list options specifically because they may have been |
| 2370 |
# set incorrectly from deprecated List settings |
| 2371 |
$et2->Options(ListSep => $$et{OPTIONS}{ListSep}); |
| 2372 |
$et2->Options(ListSplit => $$et{OPTIONS}{ListSplit}); |
| 2373 |
@found2 = @foundTags; |
| 2374 |
$info2 = $et2->ImageInfo($file2, \@found2); |
| 2375 |
} else { |
| 2376 |
$info2 = { Error => "Diff file not found" }; |
| 2377 |
} |
| 2378 |
if ($$info2{Error}) { |
| 2379 |
Warn "Error: $$info2{Error} - $file2\n"; |
| 2380 |
EFile($file); |
| 2381 |
++$countBad; |
| 2382 |
return; |
| 2383 |
} |
| 2384 |
} |
| 2385 |
# extract the information |
| 2386 |
$info = $et->ImageInfo(Infile($pipe), \@foundTags); |
| 2387 |
$et->Options(Duplicates => $oldDups); |
| 2388 |
} |
| 2389 |
|
| 2390 |
# all done now if we already wrote output text file (eg. verbose option) |
| 2391 |
if ($fp) { |
| 2392 |
if (defined $outfile) { |
| 2393 |
$et->Options(TextOut => \*STDOUT); |
| 2394 |
undef $tmpText; |
| 2395 |
if ($info->{Error}) { |
| 2396 |
close($fp); |
| 2397 |
$et->Unlink($outfile); # erase bad file |
| 2398 |
} else { |
| 2399 |
++$lineCount; # output text file (likely) is not empty |
| 2400 |
} |
| 2401 |
} |
| 2402 |
if ($info->{Error}) { |
| 2403 |
Warn "Error: $$info{Error} - $file\n"; |
| 2404 |
EFile($file); |
| 2405 |
++$countBad; |
| 2406 |
return; |
| 2407 |
} |
| 2408 |
} |
| 2409 |
|
| 2410 |
# print warnings to stderr if using binary output |
| 2411 |
# (because we are likely ignoring them and piping stdout to file) |
| 2412 |
# or if there is none of the requested information available |
| 2413 |
if ($binaryOutput or not %$info) { |
| 2414 |
my $errs = $et->GetInfo('Warning', 'Error'); |
| 2415 |
PrintErrors($et, $errs, $file) and EFile($file), $rtnVal = 1; |
| 2416 |
} elsif ($et->GetValue('Error') or ($$et{Validate} and $et->GetValue('Warning'))) { |
| 2417 |
$rtnVal = 1; |
| 2418 |
} |
| 2419 |
|
| 2420 |
# open output file (or stdout if no output file) if not done already |
| 2421 |
unless (defined $outfile or $tagOut) { |
| 2422 |
($fp, $outfile, $append) = OpenOutputFile($orig); |
| 2423 |
$fp or EFile($file), ++$countBad, return; |
| 2424 |
$tmpText = $outfile if defined $outfile and not $append; |
| 2425 |
} |
| 2426 |
|
| 2427 |
# print differences if requested |
| 2428 |
if (defined $diff) { |
| 2429 |
my (%done, %done2, $wasDiff, @diffs, @groupTags2); |
| 2430 |
my $v = $verbose || 0; |
| 2431 |
print $fp "======== diff < $file > $file2\n"; |
| 2432 |
my ($g2, $same) = (0, 0); # start with $g2 false, but not equal to '' to avoid infinite loop |
| 2433 |
for (;;) { |
| 2434 |
my ($g, $tag2, $i, $key, @dupl, $val2, $t2, $equal, %used); |
| 2435 |
my $tag = shift @foundTags; |
| 2436 |
if (defined $tag) { |
| 2437 |
$done{$tag} = 1; |
| 2438 |
$g = $et->GetGroup($tag, $showGroup); |
| 2439 |
} else { |
| 2440 |
for (;;) { |
| 2441 |
$tag2 = shift @found2; |
| 2442 |
defined $tag2 or $g = '', last; |
| 2443 |
$done2{$tag2} or $g = $et2->GetGroup($tag2, $showGroup), last; |
| 2444 |
} |
| 2445 |
} |
| 2446 |
if ($g ne $g2) { |
| 2447 |
# add any outstanding tags from diff file not yet handled in previous group ($g2) |
| 2448 |
foreach $t2 (@groupTags2) { |
| 2449 |
next if $done2{$t2}; |
| 2450 |
my $val2 = $et2->GetValue($t2); |
| 2451 |
next unless defined $val2; |
| 2452 |
my $name = $outFormat < 1 ? $et2->GetDescription($t2) : GetTagName($t2); |
| 2453 |
my $len = LengthUTF8($name); |
| 2454 |
my $pad = $outFormat < 2 ? ' ' x ($len < 32 ? 32 - $len : 0) : ''; |
| 2455 |
if ($allGroup) { |
| 2456 |
my $grp = "[$g2]"; |
| 2457 |
$grp .= ' ' x (15 - length($grp)) if length($grp) < 15 and $outFormat < 2; |
| 2458 |
push @diffs, sprintf "> %s %s%s: %s\n", $grp, $name, $pad, Printable($val2); |
| 2459 |
} else { |
| 2460 |
push @diffs, sprintf "> %s%s: %s\n", $name, $pad, Printable($val2); |
| 2461 |
} |
| 2462 |
$done2{$t2} = 1; |
| 2463 |
} |
| 2464 |
my $str = ''; |
| 2465 |
$v and ($same or $v > 1) and $str = " ($same same tag" . ($same==1 ? '' : 's') . ')'; |
| 2466 |
if (not $allGroup) { |
| 2467 |
print $fp "---- $g2 ----$str\n" if $g2 and ($str or @diffs); |
| 2468 |
} elsif ($str and $g2) { |
| 2469 |
printf $fp " %-13s%s\n", $g2, $str; |
| 2470 |
} |
| 2471 |
# print all differences for this group |
| 2472 |
@diffs and print($fp @diffs), $wasDiff = 1, @diffs = (); |
| 2473 |
last unless $g; |
| 2474 |
($g2, $same) = ($g, 0); |
| 2475 |
# build list of all tags in the new group of the diff file |
| 2476 |
@groupTags2 = (); |
| 2477 |
push @groupTags2, $tag2 if defined $tag2; |
| 2478 |
foreach $t2 (@found2) { |
| 2479 |
$done2{$t2} or $g ne $et2->GetGroup($t2, $showGroup) or push @groupTags2, $t2; |
| 2480 |
} |
| 2481 |
} |
| 2482 |
next unless defined $tag; |
| 2483 |
my $val = $et->GetValue($tag); |
| 2484 |
next unless defined $val; # (just in case) |
| 2485 |
my $name = GetTagName($tag); |
| 2486 |
my $desc = $outFormat < 1 ? $et->GetDescription($tag) : $name; |
| 2487 |
# get matching tag key(s) from diff file |
| 2488 |
my @tags2 = grep /^$name( |$)/, @groupTags2; |
| 2489 |
T2: foreach $t2 (@tags2) { |
| 2490 |
next if $done2{$t2}; |
| 2491 |
$tag2 = $t2; |
| 2492 |
$val2 = $et2->GetValue($t2); |
| 2493 |
next unless defined $val2; |
| 2494 |
IsEqual($val, $val2) and $equal = 1, last; |
| 2495 |
# look ahead for upcoming duplicate tags in this group to see |
| 2496 |
# if any would later match this value (and skip those for now) |
| 2497 |
if ($$et{DUPL_TAG}{$name} and not @dupl) { |
| 2498 |
for ($i=0, $key=$name; $i<=$$et{DUPL_TAG}{$name}; ++$i, $key="$name ($i)") { |
| 2499 |
push @dupl, $key unless $done{$key} or $g ne $et->GetGroup($key, $showGroup); |
| 2500 |
} |
| 2501 |
@dupl = sort { $$et{FILE_ORDER}{$a} <=> $$et{FILE_ORDER}{$b} } @dupl if @dupl > 1; |
| 2502 |
} |
| 2503 |
foreach (@dupl) { |
| 2504 |
next if $used{$_}; |
| 2505 |
my $v = $et->GetValue($_); |
| 2506 |
next unless defined($v) and IsEqual($v, $val2); |
| 2507 |
$used{$_} = 1; # would match this upcoming tag |
| 2508 |
undef($tag2); undef($val2); |
| 2509 |
next T2; |
| 2510 |
} |
| 2511 |
last; |
| 2512 |
} |
| 2513 |
if ($equal) { |
| 2514 |
++$same; |
| 2515 |
} else { |
| 2516 |
my $len = LengthUTF8($desc); |
| 2517 |
my $pad = $outFormat < 2 ? ' ' x ($len < 32 ? 32 - $len : 0) : ''; |
| 2518 |
if ($allGroup) { |
| 2519 |
my $grp = "[$g]"; |
| 2520 |
$grp .= ' ' x (15 - length($grp)) if length($grp) < 15 and $outFormat < 2; |
| 2521 |
push @diffs, sprintf "< %s %s%s: %s\n", $grp, $desc, $pad, Printable($val); |
| 2522 |
if (defined $val2) { |
| 2523 |
$grp = ' ' x length($grp), $desc = ' ' x $len if $v < 3; |
| 2524 |
push @diffs, sprintf "> %s %s%s: %s\n", $grp, $desc, $pad, Printable($val2); |
| 2525 |
} |
| 2526 |
} else { |
| 2527 |
push @diffs, sprintf "< %s%s: %s\n", $desc, $pad, Printable($val); |
| 2528 |
$desc = ' ' x $len if $v < 3; |
| 2529 |
push @diffs, sprintf "> %s%s: %s\n", $desc, $pad, Printable($val2) if defined $val2; |
| 2530 |
} |
| 2531 |
} |
| 2532 |
$done2{$tag2} = 1 if defined $tag2; |
| 2533 |
} |
| 2534 |
print $fp "(no metadata differences)\n" unless $wasDiff; |
| 2535 |
if (defined $outfile) { |
| 2536 |
$created{$outfile} = 1; |
| 2537 |
close($fp); |
| 2538 |
undef $tmpText; |
| 2539 |
} |
| 2540 |
++$count; |
| 2541 |
return; |
| 2542 |
} |
| 2543 |
# restore state of comma flag for this file if appending |
| 2544 |
$comma = $outComma{$outfile} if $append and ($textOverwrite & 0x02); |
| 2545 |
|
| 2546 |
# print the results for this file |
| 2547 |
if (%printFmt) { |
| 2548 |
# output using print format file (-p) option |
| 2549 |
my ($type, @doc, $grp, $lastDoc, $cache); |
| 2550 |
$fileTrailer = ''; |
| 2551 |
# repeat for each embedded document if necessary (only if -ee used) |
| 2552 |
if ($et->Options('ExtractEmbedded')) { |
| 2553 |
# (cache tag keys if there are sub-documents) |
| 2554 |
$lastDoc = $$et{DOC_COUNT} and $cache = { }; |
| 2555 |
} else { |
| 2556 |
$lastDoc = 0; |
| 2557 |
} |
| 2558 |
for ($doc[0]=0; $doc[0]<=$lastDoc; ) { |
| 2559 |
my $doc = join '-', @doc; |
| 2560 |
my ($skipBody, $opt); |
| 2561 |
foreach $type (qw(HEAD SECT IF BODY ENDS TAIL)) { |
| 2562 |
my $prf = $printFmt{$type} or next; |
| 2563 |
if ($type eq 'HEAD' and defined $outfile) { |
| 2564 |
next if $wroteHEAD{$outfile}; |
| 2565 |
$wroteHEAD{$outfile} = 1; |
| 2566 |
} |
| 2567 |
next if $type eq 'BODY' and $skipBody; |
| 2568 |
# silence "IF" warnings and warnings for subdocuments > 1 |
| 2569 |
if ($type eq 'IF' or (($doc[0] > 1 or @doc > 1) and not $$et{OPTIONS}{IgnoreMinorErrors})) { |
| 2570 |
$opt = 'Silent'; |
| 2571 |
} else { |
| 2572 |
$opt = 'Warn'; |
| 2573 |
} |
| 2574 |
if ($lastDoc) { |
| 2575 |
if ($doc) { |
| 2576 |
next if $type eq 'HEAD' or $type eq 'TAIL'; # only repeat SECT/IF/BODY/ENDS |
| 2577 |
$grp = "Doc$doc"; |
| 2578 |
} else { |
| 2579 |
$grp = 'Main'; |
| 2580 |
} |
| 2581 |
} |
| 2582 |
my @lines; |
| 2583 |
foreach (@$prf) { |
| 2584 |
my $line = $et->InsertTagValues($_, \@foundTags, $opt, $grp, $cache); |
| 2585 |
if ($type eq 'IF') { |
| 2586 |
$skipBody = 1 unless defined $line; |
| 2587 |
} elsif (defined $line) { |
| 2588 |
push @lines, $line; |
| 2589 |
} |
| 2590 |
} |
| 2591 |
$lineCount += scalar @lines; |
| 2592 |
if ($type eq 'SECT') { |
| 2593 |
my $thisHeader = join '', @lines; |
| 2594 |
if ($sectHeader and $sectHeader ne $thisHeader) { |
| 2595 |
print $fp $sectTrailer if $sectTrailer; |
| 2596 |
undef $sectHeader; |
| 2597 |
} |
| 2598 |
$sectTrailer = ''; |
| 2599 |
print $fp $sectHeader = $thisHeader unless $sectHeader; |
| 2600 |
} elsif ($type eq 'ENDS') { |
| 2601 |
$sectTrailer .= join '', @lines if defined $sectHeader; |
| 2602 |
} elsif ($type eq 'TAIL') { |
| 2603 |
$fileTrailer .= join '', @lines; |
| 2604 |
} elsif (@lines) { |
| 2605 |
print $fp @lines; |
| 2606 |
} |
| 2607 |
} |
| 2608 |
# find next available doc-subdoc |
| 2609 |
push @doc, 1; |
| 2610 |
while (@doc > 1) { |
| 2611 |
my $nextDoc = join '-', @doc; |
| 2612 |
last if $$et{HAS_DOC}{$nextDoc}; |
| 2613 |
pop @doc; |
| 2614 |
++$doc[-1]; |
| 2615 |
} |
| 2616 |
} |
| 2617 |
delete $printFmt{HEAD} unless defined $outfile; # print header only once per output file |
| 2618 |
my $errs = $et->GetInfo('Warning', 'Error'); |
| 2619 |
PrintErrors($et, $errs, $file) and EFile($file); |
| 2620 |
} elsif ($plot) { |
| 2621 |
# add points from this file to the plot |
| 2622 |
my $tagExtra = $$et{TAG_EXTRA}; |
| 2623 |
my ($tag, %docNum); |
| 2624 |
foreach $tag (keys %$info) { |
| 2625 |
next unless $$tagExtra{$tag} and $$tagExtra{$tag}{G3}; |
| 2626 |
$docNum{$tag} = $1 if $$tagExtra{$tag}{G3} =~ /(\d+)/; |
| 2627 |
} |
| 2628 |
$$plot{DocNum} = \%docNum; |
| 2629 |
$$plot{EE} = 1 if $et->Options('ExtractEmbedded'); |
| 2630 |
$plot->AddPoints($info, \@foundTags); |
| 2631 |
} elsif (not $disableOutput) { |
| 2632 |
my ($tag, $line, %noDups, %csvInfo, $bra, $ket, $sep, $quote); |
| 2633 |
if ($fp) { |
| 2634 |
# print file header (only once) |
| 2635 |
if ($fileHeader) { |
| 2636 |
print $fp $fileHeader unless defined $outfile and ($created{$outfile} or $appended{$outfile}); |
| 2637 |
undef $fileHeader unless $textOut; |
| 2638 |
} |
| 2639 |
if ($html) { |
| 2640 |
print $fp "<table>\n"; |
| 2641 |
} elsif ($xml) { |
| 2642 |
my $f = $file; |
| 2643 |
CleanXML(\$f); |
| 2644 |
print $fp "\n<rdf:Description rdf:about='${f}'"; |
| 2645 |
print $fp "\n xmlns:et='http://ns.exiftool.org/1.0/'"; |
| 2646 |
print $fp " et:toolkit='Image::ExifTool $Image::ExifTool::VERSION'"; |
| 2647 |
# define namespaces for all tag groups |
| 2648 |
my (%groups, @groups, $grp0, $grp1); |
| 2649 |
foreach $tag (@foundTags) { |
| 2650 |
($grp0, $grp1) = $et->GetGroup($tag); |
| 2651 |
unless ($grp1) { |
| 2652 |
next unless defined $forcePrint; |
| 2653 |
$grp0 = $grp1 = 'Unknown'; |
| 2654 |
} |
| 2655 |
# add groups from structure fields |
| 2656 |
AddGroups($$info{$tag}, $grp0, \%groups, \@groups) if ref $$info{$tag}; |
| 2657 |
next if $groups{$grp1}; |
| 2658 |
# include family 0 and 1 groups in URI except for internal tags |
| 2659 |
# (this will put internal tags in the "XML" group on readback) |
| 2660 |
$groups{$grp1} = $grp0; |
| 2661 |
push @groups, $grp1; |
| 2662 |
} |
| 2663 |
foreach $grp1 (@groups) { |
| 2664 |
my $grp = $groups{$grp1}; |
| 2665 |
unless ($grp eq $grp1 and $grp =~ /^(ExifTool|File|Composite|Unknown)$/) { |
| 2666 |
$grp .= "/$grp1"; |
| 2667 |
} |
| 2668 |
print $fp "\n xmlns:$grp1='http://ns.exiftool.org/$grp/1.0/'"; |
| 2669 |
} |
| 2670 |
print $fp '>' if $outFormat < 1; # finish rdf:Description token unless short format |
| 2671 |
$ind = $outFormat >= 0 ? ' ' : ' '; |
| 2672 |
} elsif ($json) { |
| 2673 |
# set delimiters for JSON or PHP output |
| 2674 |
($bra, $ket, $sep) = $json == 1 ? ('{','}',':') : ('Array(',')',' =>'); |
| 2675 |
$quote = 1 if $$et{OPTIONS}{StructFormat} and $$et{OPTIONS}{StructFormat} eq 'JSONQ'; |
| 2676 |
print $fp ",\n" if $comma; |
| 2677 |
print $fp qq($bra\n "SourceFile"$sep ), EscapeJSON(MyConvertFileName($et,$file),1); |
| 2678 |
$comma = 1; |
| 2679 |
$ind = (defined $showGroup and not $allGroup) ? ' ' : ' '; |
| 2680 |
} elsif ($csv) { |
| 2681 |
my $file2 = MyConvertFileName($et, $file); |
| 2682 |
$database{$file2} = \%csvInfo; |
| 2683 |
push @csvFiles, $file2; |
| 2684 |
} |
| 2685 |
} |
| 2686 |
# suppress duplicates manually in JSON and short XML output |
| 2687 |
my $noDups = ($json or ($xml and $outFormat > 0)); |
| 2688 |
my $printConv = $et->Options('PrintConv'); |
| 2689 |
my $lastGroup = ''; |
| 2690 |
my $i = -1; |
| 2691 |
TAG: foreach $tag (@foundTags) { |
| 2692 |
++$i; # keep track on index in @foundTags |
| 2693 |
my $tagName = GetTagName($tag); |
| 2694 |
my ($group, $valList); |
| 2695 |
# get the value for this tag |
| 2696 |
my $val = $$info{$tag}; |
| 2697 |
# set flag if this is binary data |
| 2698 |
$isBinary = (ref $val eq 'SCALAR' and defined $binaryOutput); |
| 2699 |
if (ref $val) { |
| 2700 |
# happens with -X, -j or -php when combined with -b: |
| 2701 |
if (defined $binaryOutput and not $binaryOutput and $$et{TAG_INFO}{$tag}{Protected}) { |
| 2702 |
# avoid extracting Unsafe binary tags (eg. data blocks) [insider information] |
| 2703 |
my $lcTag = lc $tag; |
| 2704 |
$lcTag =~ s/ .*//; |
| 2705 |
next unless $$et{REQ_TAG_LOOKUP}{$lcTag} or ($$et{OPTIONS}{RequestAll} || 0) > 2; |
| 2706 |
} |
| 2707 |
$val = ConvertBinary($val); # convert SCALAR references |
| 2708 |
next unless defined $val; |
| 2709 |
if ($structOpt and ref $val) { |
| 2710 |
# serialize structure if necessary |
| 2711 |
$val = Image::ExifTool::XMP::SerializeStruct($et, $val) unless $xml or $json; |
| 2712 |
} elsif (ref $val eq 'ARRAY') { |
| 2713 |
if (defined $listItem) { |
| 2714 |
# take only the specified item |
| 2715 |
$val = $$val[$listItem]; |
| 2716 |
# join arrays of simple values (with newlines for binary output) |
| 2717 |
} elsif ($binaryOutput) { |
| 2718 |
if ($tagOut) { |
| 2719 |
$valList = $val; |
| 2720 |
$val = shift @$valList; |
| 2721 |
} else { |
| 2722 |
$val = join defined $binSep ? $binSep : "\n", @$val; |
| 2723 |
} |
| 2724 |
} elsif ($joinLists) { |
| 2725 |
$val = join $listSep, @$val; |
| 2726 |
} |
| 2727 |
} |
| 2728 |
} |
| 2729 |
if (not defined $val) { |
| 2730 |
# ignore tags that weren't found unless necessary |
| 2731 |
next if $binaryOutput; |
| 2732 |
if (defined $forcePrint) { |
| 2733 |
$val = $forcePrint; # forced to print all tag values |
| 2734 |
} elsif (not $csv) { |
| 2735 |
next; |
| 2736 |
} |
| 2737 |
} |
| 2738 |
if (defined $showGroup) { |
| 2739 |
$group = $et->GetGroup($tag, $showGroup); |
| 2740 |
# look ahead to see if this tag may suppress a priority tag in |
| 2741 |
# the same group, and if so suppress this tag instead |
| 2742 |
# (note that the tag key may look like "TAG #(1)" when the "#" feature is used) |
| 2743 |
next if $noDups and $tag =~ /^(.*?) ?\(/ and defined $$info{$1} and |
| 2744 |
$group eq $et->GetGroup($1, $showGroup); |
| 2745 |
if (not $group and ($xml or $json or $csv)) { |
| 2746 |
if ($showGroup !~ /\b4\b/) { |
| 2747 |
$group = 'Unknown'; |
| 2748 |
} elsif ($json and not $allGroup) { |
| 2749 |
$group = 'Copy0'; |
| 2750 |
} |
| 2751 |
} |
| 2752 |
if ($fp and not ($allGroup or $csv)) { |
| 2753 |
if ($lastGroup ne $group) { |
| 2754 |
if ($html) { |
| 2755 |
my $cols = 1; |
| 2756 |
++$cols if $outFormat==0 or $outFormat==1; |
| 2757 |
++$cols if $showTagID; |
| 2758 |
print $fp "<tr><td colspan=$cols bgcolor='#dddddd'>$group</td></tr>\n"; |
| 2759 |
} elsif ($json) { |
| 2760 |
print $fp "\n $ket" if $lastGroup; |
| 2761 |
print $fp ',' if $lastGroup or $comma; |
| 2762 |
print $fp qq(\n "$group"$sep $bra); |
| 2763 |
undef $comma; |
| 2764 |
undef %noDups; # allow duplicate names in different groups |
| 2765 |
} else { |
| 2766 |
print $fp "---- $group ----\n"; |
| 2767 |
} |
| 2768 |
$lastGroup = $group; |
| 2769 |
} |
| 2770 |
undef $group; # undefine so we don't print it below |
| 2771 |
} |
| 2772 |
} elsif ($noDups) { |
| 2773 |
# don't allow duplicates, but avoid suppressing the priority tag |
| 2774 |
next if $tag =~ /^(.*?) ?\(/ and defined $$info{$1}; |
| 2775 |
} |
| 2776 |
|
| 2777 |
++$lineCount; # we are printing something meaningful |
| 2778 |
|
| 2779 |
# loop through list values when -b -W used |
| 2780 |
for (;;) { |
| 2781 |
if ($tagOut) { |
| 2782 |
# determine suggested extension for output file |
| 2783 |
my $ext = SuggestedExtension($et, \$val, $tagName); |
| 2784 |
if (%wext and ($wext{$ext} || $wext{'*'} || -1) < 0) { |
| 2785 |
if ($verbose and $verbose > 1) { |
| 2786 |
print $vout "Not writing $ext output file for $tagName\n"; |
| 2787 |
} |
| 2788 |
next TAG; |
| 2789 |
} |
| 2790 |
my @groups = $et->GetGroup($tag); |
| 2791 |
defined $outfile and close($fp), undef($tmpText); # (shouldn't happen) |
| 2792 |
my $org = $et->GetValue('OriginalRawFileName') || $et->GetValue('OriginalFileName'); |
| 2793 |
($fp, $outfile, $append) = OpenOutputFile($orig, $tagName, \@groups, $ext, $org); |
| 2794 |
$fp or ++$countBad, next TAG; |
| 2795 |
$tmpText = $outfile unless $append; |
| 2796 |
} |
| 2797 |
# write binary output |
| 2798 |
if ($binaryOutput) { |
| 2799 |
print $fp $val; |
| 2800 |
print $fp $binTerm if defined $binTerm; |
| 2801 |
if ($tagOut) { |
| 2802 |
if ($append) { |
| 2803 |
$appended{$outfile} = 1 unless $created{$outfile}; |
| 2804 |
} else { |
| 2805 |
$created{$outfile} = 1; |
| 2806 |
} |
| 2807 |
close($fp); |
| 2808 |
undef $tmpText; |
| 2809 |
$verbose and print $vout "Wrote $tagName to $outfile\n"; |
| 2810 |
undef $outfile; |
| 2811 |
undef $fp; |
| 2812 |
next TAG unless $valList and @$valList; |
| 2813 |
$val = shift @$valList; |
| 2814 |
next; # loop over values of List tag |
| 2815 |
} |
| 2816 |
next TAG; |
| 2817 |
} |
| 2818 |
last; |
| 2819 |
} |
| 2820 |
# save information for CSV output |
| 2821 |
if ($csv) { |
| 2822 |
my $tn = $tagName; |
| 2823 |
$tn .= '#' if $tag =~ /#/; # add ValueConv "#" suffix if used |
| 2824 |
my $gt = $group ? "$group:$tn" : $tn; |
| 2825 |
# (tag-name case may be different if some tags don't exist |
| 2826 |
# in a file, so all logic must use lower-case tag names) |
| 2827 |
my $lcTag = lc $gt; |
| 2828 |
# override existing entry only if top priority |
| 2829 |
next if defined $csvInfo{$lcTag} and $tag =~ /\(/; |
| 2830 |
$csvInfo{$lcTag} = $val; |
| 2831 |
if (defined $csvTags{$lcTag}) { |
| 2832 |
# overwrite with actual extracted tag name |
| 2833 |
# (note: can't check "if defined $val" here because -f may be used) |
| 2834 |
$csvTags{$lcTag} = $gt if defined $$info{$tag}; |
| 2835 |
next; |
| 2836 |
} |
| 2837 |
# must check for "Unknown" group (for tags that don't exist) |
| 2838 |
if ($group and defined $csvTags[$i] and $csvTags[$i] =~ /^(.*):$tn$/i) { |
| 2839 |
next if $group eq 'Unknown'; # nothing more to do if we don't know tag group |
| 2840 |
if ($1 eq 'unknown') { |
| 2841 |
# replace unknown entry in CSV tag lookup and list |
| 2842 |
delete $csvTags{$csvTags[$i]}; |
| 2843 |
$csvTags{$lcTag} = defined($val) ? $gt : ''; |
| 2844 |
$csvTags[$i] = $lcTag; |
| 2845 |
next; |
| 2846 |
} |
| 2847 |
} |
| 2848 |
# (don't save unextracted tag name unless -f was used) |
| 2849 |
$csvTags{$lcTag} = defined($val) ? $gt : ''; |
| 2850 |
if (@csvFiles == 1) { |
| 2851 |
push @csvTags, $lcTag; # save order of tags for first file |
| 2852 |
} elsif (@csvTags) { |
| 2853 |
undef @csvTags; |
| 2854 |
} |
| 2855 |
next; |
| 2856 |
} |
| 2857 |
|
| 2858 |
# get description if we need it (use tag name if $outFormat > 0) |
| 2859 |
my $desc = $outFormat > 0 ? $tagName : $et->GetDescription($tag); |
| 2860 |
|
| 2861 |
if ($xml) { |
| 2862 |
# RDF/XML output format |
| 2863 |
my $tok = "$group:$tagName"; |
| 2864 |
if ($outFormat > 0) { |
| 2865 |
if ($structOpt and ref $val) { |
| 2866 |
$val = Image::ExifTool::XMP::SerializeStruct($et, $val); |
| 2867 |
} |
| 2868 |
if ($escapeHTML) { |
| 2869 |
$val =~ tr/\0-\x08\x0b\x0c\x0e-\x1f/./; |
| 2870 |
Image::ExifTool::XMP::FixUTF8(\$val) unless $altEnc; |
| 2871 |
$val = Image::ExifTool::HTML::EscapeHTML($val, $altEnc); |
| 2872 |
} else { |
| 2873 |
CleanXML(\$val); |
| 2874 |
} |
| 2875 |
unless ($noDups{$tok}) { |
| 2876 |
# manually un-do CR/LF conversion in Windows because output |
| 2877 |
# is in text mode, which will re-convert newlines to CR/LF |
| 2878 |
$isCRLF and $val =~ s/\x0d\x0a/\x0a/g; |
| 2879 |
print $fp "\n $tok='${val}'"; |
| 2880 |
# XML does not allow duplicate attributes |
| 2881 |
$noDups{$tok} = 1; |
| 2882 |
} |
| 2883 |
next; |
| 2884 |
} |
| 2885 |
my ($xtra, $valNum, $descClose); |
| 2886 |
if ($showTagID) { |
| 2887 |
my ($id, $lang) = $et->GetTagID($tag); |
| 2888 |
if ($id =~ /^\d+$/) { |
| 2889 |
$id = sprintf("0x%.4x", $id) if $showTagID eq 'H'; |
| 2890 |
} else { |
| 2891 |
$id = Image::ExifTool::XMP::FullEscapeXML($id); |
| 2892 |
} |
| 2893 |
$xtra = " et:id='${id}'"; |
| 2894 |
$xtra .= " xml:lang='${lang}'" if $lang; |
| 2895 |
} else { |
| 2896 |
$xtra = ''; |
| 2897 |
} |
| 2898 |
if ($tabFormat) { |
| 2899 |
my $table = $et->GetTableName($tag); |
| 2900 |
my $index = $et->GetTagIndex($tag); |
| 2901 |
$xtra .= " et:table='${table}'"; |
| 2902 |
$xtra .= " et:index='${index}'" if defined $index; |
| 2903 |
} |
| 2904 |
# Note: New $xtra attributes must be added to %ignoreEtProp in XMP.pm! |
| 2905 |
my $lastVal = $val; |
| 2906 |
for ($valNum=0; $valNum<2; ++$valNum) { |
| 2907 |
$val = FormatXML($val, $ind, $group); |
| 2908 |
# manually un-do CR/LF conversion in Windows because output |
| 2909 |
# is in text mode, which will re-convert newlines to CR/LF |
| 2910 |
$isCRLF and $val =~ s/\x0d\x0a/\x0a/g; |
| 2911 |
if ($outFormat >= 0) { |
| 2912 |
# normal output format (note: this will give |
| 2913 |
# non-standard RDF/XML if there are any attributes) |
| 2914 |
print $fp "\n <$tok$xtra$val</$tok>"; |
| 2915 |
last; |
| 2916 |
} elsif ($valNum == 0) { |
| 2917 |
CleanXML(\$desc); |
| 2918 |
if ($xtra) { |
| 2919 |
print $fp "\n <$tok>"; |
| 2920 |
print $fp "\n <rdf:Description$xtra>"; |
| 2921 |
$descClose = "\n </rdf:Description>"; |
| 2922 |
} else { |
| 2923 |
print $fp "\n <$tok rdf:parseType='Resource'>"; |
| 2924 |
$descClose = ''; |
| 2925 |
} |
| 2926 |
# print tag Description |
| 2927 |
print $fp "\n <et:desc>$desc</et:desc>"; |
| 2928 |
if ($printConv) { |
| 2929 |
# print PrintConv value |
| 2930 |
print $fp "\n <et:prt$val</et:prt>"; |
| 2931 |
$val = $et->GetValue($tag, 'ValueConv'); |
| 2932 |
$val = '' unless defined $val; |
| 2933 |
# go back to print ValueConv value only if different |
| 2934 |
next unless IsEqual($val, $lastVal, 1); |
| 2935 |
print $fp "$descClose\n </$tok>"; |
| 2936 |
last; |
| 2937 |
} |
| 2938 |
} |
| 2939 |
# print ValueConv value |
| 2940 |
print $fp "\n <et:val$val</et:val>"; |
| 2941 |
print $fp "$descClose\n </$tok>"; |
| 2942 |
last; |
| 2943 |
} |
| 2944 |
next; |
| 2945 |
} elsif ($json) { |
| 2946 |
# JSON or PHP output format |
| 2947 |
my $tok = $allGroup ? "$group:$tagName" : $tagName; |
| 2948 |
# (removed due to backward incompatibility) |
| 2949 |
# $tok .= '#' if $tag =~ /#/; # add back '#' suffix if used |
| 2950 |
next if $noDups{$tok}; |
| 2951 |
$noDups{$tok} = 1; |
| 2952 |
print $fp ',' if $comma; |
| 2953 |
print $fp qq(\n$ind"$tok"$sep ); |
| 2954 |
if ($showTagID or $outFormat < 0) { |
| 2955 |
$val = { val => $val }; |
| 2956 |
if ($showTagID) { |
| 2957 |
my ($id, $lang) = $et->GetTagID($tag); |
| 2958 |
$id = sprintf('0x%.4x', $id) if $showTagID eq 'H' and $id =~ /^\d+$/; |
| 2959 |
$$val{lang} = $lang if $lang; |
| 2960 |
$$val{id} = $id; |
| 2961 |
} |
| 2962 |
if ($tabFormat) { |
| 2963 |
$$val{table} = $et->GetTableName($tag); |
| 2964 |
my $index = $et->GetTagIndex($tag); |
| 2965 |
$$val{index} = $index if defined $index; |
| 2966 |
} |
| 2967 |
if ($outFormat < 0) { |
| 2968 |
$$val{desc} = $desc; |
| 2969 |
if ($printConv) { |
| 2970 |
my $num = $et->GetValue($tag, 'ValueConv'); |
| 2971 |
$$val{num} = $num if defined $num and not IsEqual($num, $$val{val}, 1); |
| 2972 |
} |
| 2973 |
my $ex = $$et{TAG_EXTRA}{$tag}; |
| 2974 |
$$val{'fmt'} = $$ex{G6} if defined $$ex{G6}; |
| 2975 |
if (defined $$ex{BinVal}) { |
| 2976 |
my $max = ($$et{OPTIONS}{LimitLongValues} - 5) / 3; |
| 2977 |
if ($max >= 0 and length($$ex{BinVal}) > int($max)) { |
| 2978 |
$max = int $max; |
| 2979 |
$$val{'hex'} = join ' ', unpack("(H2)$max", $$ex{BinVal}), '[...]'; |
| 2980 |
} else { |
| 2981 |
$$val{'hex'} = join ' ', unpack '(H2)*', $$ex{BinVal}; |
| 2982 |
} |
| 2983 |
} |
| 2984 |
$$val{rat} = $$ex{Rational} if defined $$ex{Rational} and $$et{OPTIONS}{SaveBin}; |
| 2985 |
} |
| 2986 |
} |
| 2987 |
FormatJSON($fp, $val, $ind, $quote); |
| 2988 |
$comma = 1; |
| 2989 |
next; |
| 2990 |
} |
| 2991 |
my $id; |
| 2992 |
if ($showTagID) { |
| 2993 |
$id = $et->GetTagID($tag); |
| 2994 |
if ($id =~ /^(\d+)(\.\d+)?$/) { # only print numeric ID's |
| 2995 |
$id = sprintf("0x%.4x", $1) if $showTagID eq 'H'; |
| 2996 |
} else { |
| 2997 |
$id = '-'; |
| 2998 |
} |
| 2999 |
} |
| 3000 |
|
| 3001 |
if ($escapeC) { |
| 3002 |
$val =~ s/([\0-\x1f\\\x7f])/$escC{$1} || sprintf('\x%.2x', ord $1)/eg; |
| 3003 |
} else { |
| 3004 |
# translate unprintable chars in value and remove trailing spaces |
| 3005 |
$val =~ tr/\x01-\x1f\x7f/./; |
| 3006 |
$val =~ s/\x00//g; |
| 3007 |
$val =~ s/\s+$//; |
| 3008 |
} |
| 3009 |
|
| 3010 |
if ($html) { |
| 3011 |
print $fp "<tr>"; |
| 3012 |
print $fp "<td>$group</td>" if defined $group; |
| 3013 |
print $fp "<td>$id</td>" if $showTagID; |
| 3014 |
print $fp "<td>$desc</td>" if $outFormat <= 1; |
| 3015 |
print $fp "<td>$val</td></tr>\n"; |
| 3016 |
} else { |
| 3017 |
my $buff = ''; |
| 3018 |
if ($tabFormat) { |
| 3019 |
$buff = "$group\t" if defined $group; |
| 3020 |
$buff .= "$id\t" if $showTagID; |
| 3021 |
if ($outFormat <= 1) { |
| 3022 |
$buff .= "$desc\t$val\n"; |
| 3023 |
} elsif (defined $line) { |
| 3024 |
$line .= "\t$val"; |
| 3025 |
} else { |
| 3026 |
$line = $val; |
| 3027 |
} |
| 3028 |
} elsif ($outFormat < 0) { # long format |
| 3029 |
$buff = "[$group] " if defined $group; |
| 3030 |
$buff .= "$id " if $showTagID; |
| 3031 |
$buff .= "$desc\n $val\n"; |
| 3032 |
} elsif ($outFormat == 0 or $outFormat == 1) { |
| 3033 |
my $wid; |
| 3034 |
my $len = 0; |
| 3035 |
if (defined $group) { |
| 3036 |
$buff = sprintf("%-15s ", "[$group]"); |
| 3037 |
$len = 16; |
| 3038 |
} |
| 3039 |
if ($showTagID) { |
| 3040 |
$wid = ($showTagID eq 'D') ? 5 : 6; |
| 3041 |
$len += $wid + 1; |
| 3042 |
($wid = $len - length($buff) - 1) < 1 and $wid = 1; |
| 3043 |
$buff .= sprintf "%${wid}s ", $id; |
| 3044 |
} |
| 3045 |
$wid = 32 - (length($buff) - $len); |
| 3046 |
# pad description to a constant length |
| 3047 |
# (get actual character length when using alternate languages |
| 3048 |
# because these descriptions may contain UTF8-encoded characters) |
| 3049 |
my $padLen = $wid - LengthUTF8($desc); |
| 3050 |
$padLen = 0 if $padLen < 0; |
| 3051 |
$buff .= $desc . (' ' x $padLen) . ": $val\n"; |
| 3052 |
} elsif ($outFormat == 2) { |
| 3053 |
$buff = "[$group] " if defined $group; |
| 3054 |
$buff .= "$id " if $showTagID; |
| 3055 |
$buff .= "$tagName: $val\n"; |
| 3056 |
} elsif ($argFormat) { |
| 3057 |
$buff = '-'; |
| 3058 |
$buff .= "$group:" if defined $group; |
| 3059 |
$tagName .= '#' if $tag =~ /#/; # add '#' suffix if used |
| 3060 |
$buff .= "$tagName=$val\n"; |
| 3061 |
} else { |
| 3062 |
$buff = "$group " if defined $group; |
| 3063 |
$buff .= "$id " if $showTagID; |
| 3064 |
$buff .= "$val\n"; |
| 3065 |
} |
| 3066 |
print $fp $buff; |
| 3067 |
} |
| 3068 |
if ($tagOut) { |
| 3069 |
if ($append) { |
| 3070 |
$appended{$outfile} = 1 unless $created{$outfile}; |
| 3071 |
} else { |
| 3072 |
$created{$outfile} = 1; |
| 3073 |
} |
| 3074 |
close($fp); |
| 3075 |
undef $tmpText; |
| 3076 |
$verbose and print $vout "Wrote $tagName to $outfile\n"; |
| 3077 |
undef $outfile; |
| 3078 |
undef $fp; |
| 3079 |
} |
| 3080 |
} |
| 3081 |
if ($fp) { |
| 3082 |
if ($html) { |
| 3083 |
print $fp "</table>\n"; |
| 3084 |
} elsif ($xml) { |
| 3085 |
# close rdf:Description element |
| 3086 |
print $fp $outFormat < 1 ? "\n</rdf:Description>\n" : "/>\n"; |
| 3087 |
} elsif ($json) { |
| 3088 |
print $fp "\n $ket" if $lastGroup; |
| 3089 |
print $fp "\n$ket"; |
| 3090 |
$comma = 1; |
| 3091 |
} elsif ($tabFormat and $outFormat > 1) { |
| 3092 |
print $fp "$line\n" if defined $line; |
| 3093 |
} |
| 3094 |
} |
| 3095 |
} |
| 3096 |
if (defined $outfile) { |
| 3097 |
if ($textOverwrite & 0x02) { |
| 3098 |
# save state of this file if we may be appending |
| 3099 |
$outComma{$outfile} = $comma; |
| 3100 |
$outTrailer{$outfile} = ''; |
| 3101 |
$outTrailer{$outfile} .= $sectTrailer and $sectTrailer = '' if $sectTrailer; |
| 3102 |
$outTrailer{$outfile} .= $fileTrailer if $fileTrailer; |
| 3103 |
} else { |
| 3104 |
# write section and file trailers before closing the file |
| 3105 |
print $fp $sectTrailer and $sectTrailer = '' if $sectTrailer; |
| 3106 |
print $fp $fileTrailer if $fileTrailer; |
| 3107 |
} |
| 3108 |
close($fp); |
| 3109 |
undef $tmpText; |
| 3110 |
if ($lineCount) { |
| 3111 |
if ($append) { |
| 3112 |
$appended{$outfile} = 1 unless $created{$outfile}; |
| 3113 |
} else { |
| 3114 |
$created{$outfile} = 1; |
| 3115 |
} |
| 3116 |
} else { |
| 3117 |
$et->Unlink($outfile) unless $append; # don't keep empty output files |
| 3118 |
} |
| 3119 |
undef $comma; |
| 3120 |
} |
| 3121 |
++$count; |
| 3122 |
} |
| 3123 |
|
| 3124 |
#------------------------------------------------------------------------------ |
| 3125 |
# Set information in file |
| 3126 |
# Inputs: 0) ExifTool object reference, 1) source file name |
| 3127 |
# 2) original source file name ('' to create from scratch) |
| 3128 |
# Returns: true on success |
| 3129 |
sub SetImageInfo($$$) |
| 3130 |
{ |
| 3131 |
my ($et, $file, $orig) = @_; |
| 3132 |
my ($outfile, $restored, $isTemporary, $isStdout, $outType, $tagsFromSrc); |
| 3133 |
my ($hardLink, $symLink, $testName, $sameFile); |
| 3134 |
my $infile = $file; # save infile in case we change it again |
| 3135 |
|
| 3136 |
# clean up old temporary file if necessary |
| 3137 |
if (defined $tmpFile) { |
| 3138 |
$et->Unlink($tmpFile); |
| 3139 |
undef $tmpFile; |
| 3140 |
} |
| 3141 |
# clear any existing errors or warnings since we check these on return |
| 3142 |
delete $$et{VALUE}{Error}; |
| 3143 |
delete $$et{VALUE}{Warning}; |
| 3144 |
|
| 3145 |
# first, try to determine our output file name so we can return quickly |
| 3146 |
# if it already exists (note: this test must be delayed until after we |
| 3147 |
# set tags from dynamic files if writing FileName or Directory) |
| 3148 |
if (defined $outOpt) { |
| 3149 |
if ($outOpt =~ /^-(\.\w+)?$/) { |
| 3150 |
# allow output file type to be specified with "-o -.EXT" |
| 3151 |
$outType = GetFileType($outOpt) if $1; |
| 3152 |
$outfile = '-'; |
| 3153 |
$isStdout = 1; |
| 3154 |
} else { |
| 3155 |
$outfile = FilenameSPrintf($outOpt, $orig); |
| 3156 |
if ($outfile eq '') { |
| 3157 |
Warn "Error: Can't create file with zero-length name from $orig\n"; |
| 3158 |
EFile($infile); |
| 3159 |
++$countBadCr; |
| 3160 |
return 0; |
| 3161 |
} |
| 3162 |
} |
| 3163 |
if (not $isStdout and (($et->IsDirectory($outfile) and not $listDir) or $outfile =~ /\/$/)) { |
| 3164 |
$outfile .= '/' unless $outfile =~ /\/$/; |
| 3165 |
my $name = $file; |
| 3166 |
$name =~ s/^.*\///s; # remove directory name |
| 3167 |
$outfile .= $name; |
| 3168 |
} else { |
| 3169 |
my $srcType = GetFileType($file) || ''; |
| 3170 |
$outType or $outType = GetFileType($outfile); |
| 3171 |
if ($outType and ($srcType ne $outType or $outType eq 'ICC') and $file ne '-') { |
| 3172 |
unless (CanCreate($outType)) { |
| 3173 |
my $what = $srcType ? 'other types' : 'scratch'; |
| 3174 |
WarnOnce "Error: Can't create $outType files from $what\n"; |
| 3175 |
EFile($infile); |
| 3176 |
++$countBadCr; |
| 3177 |
return 0; |
| 3178 |
} |
| 3179 |
if ($file ne '') { |
| 3180 |
# restore previous new values unless done already |
| 3181 |
$et->RestoreNewValues() unless $restored; |
| 3182 |
$restored = 1; |
| 3183 |
# translate to this type by setting specified tags from file |
| 3184 |
my @setTags = @tags; |
| 3185 |
foreach (@exclude) { |
| 3186 |
push @setTags, "-$_"; |
| 3187 |
} |
| 3188 |
# force some tags to be copied for certain file types |
| 3189 |
my %forceCopy = ( |
| 3190 |
ICC => 'ICC_Profile', |
| 3191 |
VRD => 'CanonVRD', |
| 3192 |
DR4 => 'CanonDR4', |
| 3193 |
); |
| 3194 |
push @setTags, $forceCopy{$outType} if $forceCopy{$outType}; |
| 3195 |
# assume "-tagsFromFile @" unless -tagsFromFile already specified |
| 3196 |
# (%setTags won't be empty if -tagsFromFile used) |
| 3197 |
if (not %setTags or (@setTags and not $setTags{'@'})) { |
| 3198 |
return 0 unless DoSetFromFile($et, $file, \@setTags); |
| 3199 |
} elsif (@setTags) { |
| 3200 |
# add orphaned tags to existing "-tagsFromFile @" for this file only |
| 3201 |
push @setTags, @{$setTags{'@'}}; |
| 3202 |
$tagsFromSrc = \@setTags; |
| 3203 |
} |
| 3204 |
# all done with source file -- create from meta information alone |
| 3205 |
$file = ''; |
| 3206 |
} |
| 3207 |
} |
| 3208 |
} |
| 3209 |
unless ($isStdout) { |
| 3210 |
$outfile = NextUnusedFilename($outfile); |
| 3211 |
if ($et->Exists($outfile, 1) and not $doSetFileName) { |
| 3212 |
Warn "Error: '${outfile}' already exists - $infile\n"; |
| 3213 |
EFile($infile); |
| 3214 |
++$countBadWr; |
| 3215 |
return 0; |
| 3216 |
} |
| 3217 |
} |
| 3218 |
} elsif ($file eq '-') { |
| 3219 |
$isStdout = 1; |
| 3220 |
} |
| 3221 |
# set tags from destination file if required |
| 3222 |
if (@dynamicFiles) { |
| 3223 |
# restore previous values if necessary |
| 3224 |
$et->RestoreNewValues() unless $restored; |
| 3225 |
my ($dyFile, %setTagsIndex); |
| 3226 |
foreach $dyFile (@dynamicFiles) { |
| 3227 |
if (not ref $dyFile) { |
| 3228 |
my ($fromFile, $setTags); |
| 3229 |
if ($dyFile eq '@') { |
| 3230 |
$fromFile = $orig; |
| 3231 |
$setTags = $tagsFromSrc || $setTags{$dyFile}; |
| 3232 |
} else { |
| 3233 |
$fromFile = FilenameSPrintf($dyFile, $orig); |
| 3234 |
defined $fromFile or EFile($infile), ++$countBadWr, return 0; |
| 3235 |
$setTags = $setTags{$dyFile}; |
| 3236 |
} |
| 3237 |
# do we have multiple -tagsFromFile options with this file? |
| 3238 |
if ($setTagsList{$dyFile}) { |
| 3239 |
# use the tags set in the i-th occurrence |
| 3240 |
my $i = $setTagsIndex{$dyFile} || 0; |
| 3241 |
$setTagsIndex{$dyFile} = $i + 1; |
| 3242 |
$setTags = $setTagsList{$dyFile}[$i] if $setTagsList{$dyFile}[$i]; |
| 3243 |
} |
| 3244 |
# set new values values from file |
| 3245 |
return 0 unless DoSetFromFile($et, $fromFile, $setTags); |
| 3246 |
} elsif (ref $dyFile eq 'ARRAY') { |
| 3247 |
# a dynamic file containing a simple tag value |
| 3248 |
my $fname = FilenameSPrintf($$dyFile[1], $orig); |
| 3249 |
my ($buff, $rtn, $wrn); |
| 3250 |
my $opts = $$dyFile[2]; |
| 3251 |
if (defined $fname and SlurpFile($fname, \$buff)) { |
| 3252 |
$verbose and print $vout "Reading $$dyFile[0] from $fname\n"; |
| 3253 |
($rtn, $wrn) = $et->SetNewValue($$dyFile[0], $buff, %$opts); |
| 3254 |
$wrn and Warn "$wrn\n"; |
| 3255 |
} |
| 3256 |
# remove this tag if we couldn't set it properly |
| 3257 |
$rtn or $et->SetNewValue($$dyFile[0], undef, Replace => 2, |
| 3258 |
ProtectSaved => $$opts{ProtectSaved}); |
| 3259 |
next; |
| 3260 |
} elsif (ref $dyFile eq 'SCALAR') { |
| 3261 |
# set new values from CSV or JSON database |
| 3262 |
my ($f, $found, $csvTag, $tg, $csvEtPrt, $csvEtVal); |
| 3263 |
undef $evalWarning; |
| 3264 |
local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; |
| 3265 |
# force UTF-8 if the database was JSON |
| 3266 |
my $old = $et->Options('Charset'); |
| 3267 |
$et->Options(Charset => 'UTF8') if $csv eq 'JSON'; |
| 3268 |
# read tags for SourceFile '*' plus the specific file |
| 3269 |
foreach $f ('*', MyConvertFileName($et, $file)) { |
| 3270 |
my $csvInfo = $database{$f}; |
| 3271 |
unless ($csvInfo) { |
| 3272 |
next if $f eq '*'; |
| 3273 |
# check absolute path and case-insensitive name |
| 3274 |
# (punt on using ConvertFileName here, so $absPath may be a mix of encodings) |
| 3275 |
my $absPath = AbsPath($f); |
| 3276 |
if (defined $absPath and $database{$absPath}) { |
| 3277 |
$csvInfo = $database{$absPath}; |
| 3278 |
} elsif ($database{lc $f}) { |
| 3279 |
$csvInfo = $database{lc $f}; |
| 3280 |
} elsif (defined $absPath and $database{lc $absPath}) { |
| 3281 |
$csvInfo = $database{lc $absPath}; |
| 3282 |
} else { |
| 3283 |
next; |
| 3284 |
} |
| 3285 |
} |
| 3286 |
$found = 1; |
| 3287 |
if ($verbose) { |
| 3288 |
print $vout "Setting new values from $csv database\n"; |
| 3289 |
print $vout 'Including tags: ',join(' ',@tags),"\n" if @tags; |
| 3290 |
print $vout 'Excluding tags: ',join(' ',@csvExclude),"\n" if @csvExclude; |
| 3291 |
} |
| 3292 |
if (@tags) { |
| 3293 |
# prepare a dummy ExifTool object to hold appropriate tags from the database |
| 3294 |
$csvEtPrt = Image::ExifTool->new unless $csvEtPrt; |
| 3295 |
foreach $csvTag (OrderedKeys($csvInfo)) { |
| 3296 |
next if $csvTag =~ /^([-_0-9A-Z]+:)*(SourceFile|Directory|FileName)$/i; |
| 3297 |
my @grps = split /:/, $csvTag; |
| 3298 |
my $name = pop @grps; |
| 3299 |
unshift @grps, 'All' while @grps < 2; |
| 3300 |
if ($name =~ s/#$//) { |
| 3301 |
# handle ValueConv tags separately |
| 3302 |
$csvEtVal = Image::ExifTool->new unless $csvEtVal; |
| 3303 |
$csvEtVal->FoundTag($name, $$csvInfo{$csvTag}, @grps); |
| 3304 |
} else { |
| 3305 |
$csvEtPrt->FoundTag($name, $$csvInfo{$csvTag}, @grps); |
| 3306 |
} |
| 3307 |
} |
| 3308 |
next; |
| 3309 |
} |
| 3310 |
my @exclTags = @csvExclude; |
| 3311 |
foreach (@exclTags) { |
| 3312 |
tr/-0-9a-zA-Z_:#?*//dc; # remove illegal characters |
| 3313 |
s/(^|:)(all:)+/$1/ig; # remove 'all' group names |
| 3314 |
s/(^|:)all(#?)$/$1*$2/i; # convert 'all' tag name to '*' |
| 3315 |
tr/?/./; s/\*/.*/g; # convert wildcards for regex |
| 3316 |
} |
| 3317 |
# run through tags in database order |
| 3318 |
foreach $csvTag (OrderedKeys($csvInfo)) { |
| 3319 |
# don't write SourceFile, Directory or FileName |
| 3320 |
next if $csvTag =~ /^([-_0-9A-Z]+:)*(SourceFile|Directory|FileName)$/i; |
| 3321 |
if (@exclTags) { |
| 3322 |
my ($exclTag, $exclGrp, $excluded); |
| 3323 |
ExclMatch: foreach $exclTag (@exclTags) { |
| 3324 |
if ($exclTag =~ /:/) { |
| 3325 |
next unless $csvTag =~ /:/; # db entry must also specify group |
| 3326 |
my @csvGrps = split /:/, $csvTag; |
| 3327 |
my @exclGrps = split /:/, $exclTag; |
| 3328 |
my $exclName = pop @exclGrps; |
| 3329 |
next unless pop(@csvGrps) =~ /^$exclName$/i; # tag name must match |
| 3330 |
foreach $exclGrp (@exclGrps) { |
| 3331 |
# each specified group name must match db entry |
| 3332 |
next ExclMatch unless grep /^$exclGrp$/i, @csvGrps; |
| 3333 |
} |
| 3334 |
$excluded = 1; |
| 3335 |
last; |
| 3336 |
} |
| 3337 |
# no group specified, so match by tag name only |
| 3338 |
$csvTag =~ /^([-_0-9A-Z]+:)*$exclTag$/i and $excluded = 1, last; |
| 3339 |
} |
| 3340 |
next if $excluded; |
| 3341 |
} |
| 3342 |
my ($rtn, $wrn) = $et->SetNewValue($csvTag, $$csvInfo{$csvTag}, |
| 3343 |
Protected => 1, AddValue => $dbAdd, |
| 3344 |
ProtectSaved => $dbSaveCount); |
| 3345 |
$wrn and Warn "$wrn\n" if $verbose; |
| 3346 |
} |
| 3347 |
} |
| 3348 |
# set specified tags now |
| 3349 |
if ($csvEtPrt) { |
| 3350 |
my @excl = map "-$_", @csvExclude; # add back leading dashes |
| 3351 |
my $opts = { AddValue => $dbAdd, Replace => 0 }; |
| 3352 |
$et->SetNewValuesFromFile($csvEtPrt, $opts, @tags, @excl); |
| 3353 |
if ($csvEtVal) { |
| 3354 |
$$opts{Type} = 'ValueConv'; |
| 3355 |
$et->SetNewValuesFromFile($csvEtVal, $opts, @tags, @excl); |
| 3356 |
} |
| 3357 |
} |
| 3358 |
$et->Options(Charset => $old) if $csv eq 'JSON'; |
| 3359 |
unless ($found) { |
| 3360 |
Warn("No SourceFile '${file}' in imported $csv database\n"); |
| 3361 |
my $absPath = AbsPath($file); |
| 3362 |
Warn("(full path: '${absPath}')\n") if defined $absPath and $absPath ne $file; |
| 3363 |
return 0; |
| 3364 |
} |
| 3365 |
} |
| 3366 |
} |
| 3367 |
} |
| 3368 |
if ($isStdout) { |
| 3369 |
# write to STDOUT |
| 3370 |
$outfile = \*STDOUT; |
| 3371 |
unless ($binaryStdout) { |
| 3372 |
binmode(STDOUT); |
| 3373 |
$binaryStdout = 1; |
| 3374 |
} |
| 3375 |
} else { |
| 3376 |
# get name of hard link if we are creating one |
| 3377 |
$hardLink = $et->GetNewValues('HardLink'); |
| 3378 |
$symLink = $et->GetNewValues('SymLink'); |
| 3379 |
$testName = $et->GetNewValues('TestName'); |
| 3380 |
$hardLink = FilenameSPrintf($hardLink, $orig) if defined $hardLink; |
| 3381 |
$symLink = FilenameSPrintf($symLink, $orig) if defined $symLink; |
| 3382 |
# determine what our output file name should be |
| 3383 |
my $newFileName = $et->GetNewValues('FileName'); |
| 3384 |
my $newDir = $et->GetNewValues('Directory'); |
| 3385 |
if (defined $newFileName and not length $newFileName) { |
| 3386 |
Warning($et,"New file name is empty - $infile"); |
| 3387 |
undef $newFileName; |
| 3388 |
} |
| 3389 |
if (defined $testName) { |
| 3390 |
my $err; |
| 3391 |
$err = "You shouldn't write FileName or Directory with TestFile" if defined $newFileName or defined $newDir; |
| 3392 |
$err = "The -o option shouldn't be used with TestFile" if defined $outfile; |
| 3393 |
$err and Warn("Error: $err - $infile\n"), EFile($infile), ++$countBadWr, return 0; |
| 3394 |
$testName = FilenameSPrintf($testName, $orig); |
| 3395 |
$testName = Image::ExifTool::GetNewFileName($file, $testName) if $file ne ''; |
| 3396 |
} |
| 3397 |
if (defined $newFileName or defined $newDir or ($doSetFileName and defined $outfile)) { |
| 3398 |
if ($newFileName) { |
| 3399 |
$newFileName = FilenameSPrintf($newFileName, $orig); |
| 3400 |
if (defined $outfile) { |
| 3401 |
$outfile = Image::ExifTool::GetNewFileName($file, $outfile) if $file ne ''; |
| 3402 |
$outfile = Image::ExifTool::GetNewFileName($outfile, $newFileName); |
| 3403 |
} elsif ($file ne '') { |
| 3404 |
$outfile = Image::ExifTool::GetNewFileName($file, $newFileName); |
| 3405 |
} |
| 3406 |
} |
| 3407 |
if ($newDir) { |
| 3408 |
$newDir = FilenameSPrintf($newDir, $orig); |
| 3409 |
$outfile = Image::ExifTool::GetNewFileName(defined $outfile ? $outfile : $file, $newDir); |
| 3410 |
} |
| 3411 |
$outfile = NextUnusedFilename($outfile, $infile); |
| 3412 |
if ($et->Exists($outfile, 1)) { |
| 3413 |
if ($infile eq $outfile) { |
| 3414 |
undef $outfile; # not changing the file name after all |
| 3415 |
# (allow for case-insensitive filesystems) |
| 3416 |
} elsif ($et->IsSameFile($infile, $outfile)) { |
| 3417 |
$sameFile = $outfile; # same file, but the name has a different case |
| 3418 |
} else { |
| 3419 |
Warn "Error: '${outfile}' already exists - $infile\n"; |
| 3420 |
EFile($infile); |
| 3421 |
++$countBadWr; |
| 3422 |
return 0; |
| 3423 |
} |
| 3424 |
} |
| 3425 |
} |
| 3426 |
if (defined $outfile) { |
| 3427 |
defined $verbose and print $vout "'${infile}' --> '${outfile}'\n"; |
| 3428 |
# create output directory if necessary |
| 3429 |
CreateDirectory($outfile); |
| 3430 |
# set temporary file (automatically erased on abnormal exit) |
| 3431 |
$tmpFile = $outfile if defined $outOpt; |
| 3432 |
} |
| 3433 |
unless (defined $tmpFile) { |
| 3434 |
# count the number of tags and pseudo-tags we are writing |
| 3435 |
my ($numSet, $numPseudo) = $et->CountNewValues(); |
| 3436 |
if ($numSet != $numPseudo and $et->IsDirectory($file)) { |
| 3437 |
print $vout "Can't write real tags to a directory - $infile\n" if defined $verbose; |
| 3438 |
$numSet = $numPseudo; |
| 3439 |
} |
| 3440 |
if ($et->Exists($file)) { |
| 3441 |
unless ($numSet) { |
| 3442 |
# no need to write if no tags set |
| 3443 |
print $vout "Nothing changed in $file\n" if defined $verbose; |
| 3444 |
EFile($infile, 1); |
| 3445 |
++$countSameWr; |
| 3446 |
return 1; |
| 3447 |
} |
| 3448 |
} elsif (CanCreate($file)) { |
| 3449 |
if ($numSet == $numPseudo) { |
| 3450 |
# no need to write if no real tags |
| 3451 |
Warn("Error: Nothing to write - $file\n"); |
| 3452 |
EFile($infile, 1); |
| 3453 |
++$countBadWr; |
| 3454 |
return 0; |
| 3455 |
} |
| 3456 |
unless (defined $outfile) { |
| 3457 |
# create file from scratch |
| 3458 |
$outfile = $file; |
| 3459 |
$file = ''; |
| 3460 |
} |
| 3461 |
} else { |
| 3462 |
# file doesn't exist, and we can't create it |
| 3463 |
Warn "Error: File not found - $file\n"; |
| 3464 |
EFile($infile); |
| 3465 |
FileNotFound($file); |
| 3466 |
++$countBadWr; |
| 3467 |
return 0; |
| 3468 |
} |
| 3469 |
# quickly rename file and/or set file date if this is all we are doing |
| 3470 |
if ($numSet == $numPseudo) { |
| 3471 |
my ($r0, $r1, $r2, $r3) = (0, 0, 0, 0); |
| 3472 |
if (defined $outfile) { |
| 3473 |
$r0 = $et->SetFileName($file, $outfile); |
| 3474 |
$file = $$et{NewName} if $r0 > 0; # continue with new name if changed |
| 3475 |
} |
| 3476 |
unless ($r0 < 0) { |
| 3477 |
$r1 = $et->SetFileModifyDate($file,undef,'FileCreateDate'); |
| 3478 |
$r2 = $et->SetFileModifyDate($file); |
| 3479 |
$r3 = $et->SetSystemTags($file); |
| 3480 |
} |
| 3481 |
if ($r0 > 0 or $r1 > 0 or $r2 > 0 or $r3 > 0) { |
| 3482 |
EFile($infile, 3); |
| 3483 |
++$countGoodWr; |
| 3484 |
} elsif ($r0 < 0 or $r1 < 0 or $r2 < 0 or $r3 < 0) { |
| 3485 |
EFile($infile); |
| 3486 |
++$countBadWr; |
| 3487 |
return 0; |
| 3488 |
} else { |
| 3489 |
EFile($infile, 1); |
| 3490 |
++$countSameWr; |
| 3491 |
} |
| 3492 |
if (defined $hardLink or defined $symLink or defined $testName) { |
| 3493 |
DoHardLink($et, $file, $hardLink, $symLink, $testName); |
| 3494 |
} |
| 3495 |
return 1; |
| 3496 |
} |
| 3497 |
if (not defined $outfile or defined $sameFile) { |
| 3498 |
# write to a truly temporary file |
| 3499 |
$outfile = "${file}_exiftool_tmp"; |
| 3500 |
if ($et->Exists($outfile)) { |
| 3501 |
Warn("Error: Temporary file already exists: $outfile\n"); |
| 3502 |
EFile($infile); |
| 3503 |
++$countBadWr; |
| 3504 |
return 0; |
| 3505 |
} |
| 3506 |
$isTemporary = 1; |
| 3507 |
} |
| 3508 |
# new output file is temporary until we know it has been written properly |
| 3509 |
$tmpFile = $outfile; |
| 3510 |
} |
| 3511 |
} |
| 3512 |
# rewrite the file |
| 3513 |
my $success = $et->WriteInfo(Infile($file), $outfile, $outType); |
| 3514 |
|
| 3515 |
# create hard link if specified |
| 3516 |
if ($success and (defined $hardLink or defined $symLink or defined $testName)) { |
| 3517 |
my $src = defined $outfile ? $outfile : $file; |
| 3518 |
DoHardLink($et, $src, $hardLink, $symLink, $testName); |
| 3519 |
} |
| 3520 |
|
| 3521 |
# get file time if preserving it |
| 3522 |
my ($aTime, $mTime, $cTime, $doPreserve); |
| 3523 |
$doPreserve = $preserveTime unless $file eq ''; |
| 3524 |
if ($doPreserve and $success) { |
| 3525 |
($aTime, $mTime, $cTime) = $et->GetFileTime($file); |
| 3526 |
# don't override date/time values written by the user |
| 3527 |
undef $cTime if $$et{WRITTEN}{FileCreateDate}; |
| 3528 |
if ($$et{WRITTEN}{FileModifyDate} or $doPreserve == 2) { |
| 3529 |
if (defined $cTime) { |
| 3530 |
undef $aTime; # only preserve FileCreateDate |
| 3531 |
undef $mTime; |
| 3532 |
} else { |
| 3533 |
undef $doPreserve; # (nothing to preserve) |
| 3534 |
} |
| 3535 |
} |
| 3536 |
} |
| 3537 |
|
| 3538 |
if ($success == 1) { |
| 3539 |
# preserve the original file times |
| 3540 |
if (defined $tmpFile) { |
| 3541 |
if ($et->Exists($file)) { |
| 3542 |
$et->SetFileTime($tmpFile, $aTime, $mTime, $cTime) if $doPreserve; |
| 3543 |
if ($isTemporary) { |
| 3544 |
# preserve original file attributes if possible |
| 3545 |
$et->CopyFileAttrs($file, $outfile); |
| 3546 |
# move original out of the way |
| 3547 |
my $original = "${file}_original"; |
| 3548 |
if (not $overwriteOrig and not $et->Exists($original)) { |
| 3549 |
# rename the file and check again to be sure the file doesn't exist |
| 3550 |
# (in case, say, the filesystem truncated the file extension) |
| 3551 |
if (not $et->Rename($file, $original) or $et->Exists($file)) { |
| 3552 |
Error "Error renaming $file\n"; |
| 3553 |
return 0; |
| 3554 |
} |
| 3555 |
} |
| 3556 |
my $dstFile = defined $sameFile ? $sameFile : $file; |
| 3557 |
if ($overwriteOrig > 1) { |
| 3558 |
# copy temporary file over top of original to preserve attributes |
| 3559 |
my ($err, $buff); |
| 3560 |
my $newFile = $tmpFile; |
| 3561 |
$et->Open(\*NEW_FILE, $newFile) or Error("Error opening $newFile\n"), return 0; |
| 3562 |
binmode(NEW_FILE); |
| 3563 |
|
| 3564 |
#.......................................................... |
| 3565 |
# temporarily disable CTRL-C during this critical operation |
| 3566 |
$critical = 1; |
| 3567 |
undef $tmpFile; # handle deletion of temporary file ourself |
| 3568 |
if ($et->Open(\*ORIG_FILE, $file, '+<')) { |
| 3569 |
binmode(ORIG_FILE); |
| 3570 |
while (read(NEW_FILE, $buff, 65536)) { |
| 3571 |
print ORIG_FILE $buff or $err = 1; |
| 3572 |
} |
| 3573 |
close(NEW_FILE); |
| 3574 |
# Handle files being shorter than the original |
| 3575 |
eval { truncate(ORIG_FILE, tell(ORIG_FILE)) } or $err = 1; |
| 3576 |
close(ORIG_FILE) or $err = 1; |
| 3577 |
if ($err) { |
| 3578 |
Warn "Couldn't overwrite in place - $file\n"; |
| 3579 |
unless ($et->Rename($newFile, $file) or |
| 3580 |
($et->Unlink($file) and $et->Rename($newFile, $file))) |
| 3581 |
{ |
| 3582 |
Error("Error renaming $newFile to $file\n"); |
| 3583 |
undef $critical; |
| 3584 |
SigInt() if $interrupted; |
| 3585 |
return 0; |
| 3586 |
} |
| 3587 |
} else { |
| 3588 |
$et->SetFileModifyDate($file, $cTime, 'FileCreateDate', 1); |
| 3589 |
$et->SetFileModifyDate($file, $mTime, 'FileModifyDate', 1); |
| 3590 |
$et->Unlink($newFile); |
| 3591 |
if ($doPreserve) { |
| 3592 |
$et->SetFileTime($file, $aTime, $mTime, $cTime); |
| 3593 |
# save time to set it later again to patch OS X 10.6 bug |
| 3594 |
$preserveTime{$file} = [ $aTime, $mTime, $cTime ]; |
| 3595 |
} |
| 3596 |
} |
| 3597 |
EFile($infile, 3); |
| 3598 |
++$countGoodWr; |
| 3599 |
} else { |
| 3600 |
close(NEW_FILE); |
| 3601 |
Warn "Error opening $file for writing\n"; |
| 3602 |
EFile($infile); |
| 3603 |
$et->Unlink($newFile); |
| 3604 |
++$countBadWr; |
| 3605 |
} |
| 3606 |
undef $critical; # end critical section |
| 3607 |
SigInt() if $interrupted; # issue delayed SIGINT if necessary |
| 3608 |
#.......................................................... |
| 3609 |
|
| 3610 |
# simply rename temporary file to replace original |
| 3611 |
# (if we didn't already rename it to add "_original") |
| 3612 |
} elsif ($et->Rename($tmpFile, $dstFile)) { |
| 3613 |
EFile($infile, 3); |
| 3614 |
++$countGoodWr; |
| 3615 |
} else { |
| 3616 |
my $newFile = $tmpFile; |
| 3617 |
undef $tmpFile; # (avoid deleting file if we get interrupted) |
| 3618 |
# unlink may fail if already renamed or no permission |
| 3619 |
if (not $et->Unlink($file)) { |
| 3620 |
Warn "Error renaming temporary file to $dstFile\n"; |
| 3621 |
EFile($infile); |
| 3622 |
$et->Unlink($newFile); |
| 3623 |
++$countBadWr; |
| 3624 |
# try renaming again now that the target has been deleted |
| 3625 |
} elsif (not $et->Rename($newFile, $dstFile)) { |
| 3626 |
Warn "Error renaming temporary file to $dstFile\n"; |
| 3627 |
EFile($infile); |
| 3628 |
# (don't delete tmp file now because it is all we have left) |
| 3629 |
++$countBadWr; |
| 3630 |
} else { |
| 3631 |
EFile($infile, 3); |
| 3632 |
++$countGoodWr; |
| 3633 |
} |
| 3634 |
} |
| 3635 |
} elsif ($overwriteOrig) { |
| 3636 |
# erase original file |
| 3637 |
EFile($infile, 3); |
| 3638 |
$et->Unlink($file) or Warn "Error erasing original $file\n"; |
| 3639 |
++$countGoodWr; |
| 3640 |
} else { |
| 3641 |
EFile($infile, 4); |
| 3642 |
++$countGoodCr; |
| 3643 |
} |
| 3644 |
} else { |
| 3645 |
# this file was created from scratch, not edited |
| 3646 |
EFile($infile, 4); |
| 3647 |
++$countGoodCr; |
| 3648 |
} |
| 3649 |
} else { |
| 3650 |
EFile($infile, 3); |
| 3651 |
++$countGoodWr; |
| 3652 |
} |
| 3653 |
} elsif ($success) { |
| 3654 |
EFile($infile, 1); |
| 3655 |
if ($isTemporary) { |
| 3656 |
# just erase the temporary file since no changes were made |
| 3657 |
$et->Unlink($tmpFile); |
| 3658 |
++$countSameWr; |
| 3659 |
} else { |
| 3660 |
$et->SetFileTime($outfile, $aTime, $mTime, $cTime) if $doPreserve; |
| 3661 |
if ($overwriteOrig) { |
| 3662 |
$et->Unlink($file) or Warn "Error erasing original $file\n"; |
| 3663 |
} |
| 3664 |
++$countCopyWr; |
| 3665 |
} |
| 3666 |
print $vout "Nothing changed in $file\n" if defined $verbose; |
| 3667 |
} else { |
| 3668 |
EFile($infile); |
| 3669 |
$et->Unlink($tmpFile) if defined $tmpFile; |
| 3670 |
++$countBadWr; |
| 3671 |
} |
| 3672 |
undef $tmpFile; |
| 3673 |
return $success; |
| 3674 |
} |
| 3675 |
|
| 3676 |
#------------------------------------------------------------------------------ |
| 3677 |
# Make hard link and handle TestName if specified |
| 3678 |
# Inputs: 0) ExifTool ref, 1) source file name, 2) HardLink name, |
| 3679 |
# 3) SymLink name, 4) TestFile name |
| 3680 |
sub DoHardLink($$$$$) |
| 3681 |
{ |
| 3682 |
my ($et, $src, $hardLink, $symLink, $testName) = @_; |
| 3683 |
if (defined $hardLink) { |
| 3684 |
$hardLink = NextUnusedFilename($hardLink); |
| 3685 |
if ($et->SetFileName($src, $hardLink, 'Link') > 0) { |
| 3686 |
$countLink{Hard} = ($countLink{Hard} || 0) + 1; |
| 3687 |
} else { |
| 3688 |
$countLink{BadHard} = ($countLink{BadHard} || 0) + 1; |
| 3689 |
} |
| 3690 |
} |
| 3691 |
if (defined $symLink) { |
| 3692 |
$symLink = NextUnusedFilename($symLink); |
| 3693 |
if ($et->SetFileName($src, $symLink, 'SymLink') > 0) { |
| 3694 |
$countLink{Sym} = ($countLink{Sym} || 0) + 1; |
| 3695 |
} else { |
| 3696 |
$countLink{BadSym} = ($countLink{BadSym} || 0) + 1; |
| 3697 |
} |
| 3698 |
} |
| 3699 |
if (defined $testName) { |
| 3700 |
$testName = NextUnusedFilename($testName, $src); |
| 3701 |
if ($usedFileName{$testName}) { |
| 3702 |
$et->Warn("File '${testName}' would exist"); |
| 3703 |
} elsif ($et->SetFileName($src, $testName, 'Test', $usedFileName{$testName}) == 1) { |
| 3704 |
$usedFileName{$testName} = 1; |
| 3705 |
$usedFileName{$src} = 0; |
| 3706 |
} |
| 3707 |
} |
| 3708 |
} |
| 3709 |
|
| 3710 |
#------------------------------------------------------------------------------ |
| 3711 |
# Clean string for XML (also removes invalid control chars and malformed UTF-8) |
| 3712 |
# Inputs: 0) string ref |
| 3713 |
# Returns: nothing, but input string is escaped |
| 3714 |
sub CleanXML($) |
| 3715 |
{ |
| 3716 |
my $strPt = shift; |
| 3717 |
# translate control characters that are invalid in XML |
| 3718 |
$$strPt =~ tr/\0-\x08\x0b\x0c\x0e-\x1f/./; |
| 3719 |
# fix malformed UTF-8 characters |
| 3720 |
Image::ExifTool::XMP::FixUTF8($strPt) unless $altEnc; |
| 3721 |
# escape necessary characters for XML |
| 3722 |
$$strPt = Image::ExifTool::XMP::EscapeXML($$strPt); |
| 3723 |
} |
| 3724 |
|
| 3725 |
#------------------------------------------------------------------------------ |
| 3726 |
# Encode string for XML |
| 3727 |
# Inputs: 0) string ref |
| 3728 |
# Returns: encoding used (and input string is translated) |
| 3729 |
sub EncodeXML($) |
| 3730 |
{ |
| 3731 |
my $strPt = shift; |
| 3732 |
if ($$strPt =~ /[\0-\x08\x0b\x0c\x0e-\x1f]/ or |
| 3733 |
(not $altEnc and Image::ExifTool::IsUTF8($strPt) < 0)) |
| 3734 |
{ |
| 3735 |
# encode binary data and non-UTF8 with special characters as base64 |
| 3736 |
$$strPt = Image::ExifTool::XMP::EncodeBase64($$strPt); |
| 3737 |
# #ATV = Alexander Vonk, private communication |
| 3738 |
return 'http://www.w3.org/2001/XMLSchema#base64Binary'; #ATV |
| 3739 |
} elsif ($escapeHTML) { |
| 3740 |
$$strPt = Image::ExifTool::HTML::EscapeHTML($$strPt, $altEnc); |
| 3741 |
} else { |
| 3742 |
$$strPt = Image::ExifTool::XMP::EscapeXML($$strPt); |
| 3743 |
} |
| 3744 |
return ''; # not encoded |
| 3745 |
} |
| 3746 |
|
| 3747 |
#------------------------------------------------------------------------------ |
| 3748 |
# Format value for XML output |
| 3749 |
# Inputs: 0) value, 1) indentation, 2) group |
| 3750 |
# Returns: formatted value |
| 3751 |
sub FormatXML($$$) |
| 3752 |
{ |
| 3753 |
local $_; |
| 3754 |
my ($val, $ind, $grp) = @_; |
| 3755 |
my $gt = '>'; |
| 3756 |
if (ref $val eq 'ARRAY') { |
| 3757 |
# convert ARRAY into an rdf:Bag |
| 3758 |
my $val2 = "\n$ind <rdf:Bag>"; |
| 3759 |
foreach (@$val) { |
| 3760 |
$val2 .= "\n$ind <rdf:li" . FormatXML($_, "$ind ", $grp) . "</rdf:li>"; |
| 3761 |
} |
| 3762 |
$val = "$val2\n$ind </rdf:Bag>\n$ind"; |
| 3763 |
} elsif (ref $val eq 'HASH') { |
| 3764 |
$gt = " rdf:parseType='Resource'>"; |
| 3765 |
my $val2 = ''; |
| 3766 |
foreach (OrderedKeys($val)) { |
| 3767 |
# (some variable-namespace XML structure fields may have a different group) |
| 3768 |
my ($ns, $tg) = ($grp, $_); |
| 3769 |
if (/^(.*?):(.*)/) { |
| 3770 |
if ($grp eq 'JSON') { |
| 3771 |
$tg =~ tr/:/_/; # colons in JSON structure elements are not namespaces |
| 3772 |
} else { |
| 3773 |
($ns, $tg) = ($1, $2); |
| 3774 |
} |
| 3775 |
} |
| 3776 |
# validate XML attribute name |
| 3777 |
my $name; |
| 3778 |
foreach $name ($ns, $tg) { |
| 3779 |
# make sure name is valid for XML |
| 3780 |
$name =~ tr/-_A-Za-z0-9.//dc; |
| 3781 |
$name = '_' . $name if $name !~ /^[_A-Za-z]/; |
| 3782 |
} |
| 3783 |
my $tok = $ns . ':' . $tg; |
| 3784 |
$val2 .= "\n$ind <$tok" . FormatXML($$val{$_}, "$ind ", $grp) . "</$tok>"; |
| 3785 |
} |
| 3786 |
$val = "$val2\n$ind"; |
| 3787 |
} else { |
| 3788 |
# (note: SCALAR reference should have already been converted) |
| 3789 |
my $enc = EncodeXML(\$val); |
| 3790 |
$gt = " rdf:datatype='${enc}'>\n" if $enc; #ATV |
| 3791 |
} |
| 3792 |
return $gt . $val; |
| 3793 |
} |
| 3794 |
|
| 3795 |
#------------------------------------------------------------------------------ |
| 3796 |
# Escape string for JSON or PHP |
| 3797 |
# Inputs: 0) string, 1) flag to force numbers to be quoted too |
| 3798 |
# Returns: Escaped string (quoted if necessary) |
| 3799 |
sub EscapeJSON($;$) |
| 3800 |
{ |
| 3801 |
my ($str, $quote) = @_; |
| 3802 |
unless ($quote) { |
| 3803 |
# JSON boolean (true or false) |
| 3804 |
return lc($str) if $str =~ /^(true|false)$/i and $json < 2; |
| 3805 |
# JSON/PHP number (see json.org for numerical format) |
| 3806 |
# return $str if $str =~ /^-?(\d|[1-9]\d+)(\.\d+)?(e[-+]?\d+)?$/i; |
| 3807 |
# (these big numbers caused problems for some JSON parsers, so be more conservative) |
| 3808 |
return $str if $str =~ /^-?(\d|[1-9]\d{1,14})(\.\d{1,16})?(e[-+]?\d{1,3})?$/i; |
| 3809 |
} |
| 3810 |
# encode JSON string in base64 if necessary |
| 3811 |
if ($json < 2 and defined $binaryOutput and Image::ExifTool::IsUTF8(\$str) < 0) { |
| 3812 |
return '"base64:' . Image::ExifTool::XMP::EncodeBase64($str, 1) . '"'; |
| 3813 |
} |
| 3814 |
# escape special characters |
| 3815 |
$str =~ s/(["\t\n\r\\])/\\$jsonChar{$1}/sg; |
| 3816 |
if ($json < 2) { # JSON |
| 3817 |
$str =~ tr/\0//d; # remove all nulls |
| 3818 |
# escape other control characters with \u |
| 3819 |
$str =~ s/([\0-\x1f\x7f])/sprintf("\\u%.4X",ord $1)/sge; |
| 3820 |
# JSON strings must be valid UTF8 |
| 3821 |
Image::ExifTool::XMP::FixUTF8(\$str) unless $altEnc; |
| 3822 |
} else { # PHP |
| 3823 |
$str =~ s/\0+$// unless $isBinary; # remove trailing nulls unless binary |
| 3824 |
# must escape "$" too for PHP |
| 3825 |
$str =~ s/\$/\\\$/sg; |
| 3826 |
# escape other control characters with \x |
| 3827 |
$str =~ s/([\0-\x1f\x7f])/sprintf("\\x%.2X",ord $1)/sge; |
| 3828 |
} |
| 3829 |
return '"' . $str . '"'; # return the quoted string |
| 3830 |
} |
| 3831 |
|
| 3832 |
#------------------------------------------------------------------------------ |
| 3833 |
# Print JSON or PHP value |
| 3834 |
# Inputs: 0) file reference, 1) value, 2) indentation, 3) true to quote numbers |
| 3835 |
sub FormatJSON($$$;$) |
| 3836 |
{ |
| 3837 |
local $_; |
| 3838 |
my ($fp, $val, $ind, $quote) = @_; |
| 3839 |
my $comma; |
| 3840 |
if (not ref $val) { |
| 3841 |
print $fp EscapeJSON($val, $quote); |
| 3842 |
} elsif (ref $val eq 'ARRAY') { |
| 3843 |
if ($joinLists and not ref $$val[0]) { |
| 3844 |
print $fp EscapeJSON(join($listSep, @$val), $quote); |
| 3845 |
} else { |
| 3846 |
my ($bra, $ket) = $json == 1 ? ('[',']') : ('Array(',')'); |
| 3847 |
print $fp $bra; |
| 3848 |
foreach (@$val) { |
| 3849 |
print $fp ',' if $comma; |
| 3850 |
FormatJSON($fp, $_, $ind, $quote); |
| 3851 |
$comma = 1, |
| 3852 |
} |
| 3853 |
print $fp $ket, |
| 3854 |
} |
| 3855 |
} elsif (ref $val eq 'HASH') { |
| 3856 |
my ($bra, $ket, $sep) = $json == 1 ? ('{','}',':') : ('Array(',')',' =>'); |
| 3857 |
print $fp $bra; |
| 3858 |
foreach (OrderedKeys($val)) { |
| 3859 |
print $fp ',' if $comma; |
| 3860 |
my $key = EscapeJSON($_, 1); |
| 3861 |
print $fp qq(\n$ind $key$sep ); |
| 3862 |
# hack to force decimal id's to be printed as strings with -H |
| 3863 |
if ($showTagID and $_ eq 'id' and $showTagID eq 'H' and $$val{$_} =~ /^\d+\.\d+$/) { |
| 3864 |
print $fp qq{"$$val{$_}"}; |
| 3865 |
} else { |
| 3866 |
FormatJSON($fp, $$val{$_}, "$ind ", $quote); |
| 3867 |
} |
| 3868 |
$comma = 1, |
| 3869 |
} |
| 3870 |
print $fp "\n$ind$ket", |
| 3871 |
} else { |
| 3872 |
# (note: SCALAR reference should have already been converted) |
| 3873 |
print $fp '"<err>"'; |
| 3874 |
} |
| 3875 |
} |
| 3876 |
|
| 3877 |
#------------------------------------------------------------------------------ |
| 3878 |
# Format value for CSV file |
| 3879 |
# Inputs: value |
| 3880 |
# Returns: value quoted if necessary |
| 3881 |
sub FormatCSV($) |
| 3882 |
{ |
| 3883 |
my $val = shift; |
| 3884 |
# check for valid encoding if the Charset option was used |
| 3885 |
if ($setCharset and ($val =~ /[^\x09\x0a\x0d\x20-\x7e\x80-\xff]/ or |
| 3886 |
($setCharset eq 'UTF8' and Image::ExifTool::IsUTF8(\$val) < 0))) |
| 3887 |
{ |
| 3888 |
$val = 'base64:' . Image::ExifTool::XMP::EncodeBase64($val, 1); |
| 3889 |
} |
| 3890 |
# currently, there is a chance that the value may contain NULL characters unless |
| 3891 |
# the -b option is used to encode as Base64. It is unclear whether or not this |
| 3892 |
# is valid CSV, but some readers may not like it. (If this becomes a problem, |
| 3893 |
# in the future values may need to be truncated at the first NULL character.) |
| 3894 |
$val = qq{"$val"} if $val =~ s/"/""/g or $val =~ /(^\s+|\s+$)/ or $val =~ /[\n\r]|\Q$csvDelim/; |
| 3895 |
return $val; |
| 3896 |
} |
| 3897 |
|
| 3898 |
#------------------------------------------------------------------------------ |
| 3899 |
# Print accumulated CSV information |
| 3900 |
# Inputs: 0) file ref |
| 3901 |
sub PrintCSV(;$) |
| 3902 |
{ |
| 3903 |
my $fp = shift || \*STDOUT; |
| 3904 |
my ($file, $lcTag, @tags); |
| 3905 |
|
| 3906 |
@csvTags or @csvTags = sort keys %csvTags; |
| 3907 |
# make a list of tags actually found |
| 3908 |
foreach $lcTag (@csvTags) { |
| 3909 |
push @tags, FormatCSV($csvTags{$lcTag}) if $csvTags{$lcTag}; |
| 3910 |
} |
| 3911 |
print $fp join($csvDelim, 'SourceFile', @tags), "\n"; |
| 3912 |
my $empty = defined($forcePrint) ? $forcePrint : ''; |
| 3913 |
foreach $file (@csvFiles) { |
| 3914 |
my @vals = (FormatCSV($file)); # start with full file name |
| 3915 |
my $csvInfo = $database{$file}; |
| 3916 |
foreach $lcTag (@csvTags) { |
| 3917 |
next unless $csvTags{$lcTag}; |
| 3918 |
my $val = $$csvInfo{$lcTag}; |
| 3919 |
defined $val or push(@vals,$empty), next; |
| 3920 |
push @vals, FormatCSV($val); |
| 3921 |
} |
| 3922 |
print $fp join($csvDelim, @vals), "\n"; |
| 3923 |
} |
| 3924 |
} |
| 3925 |
|
| 3926 |
#------------------------------------------------------------------------------ |
| 3927 |
# Add tag groups from structure fields to a list for xmlns |
| 3928 |
# Inputs: 0) tag value, 1) parent group, 2) group hash ref, 3) group list ref |
| 3929 |
sub AddGroups($$$$) |
| 3930 |
{ |
| 3931 |
my ($val, $grp, $groupHash, $groupList) = @_; |
| 3932 |
my ($key, $val2); |
| 3933 |
if (ref $val eq 'HASH') { |
| 3934 |
foreach $key (sort keys %$val) { |
| 3935 |
if ($key =~ /^(.*?):/ and not $$groupHash{$1} and $grp ne 'JSON') { |
| 3936 |
$$groupHash{$1} = $grp; |
| 3937 |
push @$groupList, $1; |
| 3938 |
} |
| 3939 |
AddGroups($$val{$key}, $grp, $groupHash, $groupList) if ref $$val{$key}; |
| 3940 |
} |
| 3941 |
} elsif (ref $val eq 'ARRAY') { |
| 3942 |
foreach $val2 (@$val) { |
| 3943 |
AddGroups($val2, $grp, $groupHash, $groupList) if ref $val2; |
| 3944 |
} |
| 3945 |
} |
| 3946 |
} |
| 3947 |
|
| 3948 |
#------------------------------------------------------------------------------ |
| 3949 |
# Convert binary data (SCALAR references) for printing |
| 3950 |
# Inputs: 0) object reference |
| 3951 |
# Returns: converted object, or undef if we don't want binary objects |
| 3952 |
sub ConvertBinary($) |
| 3953 |
{ |
| 3954 |
my $obj = shift; |
| 3955 |
my ($key, $val); |
| 3956 |
if (ref $obj eq 'HASH') { |
| 3957 |
foreach $key (keys %$obj) { |
| 3958 |
next unless ref $$obj{$key}; |
| 3959 |
$$obj{$key} = ConvertBinary($$obj{$key}); |
| 3960 |
return undef unless defined $$obj{$key}; |
| 3961 |
} |
| 3962 |
} elsif (ref $obj eq 'ARRAY') { |
| 3963 |
foreach $val (@$obj) { |
| 3964 |
next unless ref $val; |
| 3965 |
$val = ConvertBinary($val); |
| 3966 |
return undef unless defined $val; |
| 3967 |
} |
| 3968 |
} elsif (ref $obj eq 'SCALAR') { |
| 3969 |
return undef if $noBinary; |
| 3970 |
# (binaryOutput flag is set to 0 for binary mode of XML/PHP/JSON output formats) |
| 3971 |
if (defined $binaryOutput) { |
| 3972 |
$obj = $$obj; |
| 3973 |
# encode in base64 if necessary (0xf7 allows for up to 21-bit UTF-8 code space) |
| 3974 |
if ($json == 1 and ($obj =~ /[^\x09\x0a\x0d\x20-\x7e\x80-\xf7]/ or |
| 3975 |
Image::ExifTool::IsUTF8(\$obj) < 0)) |
| 3976 |
{ |
| 3977 |
$obj = 'base64:' . Image::ExifTool::XMP::EncodeBase64($obj, 1); |
| 3978 |
} |
| 3979 |
} else { |
| 3980 |
# (-b is not valid for HTML output) |
| 3981 |
my $bOpt = $html ? '' : ', use -b option to extract'; |
| 3982 |
if ($$obj =~ /^Binary data \d+ bytes$/) { |
| 3983 |
$obj = "($$obj$bOpt)"; |
| 3984 |
} else { |
| 3985 |
$obj = '(Binary data ' . length($$obj) . " bytes$bOpt)"; |
| 3986 |
} |
| 3987 |
} |
| 3988 |
} |
| 3989 |
return $obj; |
| 3990 |
} |
| 3991 |
|
| 3992 |
#------------------------------------------------------------------------------ |
| 3993 |
# Compare ValueConv and PrintConv values of a tag to see if they are equal |
| 3994 |
# Inputs: 0) value1, 1) value2, 2) flag to return true for any scalar references |
| 3995 |
# Returns: true if they are equal |
| 3996 |
sub IsEqual($$;$) |
| 3997 |
{ |
| 3998 |
my ($a, $b, $trueScalar) = @_; |
| 3999 |
# (scalar values are not print-converted) |
| 4000 |
return 1 if $a eq $b; |
| 4001 |
if (ref $a eq 'SCALAR') { |
| 4002 |
return 1 if $trueScalar; |
| 4003 |
return 1 if ref $b eq 'SCALAR' and $$a eq $$b; |
| 4004 |
return 0; |
| 4005 |
} |
| 4006 |
if (ref $a eq 'HASH' and ref $b eq 'HASH') { |
| 4007 |
return 0 if scalar(keys %$a) != scalar(keys %$b); |
| 4008 |
my $key; |
| 4009 |
foreach $key (keys %$a) { |
| 4010 |
return 0 unless IsEqual($$a{$key}, $$b{$key}, $trueScalar); |
| 4011 |
} |
| 4012 |
} else { |
| 4013 |
return 0 if ref $a ne 'ARRAY' or ref $b ne 'ARRAY' or @$a != @$b; |
| 4014 |
my $i; |
| 4015 |
for ($i=0; $i<scalar(@$a); ++$i) { |
| 4016 |
return 0 unless IsEqual($$a[$i], $$b[$i], $trueScalar); |
| 4017 |
} |
| 4018 |
} |
| 4019 |
return 1; |
| 4020 |
} |
| 4021 |
|
| 4022 |
#------------------------------------------------------------------------------ |
| 4023 |
# Get the printable rendition of a value |
| 4024 |
# Inputs: 0) value (may be a reference) |
| 4025 |
# Returns: de-referenced value |
| 4026 |
sub Printable($) |
| 4027 |
{ |
| 4028 |
my $val = shift; |
| 4029 |
if (ref $val) { |
| 4030 |
if ($structOpt) { |
| 4031 |
require Image::ExifTool::XMP; |
| 4032 |
$val = Image::ExifTool::XMP::SerializeStruct($mt, $val); |
| 4033 |
} elsif (ref $val eq 'ARRAY') { |
| 4034 |
$val = join($listSep, @$val); |
| 4035 |
} elsif (ref $val eq 'SCALAR') { |
| 4036 |
$val = '(Binary data '.length($$val).' bytes)'; |
| 4037 |
} |
| 4038 |
} |
| 4039 |
if ($escapeC) { |
| 4040 |
$val =~ s/([\0-\x1f\\\x7f])/$escC{$1} || sprintf('\x%.2x', ord $1)/eg; |
| 4041 |
} else { |
| 4042 |
# translate unprintable chars in value and remove trailing spaces |
| 4043 |
$val =~ tr/\x01-\x1f\x7f/./; |
| 4044 |
$val =~ s/\x00//g; |
| 4045 |
$val =~ s/\s+$//; |
| 4046 |
} |
| 4047 |
return $val; |
| 4048 |
} |
| 4049 |
|
| 4050 |
#------------------------------------------------------------------------------ |
| 4051 |
# Get character length of a UTF-8 string |
| 4052 |
# Inputs: 0) string |
| 4053 |
# Returns: number of characters (not bytes) in the UTF-8 string |
| 4054 |
sub LengthUTF8($) |
| 4055 |
{ |
| 4056 |
my $str = shift; |
| 4057 |
return length $str unless $fixLen; |
| 4058 |
local $SIG{'__WARN__'} = sub { }; |
| 4059 |
if (not $$mt{OPTIONS}{EncodeHangs} and eval { require Encode }) { |
| 4060 |
$str = Encode::decode_utf8($str); |
| 4061 |
} else { |
| 4062 |
$str = pack('U0C*', unpack 'C*', $str); |
| 4063 |
} |
| 4064 |
my $len; |
| 4065 |
if ($fixLen == 1) { |
| 4066 |
$len = length $str; |
| 4067 |
} else { |
| 4068 |
my $gcstr = eval { Unicode::GCString->new($str) }; |
| 4069 |
if ($gcstr) { |
| 4070 |
$len = $gcstr->columns; |
| 4071 |
} else { |
| 4072 |
$len = length $str; |
| 4073 |
delete $SIG{'__WARN__'}; |
| 4074 |
Warning($mt, 'Unicode::GCString problem. Columns may be misaligned'); |
| 4075 |
$fixLen = 1; |
| 4076 |
} |
| 4077 |
} |
| 4078 |
return $len; |
| 4079 |
} |
| 4080 |
|
| 4081 |
#------------------------------------------------------------------------------ |
| 4082 |
# Add tag list for copying tags from specified file |
| 4083 |
# Inputs: 0) set tags file name (or FMT), 1) options for SetNewValuesFromFile() |
| 4084 |
# Returns: nothing |
| 4085 |
# Notes: Uses global variables: %setTags, %setTagsList, @newValues, $saveCount |
| 4086 |
sub AddSetTagsFile($;$) |
| 4087 |
{ |
| 4088 |
my ($setFile, $opts) = @_; |
| 4089 |
if ($setTags{$setFile}) { |
| 4090 |
# move these tags aside and make a new list for the next invocation of this file |
| 4091 |
$setTagsList{$setFile} or $setTagsList{$setFile} = [ ]; |
| 4092 |
push @{$setTagsList{$setFile}}, $setTags{$setFile}; |
| 4093 |
} |
| 4094 |
$setTags{$setFile} = []; # create list for tags to copy from this file |
| 4095 |
# insert marker to save new values now (necessary even if this is not a dynamic |
| 4096 |
# file in case the same file is source'd multiple times in a single command) |
| 4097 |
push @newValues, { SaveCount => ++$saveCount }, "TagsFromFile=$setFile"; |
| 4098 |
# add option to protect the tags which are assigned after this |
| 4099 |
# (this is the mechanism by which the command-line order-of-operations is preserved) |
| 4100 |
$opts or $opts = { }; |
| 4101 |
$$opts{ProtectSaved} = $saveCount; |
| 4102 |
push @{$setTags{$setFile}}, $opts; |
| 4103 |
} |
| 4104 |
|
| 4105 |
#------------------------------------------------------------------------------ |
| 4106 |
# Get input file name or reference for calls to the ExifTool API |
| 4107 |
# Inputs: 0) file name ('-' for STDIN), 1) flag to buffer STDIN |
| 4108 |
# Returns: file name, or RAF reference for buffering STDIN |
| 4109 |
sub Infile($;$) |
| 4110 |
{ |
| 4111 |
my ($file, $bufferStdin) = @_; |
| 4112 |
if ($file eq '-' and ($bufferStdin or $rafStdin)) { |
| 4113 |
if ($rafStdin) { |
| 4114 |
$rafStdin->Seek(0); # rewind |
| 4115 |
} elsif (open RAF_STDIN, '-') { |
| 4116 |
$rafStdin = File::RandomAccess->new(\*RAF_STDIN); |
| 4117 |
$rafStdin->BinMode(); |
| 4118 |
} |
| 4119 |
return $rafStdin if $rafStdin; |
| 4120 |
} |
| 4121 |
return $file; |
| 4122 |
} |
| 4123 |
|
| 4124 |
#------------------------------------------------------------------------------ |
| 4125 |
# Issue warning to stderr, adding leading "Warning: " and trailing newline |
| 4126 |
# if the warning isn't suppressed by the API NoWarning option |
| 4127 |
# Inputs: 0) ExifTool ref, 1) warning string |
| 4128 |
sub Warning($$) |
| 4129 |
{ |
| 4130 |
my ($et, $str) = @_; |
| 4131 |
my $noWarn = $et->Options('NoWarning'); |
| 4132 |
if (not defined $noWarn or not eval { $str =~ /$noWarn/ }) { |
| 4133 |
Warn "Warning: $str\n"; |
| 4134 |
} |
| 4135 |
} |
| 4136 |
|
| 4137 |
#------------------------------------------------------------------------------ |
| 4138 |
# Set new values from file |
| 4139 |
# Inputs: 0) ExifTool ref, 1) filename, 2) reference to list of values to set |
| 4140 |
# Returns: 0 on error (and increments $countBadWr) |
| 4141 |
sub DoSetFromFile($$$) |
| 4142 |
{ |
| 4143 |
local $_; |
| 4144 |
my ($et, $file, $setTags) = @_; |
| 4145 |
$verbose and print $vout "Setting new values from $file\n"; |
| 4146 |
my $info = $et->SetNewValuesFromFile(Infile($file,1), @$setTags); |
| 4147 |
my $numSet = scalar(keys %$info); |
| 4148 |
if ($$info{Error}) { |
| 4149 |
# delete all error and warning tags |
| 4150 |
my @warns = grep /^(Error|Warning)\b/, keys %$info; |
| 4151 |
$numSet -= scalar(@warns); |
| 4152 |
# issue a warning only for the main error |
| 4153 |
my $err = $$info{Error}; |
| 4154 |
delete $$info{$_} foreach @warns; |
| 4155 |
my $noWarn = $et->Options('NoWarning'); |
| 4156 |
$$info{Warning} = $err unless defined $noWarn and eval { $err =~ /$noWarn/ }; |
| 4157 |
} elsif ($$info{Warning}) { |
| 4158 |
my $warns = 1; |
| 4159 |
++$warns while $$info{"Warning ($warns)"}; |
| 4160 |
$numSet -= $warns; |
| 4161 |
} |
| 4162 |
PrintErrors($et, $info, $file) and EFile($file), ++$countBadWr, return 0; |
| 4163 |
Warning($et,"No writable tags set from $file") unless $numSet; |
| 4164 |
return 1; |
| 4165 |
} |
| 4166 |
|
| 4167 |
#------------------------------------------------------------------------------ |
| 4168 |
# Translate backslashes to forward slashes in filename if necessary |
| 4169 |
# Inputs: 0) Filename |
| 4170 |
# Returns: nothing, but changes filename if necessary |
| 4171 |
sub CleanFilename($) |
| 4172 |
{ |
| 4173 |
$_[0] =~ tr/\\/\// if Image::ExifTool::IsPC(); |
| 4174 |
} |
| 4175 |
|
| 4176 |
#------------------------------------------------------------------------------ |
| 4177 |
# Does path name contain wildcards |
| 4178 |
# Inputs: 0) path name |
| 4179 |
# Returns: true if path contains wildcards |
| 4180 |
sub HasWildcards($) |
| 4181 |
{ |
| 4182 |
my $path = shift; |
| 4183 |
|
| 4184 |
# if this is a Windows path with the long path prefix, then wildcards are not supported |
| 4185 |
return 0 if $^O eq 'MSWin32' and $path =~ m{^[\\/]{2}\?[\\/]}; |
| 4186 |
return $path =~ /[*?]/; |
| 4187 |
} |
| 4188 |
|
| 4189 |
#------------------------------------------------------------------------------ |
| 4190 |
# Check for valid UTF-8 of a file name |
| 4191 |
# Inputs: 0) string, 1) original encoding |
| 4192 |
# Returns: 0=plain ASCII, 1=valid UTF-8, -1=invalid UTF-8 (and print warning) |
| 4193 |
sub CheckUTF8($$) |
| 4194 |
{ |
| 4195 |
my ($file, $enc) = @_; |
| 4196 |
my $isUTF8 = 0; |
| 4197 |
if ($file =~ /[\x80-\xff]/) { |
| 4198 |
$isUTF8 = Image::ExifTool::IsUTF8(\$file); |
| 4199 |
if ($isUTF8 < 0) { |
| 4200 |
if ($enc) { |
| 4201 |
Warn("Invalid filename encoding for $file\n"); |
| 4202 |
} elsif (not defined $enc) { |
| 4203 |
WarnOnce(qq{FileName encoding not specified. Use "-charset FileName=CHARSET"\n}); |
| 4204 |
} |
| 4205 |
} |
| 4206 |
} |
| 4207 |
return $isUTF8; |
| 4208 |
} |
| 4209 |
|
| 4210 |
#------------------------------------------------------------------------------ |
| 4211 |
# Set window title |
| 4212 |
# Inputs: title string or '' to reset title |
| 4213 |
sub SetWindowTitle($) |
| 4214 |
{ |
| 4215 |
my $title = shift; |
| 4216 |
if ($curTitle ne $title) { |
| 4217 |
$curTitle = $title; |
| 4218 |
if ($^O eq 'MSWin32') { |
| 4219 |
$title =~ tr(-_a-zA-Z0-9%.+/:=?*@~ )()dc; # allow only safe characters |
| 4220 |
$title =~ s/([\/?:%])/^$1/g; # escape remaing questionable chars |
| 4221 |
eval { system qq{title $title} }; |
| 4222 |
} else { |
| 4223 |
# (this only works for XTerm terminals, and STDERR must go to the console) |
| 4224 |
printf STDERR "\033]0;%s\007", $title; |
| 4225 |
} |
| 4226 |
} |
| 4227 |
} |
| 4228 |
|
| 4229 |
#------------------------------------------------------------------------------ |
| 4230 |
# Process files in our @files list |
| 4231 |
# Inputs: 0) ExifTool ref, 1) list ref to just return full file names |
| 4232 |
sub ProcessFiles($;$) |
| 4233 |
{ |
| 4234 |
my ($et, $list) = @_; |
| 4235 |
my $enc = $et->Options('CharsetFileName'); |
| 4236 |
my $file; |
| 4237 |
foreach $file (@files) { |
| 4238 |
$et->Options(CharsetFileName => 'UTF8') if $utf8FileName{$file}; |
| 4239 |
if (defined $progressMax) { |
| 4240 |
unless (defined $progressNext) { |
| 4241 |
$progressNext = $progressCount + $progressIncr; |
| 4242 |
$progressNext -= $progressNext % $progressIncr; # (show even multiples) |
| 4243 |
$progressNext = $progressMax if $progressNext > $progressMax; |
| 4244 |
} |
| 4245 |
++$progressCount; |
| 4246 |
if ($progress) { |
| 4247 |
if ($progressCount >= $progressNext) { |
| 4248 |
$progStr = " [$progressCount/$progressMax]"; |
| 4249 |
} else { |
| 4250 |
undef $progStr; # don't update progress yet |
| 4251 |
} |
| 4252 |
} |
| 4253 |
} |
| 4254 |
if ($et->IsDirectory($file) and not $listDir) { |
| 4255 |
$multiFile = $validFile = 1; |
| 4256 |
ScanDir($et, $file, $list); |
| 4257 |
} elsif ($filterFlag and not AcceptFile($file)) { |
| 4258 |
if ($et->Exists($file)) { |
| 4259 |
$filtered = 1; |
| 4260 |
Progress($vout, "-------- $file (wrong extension)") if $verbose; |
| 4261 |
} else { |
| 4262 |
Error "Error: File not found - $file\n"; |
| 4263 |
FileNotFound($file); |
| 4264 |
} |
| 4265 |
} else { |
| 4266 |
$validFile = 1; |
| 4267 |
if ($list) { |
| 4268 |
push(@$list, $file); |
| 4269 |
} else { |
| 4270 |
if (%endDir) { |
| 4271 |
my ($d, $f) = Image::ExifTool::SplitFileName($file); |
| 4272 |
next if $endDir{$d}; |
| 4273 |
} |
| 4274 |
GetImageInfo($et, $file); |
| 4275 |
Image::ExifTool::Purge($purge) if $purge; |
| 4276 |
$end and Warn("End called - $file\n"); |
| 4277 |
if ($endDir) { |
| 4278 |
Warn("EndDir called - $file\n"); |
| 4279 |
my ($d, $f) = Image::ExifTool::SplitFileName($file); |
| 4280 |
$endDir{$d} = 1; |
| 4281 |
undef $endDir; |
| 4282 |
} |
| 4283 |
} |
| 4284 |
} |
| 4285 |
$et->Options(CharsetFileName => $enc) if $utf8FileName{$file}; |
| 4286 |
last if $end; |
| 4287 |
} |
| 4288 |
} |
| 4289 |
|
| 4290 |
#------------------------------------------------------------------------------ |
| 4291 |
# Scan directory for image files |
| 4292 |
# Inputs: 0) ExifTool ref, 1) directory name, 2) list ref to return file names |
| 4293 |
sub ScanDir($$;$) |
| 4294 |
{ |
| 4295 |
local $_; |
| 4296 |
my ($et, $dir, $list) = @_; |
| 4297 |
my (@fileList, $done, $file, $utf8Name, $winSurrogate, $endThisDir); |
| 4298 |
my $enc = $et->Options('CharsetFileName'); |
| 4299 |
# recode as UTF-8 if necessary |
| 4300 |
if ($enc) { |
| 4301 |
unless ($enc eq 'UTF8') { |
| 4302 |
$dir = $et->Decode($dir, $enc, undef, 'UTF8'); |
| 4303 |
$et->Options(CharsetFileName => 'UTF8'); # now using UTF8 |
| 4304 |
} |
| 4305 |
$utf8Name = 1; |
| 4306 |
} |
| 4307 |
return if $ignore{$dir}; |
| 4308 |
# use Win32::FindFile on Windows if available |
| 4309 |
# (ReadDir will croak if there is a wildcard, so check for this) |
| 4310 |
if ($^O eq 'MSWin32' and not HasWildcards($dir)) { |
| 4311 |
undef $evalWarning; |
| 4312 |
local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] };; |
| 4313 |
if (CheckUTF8($dir, $enc) >= 0) { |
| 4314 |
if (eval { require Win32::FindFile }) { |
| 4315 |
eval { |
| 4316 |
@fileList = Win32::FindFile::ReadDir($dir); |
| 4317 |
$_ = $_->cFileName foreach @fileList; |
| 4318 |
}; |
| 4319 |
$@ and $evalWarning = $@; |
| 4320 |
if ($evalWarning) { |
| 4321 |
chomp $evalWarning; |
| 4322 |
$evalWarning =~ s/ at .*//s; |
| 4323 |
Warning($et,"[Win32::FindFile] $evalWarning - $dir"); |
| 4324 |
$winSurrogate = 1 if $evalWarning =~ /surrogate/; |
| 4325 |
} else { |
| 4326 |
$et->Options(CharsetFileName => 'UTF8'); # now using UTF8 |
| 4327 |
$utf8Name = 1; # ReadDir returns UTF-8 file names |
| 4328 |
$done = 1; |
| 4329 |
} |
| 4330 |
} else { |
| 4331 |
$done = 0; |
| 4332 |
} |
| 4333 |
} |
| 4334 |
} |
| 4335 |
unless ($done) { |
| 4336 |
# use standard perl library routines to read directory |
| 4337 |
unless (opendir(DIR_HANDLE, $dir)) { |
| 4338 |
Warn("Error opening directory $dir\n"); |
| 4339 |
return; |
| 4340 |
} |
| 4341 |
@fileList = readdir(DIR_HANDLE); |
| 4342 |
closedir(DIR_HANDLE); |
| 4343 |
if (defined $done) { |
| 4344 |
# issue warning if some names would have required Win32::FindFile |
| 4345 |
foreach $file ($dir, @fileList) { |
| 4346 |
next unless $file =~ /[\?\x80-\xff]/; |
| 4347 |
WarnOnce("Install Win32::FindFile to support Windows Unicode file names in directories\n"); |
| 4348 |
last; |
| 4349 |
} |
| 4350 |
} |
| 4351 |
} |
| 4352 |
$dir =~ /\/$/ or $dir .= '/'; # make sure directory name ends with '/' |
| 4353 |
foreach $file (@fileList) { |
| 4354 |
next if $file eq '.' or $file eq '..'; |
| 4355 |
my $path = "$dir$file"; |
| 4356 |
if ($et->IsDirectory($path)) { |
| 4357 |
next unless $recurse; |
| 4358 |
# ignore directories starting with "." by default |
| 4359 |
next if $file =~ /^\./ and $recurse == 1; |
| 4360 |
# note: this doesn't work in Windows cmd (see forum17243) |
| 4361 |
next if $ignore{$file} or ($ignore{SYMLINKS} and -l $path); |
| 4362 |
ScanDir($et, $path, $list); |
| 4363 |
last if $end; |
| 4364 |
next; |
| 4365 |
} |
| 4366 |
next if $endThisDir; |
| 4367 |
next if $ignoreHidden and $file =~ /^\./; # ignore hidden files if specified |
| 4368 |
# apply rules from -ext options |
| 4369 |
my $accepted; |
| 4370 |
if ($filterFlag) { |
| 4371 |
$accepted = AcceptFile($file) or next; |
| 4372 |
# must be specifically accepted to bypass selection logic |
| 4373 |
$accepted &= 0x01; |
| 4374 |
} |
| 4375 |
unless ($accepted) { |
| 4376 |
# read/write this file if it is a supported type |
| 4377 |
if ($scanWritable) { |
| 4378 |
if ($scanWritable eq '1') { |
| 4379 |
next unless CanWrite($file); |
| 4380 |
} else { |
| 4381 |
my $type = GetFileType($file); |
| 4382 |
next unless defined $type and $type eq $scanWritable; |
| 4383 |
} |
| 4384 |
} elsif (not GetFileType($file)) { |
| 4385 |
next unless $doUnzip; |
| 4386 |
next unless $file =~ /\.(gz|bz2)$/i; |
| 4387 |
} |
| 4388 |
} |
| 4389 |
# Windows patch to avoid replacing filename containing Unicode surrogate with 8.3 name |
| 4390 |
if ($winSurrogate and $isWriting and |
| 4391 |
(not $overwriteOrig or $overwriteOrig != 2) and |
| 4392 |
not $doSetFileName and $file =~ /~/) # (8.3 name will contain a tilde) |
| 4393 |
{ |
| 4394 |
Warn("Not writing $path\n"); |
| 4395 |
WarnOnce("Use -overwrite_original_in_place to write files with Unicode surrogate characters\n"); |
| 4396 |
EFile($file); |
| 4397 |
++$countBad; |
| 4398 |
next; |
| 4399 |
} |
| 4400 |
$utf8FileName{$path} = 1 if $utf8Name; |
| 4401 |
if ($list) { |
| 4402 |
push(@$list, $path); |
| 4403 |
} else { |
| 4404 |
GetImageInfo($et, $path); |
| 4405 |
Image::ExifTool::Purge($purge) if $purge; |
| 4406 |
if ($end) { |
| 4407 |
Warn("End called - $file\n"); |
| 4408 |
last; |
| 4409 |
} |
| 4410 |
if ($endDir) { |
| 4411 |
$path =~ s(/$)(); |
| 4412 |
Warn("EndDir called - $path\n"); |
| 4413 |
$endDir{$path} = 1; |
| 4414 |
$endThisDir = 1; |
| 4415 |
undef $endDir; |
| 4416 |
} |
| 4417 |
} |
| 4418 |
} |
| 4419 |
++$countDir; |
| 4420 |
$et->Options(CharsetFileName => $enc); # restore original setting |
| 4421 |
} |
| 4422 |
|
| 4423 |
#------------------------------------------------------------------------------ |
| 4424 |
# Find files with wildcard expression on Windows |
| 4425 |
# Inputs: 0) ExifTool ref, 1) file name with wildcards |
| 4426 |
# Returns: list of matching file names |
| 4427 |
# Notes: |
| 4428 |
# 1) Win32::FindFile must already be loaded |
| 4429 |
# 2) Sets flag in %utf8FileName for each file found |
| 4430 |
sub FindFileWindows($$) |
| 4431 |
{ |
| 4432 |
my ($et, $wildfile) = @_; |
| 4433 |
|
| 4434 |
# recode file name as UTF-8 if necessary |
| 4435 |
my $enc = $et->Options('CharsetFileName'); |
| 4436 |
$wildfile = $et->Decode($wildfile, $enc, undef, 'UTF8') if $enc and $enc ne 'UTF8'; |
| 4437 |
CleanFilename($wildfile); # use forward slashes |
| 4438 |
my ($dir, $wildname) = ($wildfile =~ m{(.*[:/])(.*)}) ? ($1, $2) : ('', $wildfile); |
| 4439 |
if (HasWildcards($dir)) { |
| 4440 |
Warn "Wildcards don't work in the directory specification\n"; |
| 4441 |
return (); |
| 4442 |
} |
| 4443 |
CheckUTF8($wildfile, $enc) >= 0 or return (); |
| 4444 |
undef $evalWarning; |
| 4445 |
local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; |
| 4446 |
my @files; |
| 4447 |
eval { |
| 4448 |
my @names = Win32::FindFile::FindFile($wildfile) or return; |
| 4449 |
# (apparently this isn't always sorted, so do a case-insensitive sort here) |
| 4450 |
@names = sort { uc($a) cmp uc($b) } @names; |
| 4451 |
my ($rname, $nm); |
| 4452 |
# replace "\?" with ".", and "\*" with ".*" for regular expression |
| 4453 |
($rname = quotemeta $wildname) =~ s/\\\?/./g; |
| 4454 |
$rname =~ s/\\\*/.*/g; |
| 4455 |
foreach $nm (@names) { |
| 4456 |
$nm = $nm->cFileName; |
| 4457 |
# make sure that FindFile behaves |
| 4458 |
# (otherwise "*.jpg" matches things like "a.jpg_original"!) |
| 4459 |
next unless $nm =~ /^$rname$/i; |
| 4460 |
next if $nm eq '.' or $nm eq '..'; # don't match "." and ".." |
| 4461 |
my $file = "$dir$nm"; # add back directory name |
| 4462 |
push @files, $file; |
| 4463 |
$utf8FileName{$file} = 1; # flag this file name as UTF-8 encoded |
| 4464 |
} |
| 4465 |
}; |
| 4466 |
$@ and $evalWarning = $@; |
| 4467 |
if ($evalWarning) { |
| 4468 |
chomp $evalWarning; |
| 4469 |
$evalWarning =~ s/ at .*//s; |
| 4470 |
Warn "Error: [Win32::FindFile] $evalWarning - $wildfile\n"; |
| 4471 |
undef @files; |
| 4472 |
EFile($wildfile); |
| 4473 |
++$countBad; |
| 4474 |
} |
| 4475 |
return @files; |
| 4476 |
} |
| 4477 |
|
| 4478 |
#------------------------------------------------------------------------------ |
| 4479 |
# Handle missing file on the command line |
| 4480 |
# Inputs: 0) file name |
| 4481 |
sub FileNotFound($) |
| 4482 |
{ |
| 4483 |
my $file = shift; |
| 4484 |
if ($file =~ /^(DIR|FILE)$/) { |
| 4485 |
my $type = { DIR => 'directory', FILE => 'file' }->{$file}; |
| 4486 |
Warn qq{You were meant to enter any valid $type name, not "$file" literally.\n}; |
| 4487 |
} |
| 4488 |
} |
| 4489 |
|
| 4490 |
#------------------------------------------------------------------------------ |
| 4491 |
# Patch for OS X 10.6 to preserve file modify date |
| 4492 |
# (this probably isn't a 100% fix, but it may solve a majority of the cases) |
| 4493 |
sub PreserveTime() |
| 4494 |
{ |
| 4495 |
local $_; |
| 4496 |
$mt->SetFileTime($_, @{$preserveTime{$_}}) foreach keys %preserveTime; |
| 4497 |
undef %preserveTime; |
| 4498 |
} |
| 4499 |
|
| 4500 |
#------------------------------------------------------------------------------ |
| 4501 |
# Return absolute path for a file |
| 4502 |
# Inputs: 0) file name |
| 4503 |
# Returns: absolute path string, or undef if path could not be determined |
| 4504 |
# Note: Warnings should be suppressed when calling this routine |
| 4505 |
sub AbsPath($) |
| 4506 |
{ |
| 4507 |
my $file = shift; |
| 4508 |
my $path; |
| 4509 |
if (defined $file) { |
| 4510 |
return undef if $file eq '*'; # (CSV SourceFile may be '*' -- no absolute path for that) |
| 4511 |
if ($^O eq 'MSWin32' and $mt->Options('WindowsLongPath')) { |
| 4512 |
$path = $mt->WindowsLongPath($file); |
| 4513 |
} elsif (eval { require Cwd }) { |
| 4514 |
local $SIG{'__WARN__'} = sub { }; |
| 4515 |
$path = eval { Cwd::abs_path($file) }; |
| 4516 |
} |
| 4517 |
CleanFilename($path) if defined $path; # use forward slashes |
| 4518 |
} |
| 4519 |
return $path; |
| 4520 |
} |
| 4521 |
|
| 4522 |
#------------------------------------------------------------------------------ |
| 4523 |
# Convert file name to ExifTool Charset |
| 4524 |
# Inputs: 0) ExifTool ref, 1) file name in CharsetFileName |
| 4525 |
# Returns: file name in ExifTool Charset |
| 4526 |
sub MyConvertFileName($$) |
| 4527 |
{ |
| 4528 |
my ($et, $file) = @_; |
| 4529 |
my $enc = $et->Options('CharsetFileName'); |
| 4530 |
$et->Options(CharsetFileName => 'UTF8') if $utf8FileName{$file}; |
| 4531 |
my $convFile = $et->ConvertFileName($file); |
| 4532 |
$et->Options(CharsetFileName => $enc) if $utf8FileName{$file}; |
| 4533 |
return $convFile; |
| 4534 |
} |
| 4535 |
|
| 4536 |
#------------------------------------------------------------------------------ |
| 4537 |
# Add print format entry |
| 4538 |
# Inputs: 0) expression string |
| 4539 |
sub AddPrintFormat($) |
| 4540 |
{ |
| 4541 |
my $expr = shift; |
| 4542 |
my $type; |
| 4543 |
if ($expr =~ /^#/) { |
| 4544 |
$expr =~ s/^#\[(HEAD|SECT|IF|BODY|ENDS|TAIL)\]// or return; # ignore comments |
| 4545 |
$type = $1; |
| 4546 |
} else { |
| 4547 |
$type = 'BODY'; |
| 4548 |
} |
| 4549 |
$printFmt{$type} or $printFmt{$type} = [ ]; |
| 4550 |
push @{$printFmt{$type}}, $expr; |
| 4551 |
# add to list of requested tags |
| 4552 |
push @requestTags, $expr =~ /\$\{?((?:[-_0-9A-Z]+:)*[-_0-9A-Z?*]+)/ig; |
| 4553 |
$printFmt{SetTags} = 1 if $expr =~ /\bSetTags\b/; |
| 4554 |
} |
| 4555 |
|
| 4556 |
#------------------------------------------------------------------------------ |
| 4557 |
# Get suggested file extension based on tag value for binary output |
| 4558 |
# Inputs: 0) ExifTool ref, 1) data ref, 2) tag name |
| 4559 |
# Returns: file extension (lower case), or 'dat' if unknown |
| 4560 |
sub SuggestedExtension($$$) |
| 4561 |
{ |
| 4562 |
my ($et, $valPt, $tag) = @_; |
| 4563 |
my $ext; |
| 4564 |
if (not $binaryOutput) { |
| 4565 |
$ext = 'txt'; |
| 4566 |
} elsif ($$valPt =~ /^\xff\xd8\xff/) { |
| 4567 |
$ext = 'jpg'; |
| 4568 |
} elsif ($$valPt =~ /^(\0\0\0\x0cjP( |\x1a\x1a)\x0d\x0a\x87\x0a|\xff\x4f\xff\x51\0)/) { |
| 4569 |
$ext = 'jp2'; |
| 4570 |
} elsif ($$valPt =~ /^(\x89P|\x8aM|\x8bJ)NG\r\n\x1a\n/) { |
| 4571 |
$ext = 'png'; |
| 4572 |
} elsif ($$valPt =~ /^GIF8[79]a/) { |
| 4573 |
$ext = 'gif'; |
| 4574 |
} elsif ($$valPt =~ /^<\?xpacket/ or $tag eq 'XMP') { |
| 4575 |
$ext = 'xmp'; |
| 4576 |
} elsif ($$valPt =~ /^<\?xml/ or $tag eq 'XML') { |
| 4577 |
$ext = 'xml'; |
| 4578 |
} elsif ($$valPt =~ /^RIFF....WAVE/s) { |
| 4579 |
$ext = 'wav'; |
| 4580 |
} elsif ($tag eq 'OriginalRawImage' and defined($ext = $et->GetValue('OriginalRawFileName'))) { |
| 4581 |
$ext =~ s/^.*\.//s; |
| 4582 |
$ext = $ext ? lc($ext) : 'raw'; |
| 4583 |
} elsif ($tag eq 'EXIF') { |
| 4584 |
$ext = 'exif'; |
| 4585 |
} elsif ($tag eq 'ICC_Profile') { |
| 4586 |
$ext = 'icc'; |
| 4587 |
} elsif ($$valPt =~ /^(MM\0\x2a|II\x2a\0)/) { |
| 4588 |
$ext = 'tiff'; |
| 4589 |
} elsif ($$valPt =~ /^.{4}ftyp(3gp|mp4|f4v|qt )/s) { |
| 4590 |
my %movType = ( 'qt ' => 'mov' ); |
| 4591 |
$ext = $movType{$1} || $1; |
| 4592 |
} elsif ($$valPt =~ /^<(!DOCTYPE )?html/i) { |
| 4593 |
$ext = 'html'; |
| 4594 |
} elsif ($$valPt =~ /^[\n\r]*\{[\n\r]*\\rtf/) { |
| 4595 |
$ext = 'rtf'; |
| 4596 |
} elsif ($$valPt !~ /^.{0,4096}\0/s) { |
| 4597 |
$ext = 'txt'; |
| 4598 |
} elsif ($$valPt =~ /^BM.{15}\0/s) { |
| 4599 |
$ext = 'bmp'; |
| 4600 |
} elsif ($$valPt =~ /^CANON OPTIONAL DATA\0/) { |
| 4601 |
$ext = 'vrd'; |
| 4602 |
} elsif ($$valPt =~ /^IIII\x04\0\x04\0/) { |
| 4603 |
$ext = 'dr4'; |
| 4604 |
} elsif ($$valPt =~ /^(.{10}|.{522})(\x11\x01|\x00\x11)/s) { |
| 4605 |
$ext = 'pict'; |
| 4606 |
} elsif ($$valPt =~ /^\xff\x0a|\0\0\0\x0cJXL \x0d\x0a......ftypjxl/s) { |
| 4607 |
$ext = 'jxl'; |
| 4608 |
} elsif ($$valPt =~ /^.{4}jumb\0.{3}jumdc2pa/s) { |
| 4609 |
$ext = 'c2pa'; |
| 4610 |
} elsif ($tag eq 'JUMBF') { |
| 4611 |
$ext = 'jumbf'; |
| 4612 |
} else { |
| 4613 |
$ext = 'dat'; |
| 4614 |
} |
| 4615 |
return $ext; |
| 4616 |
} |
| 4617 |
|
| 4618 |
#------------------------------------------------------------------------------ |
| 4619 |
# Load print format file |
| 4620 |
# Inputs: 0) file name, 1) flag to avoid adding newline to input argument |
| 4621 |
# - saves lines of file to %printFmt list |
| 4622 |
# - adds tag names to @tags list |
| 4623 |
sub LoadPrintFormat($;$) |
| 4624 |
{ |
| 4625 |
my ($arg, $noNL) = @_; |
| 4626 |
if (not defined $arg) { |
| 4627 |
Error "Must specify file or expression for -p option\n"; |
| 4628 |
} elsif ($arg !~ /\n/ and -f $arg and $mt->Open(\*FMT_FILE, $arg)) { |
| 4629 |
foreach (<FMT_FILE>) { |
| 4630 |
AddPrintFormat($_); |
| 4631 |
} |
| 4632 |
close(FMT_FILE); |
| 4633 |
} else { |
| 4634 |
$arg .= "\n" unless $noNL; |
| 4635 |
AddPrintFormat($arg); |
| 4636 |
} |
| 4637 |
} |
| 4638 |
|
| 4639 |
#------------------------------------------------------------------------------ |
| 4640 |
# A sort of sprintf for filenames |
| 4641 |
# Inputs: 0) format string (%d=dir, %f=file name, %e=ext), |
| 4642 |
# 1) source filename or undef to test format string |
| 4643 |
# 2-4) [%t %g %s %o only] tag name, ref to array of group names, |
| 4644 |
# suggested extension, original raw file name |
| 4645 |
# Returns: new filename or undef on error (or if no file and fmt contains token) |
| 4646 |
sub FilenameSPrintf($;$@) |
| 4647 |
{ |
| 4648 |
my ($fmt, $file, @extra) = @_; |
| 4649 |
local $_; |
| 4650 |
# return format string straight away if no tokens |
| 4651 |
return $fmt unless $fmt =~ /%[-+]?\d*[.:]?\d*[lu]?[dDfFeEtgso]/; |
| 4652 |
return undef unless defined $file; |
| 4653 |
CleanFilename($file); # make sure we are using forward slashes |
| 4654 |
# split filename into directory, file, extension |
| 4655 |
my %part; |
| 4656 |
@part{qw(d f E)} = ($file =~ /^(.*?)([^\/]*?)(\.[^.\/]*)?$/); |
| 4657 |
defined $part{f} or Warn("Error: Bad pattern match for file $file\n"), return undef; |
| 4658 |
if ($part{E}) { |
| 4659 |
$part{e} = substr($part{E}, 1); |
| 4660 |
} else { |
| 4661 |
@part{qw(e E)} = ('', ''); |
| 4662 |
} |
| 4663 |
$part{F} = $part{f} . $part{E}; |
| 4664 |
($part{D} = $part{d}) =~ s{/+$}{}; |
| 4665 |
@part{qw(t g s o)} = @extra; |
| 4666 |
my ($filename, $pos) = ('', 0); |
| 4667 |
while ($fmt =~ /(%([-+]?)(\d*)([.:]?)(\d*)([lu]?)([dDfFeEtgso]))/g) { |
| 4668 |
$filename .= substr($fmt, $pos, pos($fmt) - $pos - length($1)); |
| 4669 |
$pos = pos($fmt); |
| 4670 |
my ($sign, $wid, $dot, $skip, $mod, $code) = ($2, $3, $4, $5 || 0, $6, $7); |
| 4671 |
my (@path, $part, $len, $groups); |
| 4672 |
if (lc $code eq 'd' and $dot and $dot eq ':') { |
| 4673 |
# field width applies to directory levels instead of characters |
| 4674 |
@path = split '/', $part{$code}; |
| 4675 |
$len = scalar @path; |
| 4676 |
} else { |
| 4677 |
if ($code eq 'g') { |
| 4678 |
$groups = $part{g} || [ ] unless defined $groups; |
| 4679 |
$fmt =~ /\G(\d?)/g; # look for %g1, %g2, etc |
| 4680 |
$part{g} = $$groups[$1 || 0]; |
| 4681 |
$pos = pos($fmt); |
| 4682 |
} |
| 4683 |
$part{$code} = '' unless defined $part{$code}; |
| 4684 |
$len = length $part{$code}; |
| 4685 |
} |
| 4686 |
next unless $skip < $len; |
| 4687 |
$wid = $len - $skip if $wid eq '' or $wid + $skip > $len; |
| 4688 |
$skip = $len - $wid - $skip if $sign eq '-'; |
| 4689 |
if (@path) { |
| 4690 |
$part = join('/', @path[$skip..($skip+$wid-1)]); |
| 4691 |
$part .= '/' unless $code eq 'D'; |
| 4692 |
} else { |
| 4693 |
$part = substr($part{$code}, $skip, $wid); |
| 4694 |
} |
| 4695 |
$part = ($mod eq 'u') ? uc($part) : lc($part) if $mod; |
| 4696 |
$filename .= $part; |
| 4697 |
} |
| 4698 |
$filename .= substr($fmt, $pos); # add rest of file name |
| 4699 |
# remove double slashes (except at beginning to allow Windows UNC paths) |
| 4700 |
$filename =~ s{(?!^)//}{/}g; |
| 4701 |
return $filename; |
| 4702 |
} |
| 4703 |
|
| 4704 |
#------------------------------------------------------------------------------ |
| 4705 |
# Convert number to alphabetical index: a, b, c, ... z, aa, ab ... |
| 4706 |
# Inputs: 0) number |
| 4707 |
# Returns: alphabetical index string |
| 4708 |
sub Num2Alpha($) |
| 4709 |
{ |
| 4710 |
my $num = shift; |
| 4711 |
my $alpha = chr(97 + ($num % 26)); |
| 4712 |
while ($num >= 26) { |
| 4713 |
$num = int($num / 26) - 1; |
| 4714 |
$alpha = chr(97 + ($num % 26)) . $alpha; |
| 4715 |
} |
| 4716 |
return $alpha; |
| 4717 |
} |
| 4718 |
|
| 4719 |
#------------------------------------------------------------------------------ |
| 4720 |
# Expand '%c' and '%C' codes if filename to get next unused file name |
| 4721 |
# Inputs: 0) file name format string, 1) filename ok to use even if it exists |
| 4722 |
# Returns: new file name |
| 4723 |
sub NextUnusedFilename($;$) |
| 4724 |
{ |
| 4725 |
my ($fmt, $okfile) = @_; |
| 4726 |
return $fmt unless $fmt =~ /%[-+]?\d*[.:]?\d*[lun]?[cC]/; |
| 4727 |
my %sep = ( '-' => '-', '+' => '_' ); |
| 4728 |
my ($copy, $alpha) = (0, 'a'); |
| 4729 |
my $lastFile; |
| 4730 |
for (;;) { |
| 4731 |
my ($filename, $pos) = ('', 0); |
| 4732 |
while ($fmt =~ /(%([-+]?)(\d*)([.:]?)(\d*)([lun]?)([cC]))/g) { |
| 4733 |
$filename .= substr($fmt, $pos, pos($fmt) - $pos - length($1)); |
| 4734 |
$pos = pos($fmt); |
| 4735 |
my ($sign, $wid, $dec, $wid2, $mod, $tok) = ($2, $3 || 0, $4, $5 || 0, $6, $7); |
| 4736 |
my $seq; |
| 4737 |
if ($tok eq 'C') { |
| 4738 |
# increment sequence number for %C on collision if ':' is used |
| 4739 |
$sign eq '-' ? ++$seqFileDir : ++$seqFileNum if $copy and $dec eq ':'; |
| 4740 |
$seq = $wid + ($sign eq '-' ? $seqFileDir : $seqFileNum) - 1; |
| 4741 |
$wid = $wid2; |
| 4742 |
} else { |
| 4743 |
next unless $dec or $copy; |
| 4744 |
$wid = $wid2 if $wid < $wid2; |
| 4745 |
# add dash or underline separator if '-' or '+' specified |
| 4746 |
$filename .= $sep{$sign} if $sign; |
| 4747 |
} |
| 4748 |
if ($mod and $mod ne 'n') { |
| 4749 |
my $a = $tok eq 'C' ? Num2Alpha($seq) : $alpha; |
| 4750 |
my $str = ($wid and $wid > length $a) ? 'a' x ($wid - length($a)) : ''; |
| 4751 |
$str .= $a; |
| 4752 |
$str = uc $str if $mod eq 'u'; |
| 4753 |
$filename .= $str; |
| 4754 |
} else { |
| 4755 |
my $c = $tok eq 'C' ? $seq : $copy; |
| 4756 |
my $num = $c + ($mod ? 1 : 0); |
| 4757 |
$filename .= $wid ? sprintf("%.${wid}d",$num) : $num; |
| 4758 |
} |
| 4759 |
} |
| 4760 |
$filename .= substr($fmt, $pos); # add rest of file name |
| 4761 |
# return now with filename unless file exists |
| 4762 |
return $filename unless ($mt->Exists($filename, 1) and not defined $usedFileName{$filename}) or $usedFileName{$filename}; |
| 4763 |
if (defined $okfile) { |
| 4764 |
return $filename if $filename eq $okfile; |
| 4765 |
my ($fn, $ok) = (AbsPath($filename), AbsPath($okfile)); |
| 4766 |
return $okfile if defined $fn and defined $ok and $fn eq $ok; |
| 4767 |
} |
| 4768 |
return $filename if defined $lastFile and $lastFile eq $filename; |
| 4769 |
$lastFile = $filename; |
| 4770 |
++$copy; |
| 4771 |
++$alpha; |
| 4772 |
} |
| 4773 |
} |
| 4774 |
|
| 4775 |
#------------------------------------------------------------------------------ |
| 4776 |
# Create directory for specified file |
| 4777 |
# Inputs: 0) complete file name including path |
| 4778 |
# Returns: true if a directory was created |
| 4779 |
sub CreateDirectory($) |
| 4780 |
{ |
| 4781 |
my $file = shift; |
| 4782 |
my $err = $mt->CreateDirectory($file); |
| 4783 |
if (defined $err) { |
| 4784 |
$err and Error("$err\n"), return 0; |
| 4785 |
if ($verbose) { |
| 4786 |
my $dir; |
| 4787 |
($dir = $file) =~ s(/[^/]*$)(); |
| 4788 |
print $vout "Created directory $dir\n"; |
| 4789 |
} |
| 4790 |
++$countNewDir; |
| 4791 |
return 1; |
| 4792 |
} |
| 4793 |
return 0; |
| 4794 |
} |
| 4795 |
|
| 4796 |
#------------------------------------------------------------------------------ |
| 4797 |
# Open output text file |
| 4798 |
# Inputs: 0) file name format string, 1-N) extra arguments for FilenameSPrintf |
| 4799 |
# Returns: 0) file reference (or undef on error), 1) file name if opened, 2) append flag |
| 4800 |
# Notes: returns reference to STDOUT and no file name if no textOut file needed |
| 4801 |
sub OpenOutputFile($;@) |
| 4802 |
{ |
| 4803 |
my ($file, @args) = @_; |
| 4804 |
my ($fp, $outfile, $append); |
| 4805 |
if ($textOut) { |
| 4806 |
$outfile = $file; |
| 4807 |
CleanFilename($outfile); |
| 4808 |
if ($textOut =~ /%[-+]?\d*[.:]?\d*[lun]?[dDfFeEtgsocC]/ or defined $tagOut) { |
| 4809 |
# make filename from printf-like $textOut |
| 4810 |
$outfile = FilenameSPrintf($textOut, $file, @args); |
| 4811 |
return () unless defined $outfile; |
| 4812 |
$outfile = NextUnusedFilename($outfile); |
| 4813 |
CreateDirectory($outfile); # create directory if necessary |
| 4814 |
} else { |
| 4815 |
$outfile =~ s/\.[^.\/]*$//; # remove extension if it exists |
| 4816 |
$outfile .= $textOut; |
| 4817 |
} |
| 4818 |
my $mode = '>'; |
| 4819 |
if ($mt->Exists($outfile, 1)) { |
| 4820 |
unless ($textOverwrite) { |
| 4821 |
Warn "Output file $outfile already exists for $file\n"; |
| 4822 |
return (); |
| 4823 |
} |
| 4824 |
if ($textOverwrite == 2 or ($textOverwrite == 3 and $created{$outfile})) { |
| 4825 |
$mode = '>>'; |
| 4826 |
$append = 1; |
| 4827 |
} |
| 4828 |
} |
| 4829 |
unless ($mt->Open(\*OUTFILE, $outfile, $mode)) { |
| 4830 |
my $what = $mode eq '>' ? 'creating' : 'appending to'; |
| 4831 |
Error("Error $what $outfile\n"); |
| 4832 |
return (); |
| 4833 |
} |
| 4834 |
binmode(OUTFILE) if $binaryOutput; |
| 4835 |
$fp = \*OUTFILE; |
| 4836 |
} else { |
| 4837 |
$fp = \*STDOUT; |
| 4838 |
} |
| 4839 |
return($fp, $outfile, $append); |
| 4840 |
} |
| 4841 |
|
| 4842 |
#------------------------------------------------------------------------------ |
| 4843 |
# Filter files based on extension |
| 4844 |
# Inputs: 0) file name |
| 4845 |
# Returns: 0 = rejected, 1 = specifically accepted, 2 = accepted by default |
| 4846 |
# Notes: This routine should only be called if $filterFlag is set |
| 4847 |
sub AcceptFile($) |
| 4848 |
{ |
| 4849 |
my $file = shift; |
| 4850 |
my $ext = ($file =~ /^.*\.(.+)$/s) ? uc($1) : ''; |
| 4851 |
return $filterExt{$ext} if defined $filterExt{$ext}; |
| 4852 |
return $filterExt{'*'} if defined $filterExt{'*'}; |
| 4853 |
return 0 if $filterFlag & 0x02; # reject if accepting specific extensions |
| 4854 |
return 2; # accept by default |
| 4855 |
} |
| 4856 |
|
| 4857 |
#------------------------------------------------------------------------------ |
| 4858 |
# Slurp file into buffer |
| 4859 |
# Inputs: 0) file name, 1) buffer reference |
| 4860 |
# Returns: 1 on success |
| 4861 |
sub SlurpFile($$) |
| 4862 |
{ |
| 4863 |
my ($file, $buffPt) = @_; |
| 4864 |
$mt->Open(\*INFILE, $file) or Warn("Error opening file $file\n"), return 0; |
| 4865 |
binmode(INFILE); |
| 4866 |
# (CAREFUL!: must clear buffer first to reset possible utf8 flag because the data |
| 4867 |
# would be corrupted if it was read into a buffer which had the utf8 flag set!) |
| 4868 |
undef $$buffPt; |
| 4869 |
my $bsize = 1024 * 1024; |
| 4870 |
my $num = read(INFILE, $$buffPt, $bsize); |
| 4871 |
unless (defined $num) { |
| 4872 |
close(INFILE); |
| 4873 |
Warn("Error reading $file\n"); |
| 4874 |
return 0; |
| 4875 |
} |
| 4876 |
my $bmax = 64 * $bsize; |
| 4877 |
while ($num == $bsize) { |
| 4878 |
$bsize *= 2 if $bsize < $bmax; |
| 4879 |
my $buff; |
| 4880 |
$num = read(INFILE, $buff, $bsize); |
| 4881 |
last unless $num; |
| 4882 |
$$buffPt .= $buff; |
| 4883 |
} |
| 4884 |
close(INFILE); |
| 4885 |
return 1; |
| 4886 |
} |
| 4887 |
|
| 4888 |
|
| 4889 |
#------------------------------------------------------------------------------ |
| 4890 |
# Filter argfile line |
| 4891 |
# Inputs: 0) line of argfile |
| 4892 |
# Returns: filtered line or undef to ignore |
| 4893 |
sub FilterArgfileLine($) |
| 4894 |
{ |
| 4895 |
my $arg = shift; |
| 4896 |
if ($arg =~ /^#/) { # comment lines begin with '#' |
| 4897 |
return undef unless $arg =~ s/^#\[CSTR\]//; |
| 4898 |
$arg =~ s/[\x0d\x0a]+$//s; # remove trailing newline |
| 4899 |
# escape double quotes, dollar signs and ampersands if they aren't already |
| 4900 |
# escaped by an odd number of backslashes, and escape a single backslash |
| 4901 |
# if it occurs at the end of the string |
| 4902 |
$arg =~ s{\\(.)|(["\$\@]|\\$)}{'\\'.($2 || $1)}sge; |
| 4903 |
# un-escape characters in C string |
| 4904 |
my %esc = ( a => "\a", b => "\b", f => "\f", n => "\n", |
| 4905 |
r => "\r", t => "\t", '"' => '"', '\\' => '\\' ); |
| 4906 |
$arg =~ s/\\(.)/$esc{$1}||'\\'.$1/egs; |
| 4907 |
} else { |
| 4908 |
$arg =~ s/^\s+//; # remove leading white space |
| 4909 |
$arg =~ s/[\x0d\x0a]+$//s; # remove trailing newline |
| 4910 |
# remove white space before, and single space after '=', '+=', '-=' or '<=' |
| 4911 |
$arg =~ s/^(-[-_0-9A-Z:]+#?)\s*([-+<]?=) ?/$1$2/i; |
| 4912 |
return undef if $arg eq ''; |
| 4913 |
} |
| 4914 |
return $arg; |
| 4915 |
} |
| 4916 |
|
| 4917 |
#------------------------------------------------------------------------------ |
| 4918 |
# Read arguments from -stay_open argfile |
| 4919 |
# Inputs: 0) argument list ref |
| 4920 |
# Notes: blocks until -execute, -stay_open or -@ option is available |
| 4921 |
# (or until there was an error reading from the file) |
| 4922 |
sub ReadStayOpen($) |
| 4923 |
{ |
| 4924 |
my $args = shift; |
| 4925 |
my (@newArgs, $processArgs, $result, $optArgs); |
| 4926 |
my $lastOpt = ''; |
| 4927 |
my $unparsed = length $stayOpenBuff; |
| 4928 |
for (;;) { |
| 4929 |
if ($unparsed) { |
| 4930 |
# parse data already read from argfile |
| 4931 |
$result = $unparsed; |
| 4932 |
undef $unparsed; |
| 4933 |
} else { |
| 4934 |
# read more data from argfile |
| 4935 |
# - this read may block (which is good) if reading from a pipe |
| 4936 |
$result = sysread(STAYOPEN, $stayOpenBuff, 65536, length($stayOpenBuff)); |
| 4937 |
} |
| 4938 |
if ($result) { |
| 4939 |
my $pos = 0; |
| 4940 |
while ($stayOpenBuff =~ /\n/g) { |
| 4941 |
my $len = pos($stayOpenBuff) - $pos; |
| 4942 |
my $arg = substr($stayOpenBuff, $pos, $len); |
| 4943 |
$pos += $len; |
| 4944 |
$arg = FilterArgfileLine($arg); |
| 4945 |
next unless defined $arg; |
| 4946 |
push @newArgs, $arg; |
| 4947 |
if ($optArgs) { |
| 4948 |
# this is an argument for the last option |
| 4949 |
undef $optArgs; |
| 4950 |
next unless $lastOpt eq '-stay_open' or $lastOpt eq '-@'; |
| 4951 |
} else { |
| 4952 |
$lastOpt = lc $arg; |
| 4953 |
$optArgs = $optArgs{$arg}; |
| 4954 |
unless (defined $optArgs) { |
| 4955 |
$optArgs = $optArgs{$lastOpt}; |
| 4956 |
# handle options with trailing numbers |
| 4957 |
$optArgs = $optArgs{"$1#$2"} if not defined $optArgs and $lastOpt =~ /^(.*?)\d+(!?)$/; |
| 4958 |
} |
| 4959 |
next unless $lastOpt =~ /^-execute\d*$/; |
| 4960 |
} |
| 4961 |
$processArgs = 1; |
| 4962 |
last; # process arguments up to this point |
| 4963 |
} |
| 4964 |
next unless $pos; # nothing to do if we didn't read any arguments |
| 4965 |
# keep unprocessed data in buffer |
| 4966 |
$stayOpenBuff = substr($stayOpenBuff, $pos); |
| 4967 |
if ($processArgs) { |
| 4968 |
# process new arguments after -execute or -stay_open option |
| 4969 |
unshift @$args, @newArgs; |
| 4970 |
last; |
| 4971 |
} |
| 4972 |
} elsif ($result == 0) { |
| 4973 |
# sysread() didn't block (eg. when reading from a file), |
| 4974 |
# so wait for a short time (1/100 sec) then try again |
| 4975 |
# Note: may break out of this early if SIGCONT is received |
| 4976 |
select(undef,undef,undef,0.01); |
| 4977 |
} else { |
| 4978 |
Warn "Error reading from ARGFILE\n"; |
| 4979 |
close STAYOPEN; |
| 4980 |
$stayOpen = 0; |
| 4981 |
last; |
| 4982 |
} |
| 4983 |
} |
| 4984 |
} |
| 4985 |
|
| 4986 |
#------------------------------------------------------------------------------ |
| 4987 |
# Add new entry to -efile output file |
| 4988 |
# Inputs: 0) file name, 1) -efile option number (0=error, 1=same, 2=failed, 3=updated, 4=created) |
| 4989 |
sub EFile($$) |
| 4990 |
{ |
| 4991 |
my $entry = shift; |
| 4992 |
my $efile = $efile[shift || 0]; |
| 4993 |
if (defined $efile and length $entry and $entry ne '-') { |
| 4994 |
my $err; |
| 4995 |
CreateDirectory($efile); |
| 4996 |
if ($mt->Open(\*EFILE_FILE, $efile, '>>')) { |
| 4997 |
print EFILE_FILE $entry, "\n" or Warn("Error writing to $efile\n"), $err = 1; |
| 4998 |
close EFILE_FILE; |
| 4999 |
} else { |
| 5000 |
Warn("Error opening '${efile}' for append\n"); |
| 5001 |
$err = 1; |
| 5002 |
} |
| 5003 |
if ($err) { |
| 5004 |
defined $_ and $_ eq $efile and undef $_ foreach @efile; |
| 5005 |
} |
| 5006 |
} |
| 5007 |
} |
| 5008 |
|
| 5009 |
#------------------------------------------------------------------------------ |
| 5010 |
# Print progress message if it is time for it |
| 5011 |
# Inputs: 0) file ref, 1) message |
| 5012 |
sub Progress($$) |
| 5013 |
{ |
| 5014 |
my ($file, $msg) = @_; |
| 5015 |
if (defined $progStr) { |
| 5016 |
print $file $msg, $progStr, "\n"; |
| 5017 |
undef $progressNext if defined $progressMax; |
| 5018 |
} |
| 5019 |
} |
| 5020 |
|
| 5021 |
#------------------------------------------------------------------------------ |
| 5022 |
# Print list of tags |
| 5023 |
# Inputs: 0) message, 1-N) list of tag names |
| 5024 |
sub PrintTagList($@) |
| 5025 |
{ |
| 5026 |
my $msg = shift; |
| 5027 |
print $msg, ":\n" unless $quiet; |
| 5028 |
my $tag; |
| 5029 |
if (($outFormat < 0 or $verbose) and $msg =~ /file extensions$/ and @_) { |
| 5030 |
foreach $tag (@_) { |
| 5031 |
printf(" %-11s %s\n", $tag, GetFileType($tag, 1)); |
| 5032 |
} |
| 5033 |
return; |
| 5034 |
} |
| 5035 |
my ($len, $pad) = (0, $quiet ? '' : ' '); |
| 5036 |
foreach $tag (@_) { |
| 5037 |
my $taglen = length($tag); |
| 5038 |
if ($len + $taglen > 77) { |
| 5039 |
print "\n"; |
| 5040 |
($len, $pad) = (0, $quiet ? '' : ' '); |
| 5041 |
} |
| 5042 |
print $pad, $tag; |
| 5043 |
$len += $taglen + 1; |
| 5044 |
$pad = ' '; |
| 5045 |
} |
| 5046 |
@_ or print $pad, '[empty list]'; |
| 5047 |
print "\n"; |
| 5048 |
} |
| 5049 |
|
| 5050 |
#------------------------------------------------------------------------------ |
| 5051 |
# Print warnings and errors from info hash |
| 5052 |
# Inputs: 0) ExifTool object ref, 1) info hash, 2) file name |
| 5053 |
# Returns: true if there was an Error |
| 5054 |
sub PrintErrors($$$) |
| 5055 |
{ |
| 5056 |
my ($et, $info, $file) = @_; |
| 5057 |
my ($tag, $key); |
| 5058 |
foreach $tag (qw(Warning Error)) { |
| 5059 |
next unless $$info{$tag}; |
| 5060 |
my @keys = ( $tag ); |
| 5061 |
push @keys, sort(grep /^$tag /, keys %$info) if $et->Options('Duplicates'); |
| 5062 |
foreach $key (@keys) { |
| 5063 |
Warn "$tag: $info->{$key} - $file\n"; |
| 5064 |
} |
| 5065 |
} |
| 5066 |
return $$info{Error}; |
| 5067 |
} |
| 5068 |
|
| 5069 |
#===================================================================================== |
| 5070 |
# NOTE: Be sure to update windows_exiftool.txt with any changes to this documentation! |
| 5071 |
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv |
| 5072 |
|
| 5073 |
__END__ |
| 5074 |
|
| 5075 |
=head1 NAME |
| 5076 |
|
| 5077 |
exiftool - Read and write meta information in files |
| 5078 |
|
| 5079 |
=head1 SYNOPSIS |
| 5080 |
|
| 5081 |
=head2 Reading |
| 5082 |
|
| 5083 |
B<exiftool> [I<OPTIONS>] [-I<TAG>...] [--I<TAG>...] I<FILE>... |
| 5084 |
|
| 5085 |
=head2 Writing |
| 5086 |
|
| 5087 |
B<exiftool> [I<OPTIONS>] -I<TAG>[+-^E<lt>]=[I<VALUE>]... I<FILE>... |
| 5088 |
|
| 5089 |
=head2 Copying |
| 5090 |
|
| 5091 |
B<exiftool> [I<OPTIONS>] B<-tagsFromFile> I<SRCFILE> |
| 5092 |
[-[I<DSTTAG>E<lt>]I<SRCTAG>...] I<FILE>... |
| 5093 |
|
| 5094 |
=head2 Other |
| 5095 |
|
| 5096 |
B<exiftool> [ B<-ver> | |
| 5097 |
B<-list>[B<w>|B<f>|B<r>|B<wf>|B<g>[I<NUM>]|B<d>|B<x>|B<geo>] ] |
| 5098 |
|
| 5099 |
For specific examples, see the L<EXAMPLES|/READING EXAMPLES> sections below. |
| 5100 |
|
| 5101 |
This documentation is displayed if exiftool is run without an input I<FILE> |
| 5102 |
when one is expected. |
| 5103 |
|
| 5104 |
=head1 DESCRIPTION |
| 5105 |
|
| 5106 |
A command-line interface to L<Image::ExifTool|Image::ExifTool>, used for |
| 5107 |
reading and writing meta information in a variety of file types. I<FILE> is |
| 5108 |
one or more source file names, directory names, or C<-> for the standard |
| 5109 |
input. Metadata is read from source files and printed in readable form to |
| 5110 |
the console (or written to output text files with B<-w>). |
| 5111 |
|
| 5112 |
To write or delete metadata, tag values are assigned using |
| 5113 |
-I<TAG>=[I<VALUE>], and/or the B<-geotag>, B<-csv=> or B<-json=> options. |
| 5114 |
To copy or move metadata, the B<-tagsFromFile> feature is used. By default |
| 5115 |
the original files are preserved with C<_original> appended to their names |
| 5116 |
-- be sure to verify that the new files are OK before erasing the originals. |
| 5117 |
Once in write mode, exiftool will ignore any read-specific options. |
| 5118 |
|
| 5119 |
Note: If I<FILE> is a directory name then only supported file types in the |
| 5120 |
directory are processed (in write mode only writable types are processed). |
| 5121 |
However, files may be specified by name, or the B<-ext> option may be used |
| 5122 |
to force processing of files with any extension. Hidden files in the |
| 5123 |
directory are also processed. Adding the B<-r> option causes subdirectories |
| 5124 |
to be processed recursively, but subdirectories with names beginning with |
| 5125 |
"." are skipped unless B<-r.> is used. |
| 5126 |
|
| 5127 |
Below is a list of file types and meta information formats currently |
| 5128 |
supported by ExifTool (r = read, w = write, c = create): |
| 5129 |
|
| 5130 |
File Types |
| 5131 |
------------+-------------+-------------+-------------+------------ |
| 5132 |
360 r/w | DR4 r/w/c | JP2 r/w | ODS r | RW2 r/w |
| 5133 |
3FR r | DSF r | JPEG r/w | ODT r | RWL r/w |
| 5134 |
3G2 r/w | DSS r | JSON r | OFR r | RWZ r |
| 5135 |
3GP r/w | DV r | JXL r/w | OGG r | RM r |
| 5136 |
7Z r | DVB r/w | K25 r | OGV r | SEQ r |
| 5137 |
A r | DVR-MS r | KDC r | ONP r | SKETCH r |
| 5138 |
AA r | DYLIB r | KEY r | OPUS r | SO r |
| 5139 |
AAC r | EIP r | KVAR r | ORF r/w | SR2 r/w |
| 5140 |
AAE r | EPS r/w | LA r | ORI r/w | SRF r |
| 5141 |
AAX r/w | EPUB r | LFP r | OTF r | SRW r/w |
| 5142 |
ACR r | ERF r/w | LIF r | PAC r | SVG r |
| 5143 |
AFM r | EXE r | LNK r | PAGES r | SWF r |
| 5144 |
AI r/w | EXIF r/w/c | LRV r/w | PBM r/w | THM r/w |
| 5145 |
AIFF r | EXR r | M2TS r | PCAP r | TIFF r/w |
| 5146 |
APE r | EXV r/w/c | M4A/V r/w | PCAPNG r | TNEF r |
| 5147 |
ARQ r/w | F4A/V r/w | MACOS r | PCD r | TORRENT r |
| 5148 |
ARW r/w | FFF r/w | MAX r | PCX r | TTC r |
| 5149 |
ASF r | FITS r | MEF r/w | PDB r | TTF r |
| 5150 |
AVI r | FLA r | MIE r/w/c | PDF r/w | TXT r |
| 5151 |
AVIF r/w | FLAC r | MIFF r | PEF r/w | URL r |
| 5152 |
AZW r | FLIF r/w | MKA r | PFA r | VCF r |
| 5153 |
BMP r | FLV r | MKS r | PFB r | VNT r |
| 5154 |
BPG r | FPF r | MKV r | PFM r | VRD r/w/c |
| 5155 |
BTF r | FPX r | MNG r/w | PGF r | VSD r |
| 5156 |
C2PA r | GIF r/w | MOBI r | PGM r/w | VSDX r |
| 5157 |
CHM r | GLV r/w | MODD r | PLIST r | WAV r |
| 5158 |
COS r | GPR r/w | MOI r | PICT r | WDP r/w |
| 5159 |
CR2 r/w | GZ r | MOS r/w | PMP r | WEBP r/w |
| 5160 |
CR3 r/w | HDP r/w | MOV r/w | PNG r/w | WEBM r |
| 5161 |
CRM r/w | HDR r | MP3 r | PPM r/w | WMA r |
| 5162 |
CRW r/w | HEIC r/w | MP4 r/w | PPT r | WMV r |
| 5163 |
CS1 r/w | HEIF r/w | MPC r | PPTX r | WOFF r |
| 5164 |
CSV r | HTML r | MPG r | PS r/w | WOFF2 r |
| 5165 |
CUR r | ICC r/w/c | MPO r/w | PSB r/w | WPG r |
| 5166 |
CZI r | ICO r | MQV r/w | PSD r/w | WTV r |
| 5167 |
DCM r | ICS r | MRC r | PSP r | WV r |
| 5168 |
DCP r/w | IDML r | MRW r/w | QTIF r/w | X3F r/w |
| 5169 |
DCR r | IIQ r/w | MXF r | R3D r | XCF r |
| 5170 |
DFONT r | IND r/w | NEF r/w | RA r | XISF r |
| 5171 |
DIVX r | INSP r/w | NKA r | RAF r/w | XLS r |
| 5172 |
DJVU r | INSV r | NKSC r/w | RAM r | XLSX r |
| 5173 |
DLL r | INX r | NRW r/w | RAR r | XMP r/w/c |
| 5174 |
DNG r/w | ISO r | NUMBERS r | RAW r/w | ZIP r |
| 5175 |
DOC r | ITC r | NXD r | RIFF r | |
| 5176 |
DOCX r | J2C r | O r | RSRC r | |
| 5177 |
DPX r | JNG r/w | ODP r | RTF r | |
| 5178 |
|
| 5179 |
Meta Information |
| 5180 |
----------------------+----------------------+--------------------- |
| 5181 |
EXIF r/w/c | CIFF r/w | Ricoh RMETA r |
| 5182 |
GPS r/w/c | AFCP r/w | Picture Info r |
| 5183 |
IPTC r/w/c | Kodak Meta r/w | Adobe APP14 r |
| 5184 |
XMP r/w/c | FotoStation r/w | MPF r |
| 5185 |
MakerNotes r/w/c | PhotoMechanic r/w | Stim r |
| 5186 |
Photoshop IRB r/w/c | JPEG 2000 r | DPX r |
| 5187 |
ICC Profile r/w/c | DICOM r | APE r |
| 5188 |
MIE r/w/c | Flash r | Vorbis r |
| 5189 |
JFIF r/w/c | FlashPix r | SPIFF r |
| 5190 |
Ducky APP12 r/w/c | QuickTime r | DjVu r |
| 5191 |
PDF r/w/c | Matroska r | M2TS r |
| 5192 |
PNG r/w/c | MXF r | PE/COFF r |
| 5193 |
Canon VRD r/w/c | PrintIM r | AVCHD r |
| 5194 |
Nikon Capture r/w/c | FLAC r | ZIP r |
| 5195 |
GeoTIFF r/w/c | ID3 r | (and more) |
| 5196 |
|
| 5197 |
=head1 OPTIONS |
| 5198 |
|
| 5199 |
Case is not significant for any command-line option (including tag and group |
| 5200 |
names), except for single-character options when the corresponding |
| 5201 |
upper-case option exists. Many single-character options have equivalent |
| 5202 |
long-name versions (shown in brackets), and some options have inverses which |
| 5203 |
are invoked with a leading double-dash. Unrecognized options are |
| 5204 |
interpreted as tag names (for this reason, multiple single-character options |
| 5205 |
may NOT be combined into one argument). Contrary to standard practice, |
| 5206 |
options may appear after source file names on the exiftool command line. |
| 5207 |
|
| 5208 |
=head2 Option Overview |
| 5209 |
|
| 5210 |
L<Tag operations|/Tag operations> |
| 5211 |
|
| 5212 |
-TAG or --TAG Extract or exclude specified tag |
| 5213 |
-TAG[+-^]=[VALUE] Write new value for tag |
| 5214 |
-TAG[+-]<=DATFILE Write tag value from contents of file |
| 5215 |
-[+]TAG[+-]<SRCTAG Copy tag value (see -tagsFromFile) |
| 5216 |
|
| 5217 |
-tagsFromFile SRCFILE Copy tag values from file |
| 5218 |
-x TAG (-exclude) Exclude specified tag |
| 5219 |
|
| 5220 |
L<Input-output text formatting|/Input-output text formatting> |
| 5221 |
|
| 5222 |
-args (-argFormat) Format metadata as exiftool arguments |
| 5223 |
-b (-binary) Output metadata in binary format |
| 5224 |
-c FMT (-coordFormat) Set format for GPS coordinates |
| 5225 |
-charset [[TYPE=]CHARSET] Specify encoding for special characters |
| 5226 |
-csv[[+]=CSVFILE] Export/import tags in CSV format |
| 5227 |
-csvDelim STR Set delimiter for CSV file |
| 5228 |
-d FMT (-dateFormat) Set format for date/time values |
| 5229 |
-D (-decimal) Show tag ID numbers in decimal |
| 5230 |
-E,-ex,-ec (-escape(HTML|XML|C))Escape tag values for HTML, XML or C |
| 5231 |
-f (-forcePrint) Force printing of all specified tags |
| 5232 |
-g[NUM...] (-groupHeadings) Organize output by tag group |
| 5233 |
-G[NUM...] (-groupNames) Print group name for each tag |
| 5234 |
-h (-htmlFormat) Use HTML formatting for output |
| 5235 |
-H (-hex) Show tag ID numbers in hexadecimal |
| 5236 |
-htmlDump[OFFSET] Generate HTML-format binary dump |
| 5237 |
-j[[+]=JSONFILE] (-json) Export/import tags in JSON format |
| 5238 |
-l (-long) Use long 2-line output format |
| 5239 |
-L (-latin) Use Windows Latin1 encoding |
| 5240 |
-lang [LANG] Set current language |
| 5241 |
-listItem INDEX Extract specific item from a list |
| 5242 |
-n (--printConv) No print conversion |
| 5243 |
-p[-] STR (-printFormat) Print output in specified format |
| 5244 |
-php Export tags as a PHP Array |
| 5245 |
-plot Output tags as SVG plot file |
| 5246 |
-s[NUM] (-short) Short output format (-s for tag names) |
| 5247 |
-S (-veryShort) Very short output format |
| 5248 |
-sep STR (-separator) Set separator string for list items |
| 5249 |
-sort Sort output alphabetically |
| 5250 |
-struct Enable output of structured information |
| 5251 |
-t (-tab) Output in tab-delimited list format |
| 5252 |
-T (-table) Output in tabular format |
| 5253 |
-v[NUM] (-verbose) Print verbose messages |
| 5254 |
-w[+|!] EXT (-textOut) Write (or overwrite!) output text files |
| 5255 |
-W[+|!] FMT (-tagOut) Write output text file for each tag |
| 5256 |
-Wext EXT (-tagOutExt) Write only specified file types with -W |
| 5257 |
-X (-xmlFormat) Use RDF/XML output format |
| 5258 |
|
| 5259 |
L<Processing control|/Processing control> |
| 5260 |
|
| 5261 |
-a (-duplicates) Allow duplicate tags to be extracted |
| 5262 |
-e (--composite) Do not generate composite tags |
| 5263 |
-ee[NUM] (-extractEmbedded) Extract information from embedded files |
| 5264 |
-ext[+] EXT (-extension) Process files with specified extension |
| 5265 |
-F[OFFSET] (-fixBase) Fix the base for maker notes offsets |
| 5266 |
-fast[NUM] Increase speed when extracting metadata |
| 5267 |
-fileOrder[NUM] [-]TAG Set file processing order |
| 5268 |
-i DIR (-ignore) Ignore specified directory name |
| 5269 |
-if[NUM] EXPR Conditionally process files |
| 5270 |
-m (-ignoreMinorErrors) Ignore minor errors and warnings |
| 5271 |
-o OUTFILE (-out) Set output file or directory name |
| 5272 |
-overwrite_original Overwrite original by renaming tmp file |
| 5273 |
-overwrite_original_in_place Overwrite original by copying tmp file |
| 5274 |
-P (-preserve) Preserve file modification date/time |
| 5275 |
-password PASSWD Password for processing protected files |
| 5276 |
-progress[NUM][:[TITLE]] Show file progress count |
| 5277 |
-q (-quiet) Quiet processing |
| 5278 |
-r[.] (-recurse) Recursively process subdirectories |
| 5279 |
-scanForXMP Brute force XMP scan |
| 5280 |
-u (-unknown) Extract unknown tags |
| 5281 |
-U (-unknown2) Extract unknown binary tags too |
| 5282 |
-wm MODE (-writeMode) Set mode for writing/creating tags |
| 5283 |
-z (-zip) Read/write compressed information |
| 5284 |
|
| 5285 |
L<Other options|/Other options> |
| 5286 |
|
| 5287 |
-@ ARGFILE Read command-line arguments from file |
| 5288 |
-k (-pause) Pause before terminating |
| 5289 |
-list[w|f|r|wf|g[NUM]|d|x|geo] List various exiftool capabilities |
| 5290 |
-ver Print exiftool version number |
| 5291 |
-- End of options |
| 5292 |
|
| 5293 |
L<Special features|/Special features> |
| 5294 |
|
| 5295 |
-diff FILE2 Compare metadata with another file |
| 5296 |
-geotag TRKFILE Geotag images from specified GPS log |
| 5297 |
-globalTimeShift SHIFT Shift all formatted date/time values |
| 5298 |
-use MODULE Add features from plug-in module |
| 5299 |
|
| 5300 |
L<Utilities|/Utilities> |
| 5301 |
|
| 5302 |
-delete_original[!] Delete "_original" backups |
| 5303 |
-restore_original Restore from "_original" backups |
| 5304 |
|
| 5305 |
L<Advanced options|/Advanced options> |
| 5306 |
|
| 5307 |
-api [OPT[[^]=[VAL]]] Set ExifTool API option |
| 5308 |
-common_args Define common arguments |
| 5309 |
-config CFGFILE Specify configuration file name |
| 5310 |
-echo[NUM] TEXT Echo text to stdout or stderr |
| 5311 |
-efile[NUM][!] TXTFILE Save names of files with errors |
| 5312 |
-execute[NUM] Execute multiple commands on one line |
| 5313 |
-fileNUM ALTFILE Load tags from alternate file |
| 5314 |
-list_dir List directories, not their contents |
| 5315 |
-srcfile FMT Process a different source file |
| 5316 |
-stay_open FLAG Keep reading -@ argfile even after EOF |
| 5317 |
-userParam PARAM[[^]=[VAL]] Set user parameter (API UserParam opt) |
| 5318 |
|
| 5319 |
=head2 Option Details |
| 5320 |
|
| 5321 |
=head3 Tag operations |
| 5322 |
|
| 5323 |
=over 5 |
| 5324 |
|
| 5325 |
=item B<->I<TAG> |
| 5326 |
|
| 5327 |
Extract information for the specified tag (eg. C<-CreateDate>). Multiple |
| 5328 |
tags may be specified in a single command. A tag name is the handle by |
| 5329 |
which a piece of information is referenced. See |
| 5330 |
L<Image::ExifTool::TagNames|Image::ExifTool::TagNames> for documentation on |
| 5331 |
available tag names. A tag name may include leading group names separated |
| 5332 |
by colons (eg. C<-EXIF:CreateDate>, or C<-Doc1:XMP:Creator>), and each group |
| 5333 |
name may be prefixed by a digit to specify family number (eg. |
| 5334 |
C<-1IPTC:City>). (Note that the API SavePath and SaveFormat options must be |
| 5335 |
used for the family 5 and 6 groups respectively to be available.) Use the |
| 5336 |
B<-listg> option to list available group names by family. |
| 5337 |
|
| 5338 |
A special tag name of C<All> may be used to indicate all meta information |
| 5339 |
(ie. B<-All>). This is particularly useful when a group name is specified |
| 5340 |
to extract all information in a group (but beware that unless the B<-a> |
| 5341 |
option is also used, some tags in the group may be suppressed by same-named |
| 5342 |
tags in other groups). The wildcard characters C<?> and C<*> may be used in |
| 5343 |
a tag name to match any single character and zero or more characters |
| 5344 |
respectively. These may not be used in a group name, with the exception |
| 5345 |
that a group name of C<*> (or C<All>) may be used to extract all instances |
| 5346 |
of a tag (as if B<-a> was used). Note that arguments containing wildcards |
| 5347 |
must be quoted on the command line of most systems to prevent shell |
| 5348 |
globbing. |
| 5349 |
|
| 5350 |
A C<#> may be appended to the tag name to disable the print conversion on a |
| 5351 |
per-tag basis (see the B<-n> option). This may also be used when writing or |
| 5352 |
copying tags. |
| 5353 |
|
| 5354 |
If no tags are specified, all available information is extracted (as if |
| 5355 |
C<-All> had been specified). |
| 5356 |
|
| 5357 |
Note: Descriptions, not tag names, are shown by default when extracting |
| 5358 |
information. Use the B<-s> option to see the tag names instead. |
| 5359 |
|
| 5360 |
=item B<-->I<TAG> |
| 5361 |
|
| 5362 |
Exclude specified tag from extracted information. Same as the B<-x> option. |
| 5363 |
Group names and wildcards are permitted as described above for B<->I<TAG>. |
| 5364 |
Once excluded from the output, a tag may not be re-included by a subsequent |
| 5365 |
option. Also note that this excludes the tag from being used in a C<-if> |
| 5366 |
condition. May be used following a B<-tagsFromFile> option to exclude tags |
| 5367 |
from being copied (when redirecting to another tag, it is the source tag |
| 5368 |
that should be excluded), or to exclude groups from being deleted when |
| 5369 |
deleting all information (eg. C<-all= --exif:all> deletes all but EXIF |
| 5370 |
information). But note that this will not exclude individual tags from a |
| 5371 |
group delete (unless a family 2 group is specified, see note 4 below). |
| 5372 |
Instead, individual tags may be recovered using the B<-tagsFromFile> option |
| 5373 |
(eg. C<-all= -tagsfromfile @ -artist>). |
| 5374 |
|
| 5375 |
To speed processing when reading XMP, exclusions in XMP groups also bypass |
| 5376 |
processing of the corresponding XMP property and any contained properties. |
| 5377 |
For example, C<--xmp-crs:all> may speed processing significantly in cases |
| 5378 |
where a large number of XMP-crs tags exist. To use this feature to bypass |
| 5379 |
processing of a specific XMP property, the property name must be used |
| 5380 |
instead of the ExifTool tag name (eg. C<--xmp-crs:dabs>). Also, C<XMP-all> |
| 5381 |
may be used to to indicate any XMP namespace (eg. C<--xmp-all:dabs>). |
| 5382 |
|
| 5383 |
=item B<->I<TAG>[+-^]B<=>[I<VALUE>] |
| 5384 |
|
| 5385 |
Write a new value for the specified tag (eg. C<-comment=wow>), or delete the |
| 5386 |
tag if no I<VALUE> is given (eg. C<-comment=>). C<+=> and C<-=> are used to |
| 5387 |
add or remove existing entries from a list, or to shift date/time values |
| 5388 |
(see L<Image::ExifTool::Shift.pl|Image::ExifTool::Shift.pl> and notes 6 and |
| 5389 |
7 below for more details). C<+=> may also be used to increment numerical |
| 5390 |
values (or decrement if I<VALUE> is negative), and C<-=> may be used to |
| 5391 |
conditionally delete or replace a tag (see L</WRITING EXAMPLES> for |
| 5392 |
examples). C<^=> is used to write an empty string instead of deleting the |
| 5393 |
tag when no I<VALUE> is given, but otherwise it is equivalent to C<=>. |
| 5394 |
(Note that the caret must be quoted in the Windows CMD shell.) |
| 5395 |
|
| 5396 |
I<TAG> may contain one or more leading family 0, 1, 2 or 7 group names, |
| 5397 |
prefixed by optional family numbers, and separated colons. If no group name |
| 5398 |
is specified, the tag is created in the preferred group, and updated in any |
| 5399 |
other location where a same-named tag already exists. The preferred group |
| 5400 |
in JPEG and TIFF-format images is the first group in the following list |
| 5401 |
where I<TAG> is valid: 1) EXIF, 2) IPTC, 3) XMP. |
| 5402 |
|
| 5403 |
The wildcards C<*> and C<?> may be used in tag names to assign the same |
| 5404 |
value to multiple tags. When specified with wildcards, "Unsafe" tags are |
| 5405 |
not written. A tag name of C<All> is equivalent to C<*> (except that it |
| 5406 |
doesn't require quoting, while arguments with wildcards do on systems with |
| 5407 |
shell globbing), and is often used when deleting all metadata (ie. C<-All=>) |
| 5408 |
or an entire group (eg. C<-XMP-dc:All=>, see note 4 below). Note that not |
| 5409 |
all groups are deletable, and that the JPEG APP14 "Adobe" group is not |
| 5410 |
removed by default with C<-All=> because it may affect the appearance of the |
| 5411 |
image. However, color space information is removed, so the colors may be |
| 5412 |
affected (but this may be avoided by copying back the tags defined by the |
| 5413 |
ColorSpaceTags shortcut). Use the B<-listd> option for a complete list of |
| 5414 |
deletable groups, and see note 5 below regarding the "APP" groups. Also, |
| 5415 |
within an image some groups may be contained within others, and these groups |
| 5416 |
are removed if the containing group is deleted: |
| 5417 |
|
| 5418 |
JPEG Image: |
| 5419 |
- Deleting EXIF or IFD0 also deletes ExifIFD, GlobParamIFD, |
| 5420 |
GPS, IFD1, InteropIFD, MakerNotes, PrintIM and SubIFD. |
| 5421 |
- Deleting ExifIFD also deletes InteropIFD and MakerNotes. |
| 5422 |
- Deleting Photoshop also deletes IPTC. |
| 5423 |
|
| 5424 |
TIFF Image: |
| 5425 |
- Deleting EXIF only removes ExifIFD which also deletes |
| 5426 |
InteropIFD and MakerNotes. |
| 5427 |
|
| 5428 |
MOV/MP4 Video: |
| 5429 |
- Deleting ItemList also deletes Keys tags. |
| 5430 |
|
| 5431 |
Notes: |
| 5432 |
|
| 5433 |
1) B<Many tag values may be assigned in a single command>. If two |
| 5434 |
assignments affect the same tag, the latter takes precedence (except for |
| 5435 |
list-type tags, for which both values are written). |
| 5436 |
|
| 5437 |
2) In general, MakerNotes tags are considered "Permanent", and may be edited |
| 5438 |
but not created or deleted individually. This avoids many potential |
| 5439 |
problems, including the inevitable compatibility problems with OEM software |
| 5440 |
which may be very inflexible about the information it expects to find in the |
| 5441 |
maker notes. |
| 5442 |
|
| 5443 |
3) Changes to PDF files by ExifTool are reversible (by deleting the update |
| 5444 |
with C<-PDF-update:all=>) because the original information is never actually |
| 5445 |
deleted from the file. So ExifTool alone may not be used to securely edit |
| 5446 |
metadata in PDF files. |
| 5447 |
|
| 5448 |
4) Specifying C<-GROUP:all=> deletes the entire group as a block only if a |
| 5449 |
single family 0 or 1 group is specified. Otherwise all deletable tags in |
| 5450 |
the specified group(s) are removed individually, and in this case is it |
| 5451 |
possible to exclude individual tags from a mass delete. For example, |
| 5452 |
C<-time:all --Exif:Time:All> removes all deletable Time tags except those in |
| 5453 |
the EXIF. This difference also applies if family 2 is specified when |
| 5454 |
deleting all groups. For example, C<-2all:all=> deletes tags individually, |
| 5455 |
while C<-all:all=> deletes entire blocks. |
| 5456 |
|
| 5457 |
5) The "APP" group names ("APP0" through "APP15") are used to delete JPEG |
| 5458 |
application segments which are not associated with another deletable group. |
| 5459 |
For example, specifying C<-APP14:All=> will NOT delete the APP14 "Adobe" |
| 5460 |
segment because this is accomplished with C<-Adobe:All>. But note that |
| 5461 |
these unnamed APP segments may not be excluded with C<--APPxx:all> when |
| 5462 |
deleting all information. |
| 5463 |
|
| 5464 |
6) When shifting a value, the shift is applied to the original value of the |
| 5465 |
tag, overriding any other values previously assigned to the tag on the same |
| 5466 |
command line. To shift a date/time value and copy it to another tag in the |
| 5467 |
same operation, use the B<-globalTimeShift> option. |
| 5468 |
|
| 5469 |
7) The C<+=> operator may not be used to shift a List-type date/time tag |
| 5470 |
(eg. XMP-dc:Date) because C<+=> is used to add elements to the list. |
| 5471 |
Instead, the B<-globalTimeShift> option should be used. |
| 5472 |
|
| 5473 |
Special feature: Integer values may be specified in hexadecimal with a |
| 5474 |
leading C<0x>, and simple rational values may be specified as fractions. |
| 5475 |
|
| 5476 |
=item B<->I<TAG>E<lt>=I<DATFILE> or B<->I<TAG>E<lt>=I<FMT> |
| 5477 |
|
| 5478 |
Set the value of a tag from the contents of file I<DATFILE>. The file name |
| 5479 |
may also be given by a I<FMT> string where %d, %f and %e represent the |
| 5480 |
directory, file name and extension of the original I<FILE> (see the B<-w> |
| 5481 |
option for more details). Note that quotes are required around this |
| 5482 |
argument to prevent shell redirection since it contains a C<E<lt>> symbol. |
| 5483 |
If I<DATFILE>/I<FMT> is not provided, the effect is the same as C<-TAG=>, |
| 5484 |
and the tag is simply deleted. C<+E<lt>=> or C<-E<lt>=> may also be used to |
| 5485 |
add or delete specific list entries, to conditionally delete/replace tags, |
| 5486 |
or to shift date/time values. |
| 5487 |
|
| 5488 |
=item B<-tagsFromFile> I<SRCFILE> or I<FMT> |
| 5489 |
|
| 5490 |
Copy tag values from I<SRCFILE> to I<FILE>. Tag names on the command line |
| 5491 |
after this option specify the tags to be copied, or excluded from the copy. |
| 5492 |
Wildcards are permitted in these tag names. If no tags are specified, then |
| 5493 |
all possible tags (see note 1 below) from the source file are copied to |
| 5494 |
same-named tags in the preferred location of the output file (the same as |
| 5495 |
specifying C<-all>). More than one B<-tagsFromFile> option may be used to |
| 5496 |
copy tags from multiple files. |
| 5497 |
|
| 5498 |
By default, this option will update any existing and writable same-named |
| 5499 |
tags in the output I<FILE>, but will create new tags only in their preferred |
| 5500 |
groups. This allows some information to be automatically transferred to the |
| 5501 |
appropriate group when copying between images of different formats. However, |
| 5502 |
if a group name is specified for a tag then the information is written only |
| 5503 |
to this group (unless redirected to another group, see below). If C<All> is |
| 5504 |
used as a group name, then the specified tag(s) are written to the same |
| 5505 |
family 1 group they had in the source file (ie. the same specific location, |
| 5506 |
like ExifIFD or XMP-dc). For example, the common operation of copying all |
| 5507 |
writable tags to the same specific locations in the output I<FILE> is |
| 5508 |
achieved by adding C<-all:all>. A different family may be specified by |
| 5509 |
adding a leading family number to the group name (eg. C<-0all:all> preserves |
| 5510 |
the same general location, like EXIF or XMP). |
| 5511 |
|
| 5512 |
I<SRCFILE> may be the same as I<FILE> to move information around within a |
| 5513 |
single file. In this case, C<@> may be used to represent the source file |
| 5514 |
(ie. C<-tagsFromFile @>), permitting this feature to be used for batch |
| 5515 |
processing multiple files. Specified tags are then copied from each file in |
| 5516 |
turn as it is rewritten. For advanced batch use, the source file name may |
| 5517 |
also be specified using a I<FMT> string in which %d, %f and %e represent the |
| 5518 |
directory, file name and extension of I<FILE>. (eg. the current I<FILE> |
| 5519 |
would be represented by C<%d%f.%e>, with the same effect as C<@>). See the |
| 5520 |
B<-w> option for I<FMT> string examples. |
| 5521 |
|
| 5522 |
A powerful redirection feature allows a destination tag to be specified for |
| 5523 |
each copied tag. With this feature, information may be written to a tag |
| 5524 |
with a different name or group. This is done using |
| 5525 |
E<quot>'-I<DSTTAG>E<lt>I<SRCTAG>'E<quot> or |
| 5526 |
E<quot>'-I<SRCTAG>E<gt>I<DSTTAG>'E<quot> on the command line after |
| 5527 |
B<-tagsFromFile>, and causes the value of I<SRCTAG> to be copied from |
| 5528 |
I<SRCFILE> and written to I<DSTTAG> in I<FILE>. Has no effect unless |
| 5529 |
I<SRCTAG> exists in I<SRCFILE>. Note that this argument must be quoted to |
| 5530 |
prevent shell redirection, and there is no C<=> sign as when assigning new |
| 5531 |
values. Source and/or destination tags may be prefixed by a group name |
| 5532 |
and/or suffixed by C<#>. Wildcards are allowed in both the source and |
| 5533 |
destination tag names. A destination group and/or tag name of C<All> or |
| 5534 |
C<*> writes to the same family 1 group and/or tag name as the source (but |
| 5535 |
the family may be specified by adding a leading number to the group name, |
| 5536 |
eg. C<0All> writes to the same family 0 group as the source). If no |
| 5537 |
destination group is specified, the information is written to the preferred |
| 5538 |
group. Whitespace around the C<E<gt>> or C<E<lt>> is ignored. As a |
| 5539 |
convenience, C<-tagsFromFile @> is assumed for any redirected tags which are |
| 5540 |
specified without a prior B<-tagsFromFile> option. Copied tags may also be |
| 5541 |
added or deleted from a list, or conditionally deleted/replaced with |
| 5542 |
arguments of the form E<quot>'-I<SRCTAG>+E<lt>I<DSTTAG>'E<quot> or |
| 5543 |
E<quot>'-I<SRCTAG>-E<lt>I<DSTTAG>'E<quot> (but see Note 5 below). |
| 5544 |
|
| 5545 |
An extension of the redirection feature allows strings involving tag names |
| 5546 |
to be used on the right hand side of the C<E<lt>> symbol with the syntax |
| 5547 |
E<quot>'-I<DSTTAG>E<lt>I<STR>'E<quot>, where tag names in I<STR> are |
| 5548 |
prefixed with a C<$> symbol. See the B<-p> option and the |
| 5549 |
L</Advanced formatting feature> section for more details about this syntax. |
| 5550 |
Strings starting with a C<=> sign must insert a single space after the |
| 5551 |
C<E<lt>> to avoid confusion with the C<E<lt>=> operator which sets the tag |
| 5552 |
value from the contents of a file. A single space at the start of the |
| 5553 |
string is removed if it exists, but all other whitespace in the string is |
| 5554 |
preserved. See note 8 below about using the redirection feature with |
| 5555 |
list-type tags, shortcuts or when using wildcards in tag names. |
| 5556 |
|
| 5557 |
See L</COPYING EXAMPLES> for examples using B<-tagsFromFile>. |
| 5558 |
|
| 5559 |
Notes: |
| 5560 |
|
| 5561 |
1) Some tags (generally tags which may affect the appearance of the image) |
| 5562 |
are considered "Unsafe" to write, and are only copied if specified |
| 5563 |
explicitly (ie. no wildcards). See the |
| 5564 |
L<tag name documentation|Image::ExifTool::TagNames> for more details about |
| 5565 |
"Unsafe" tags. |
| 5566 |
|
| 5567 |
2) Be aware of the difference between excluding a tag from being copied |
| 5568 |
(--I<TAG>), and deleting a tag (-I<TAG>=). Excluding a tag prevents it from |
| 5569 |
being copied to the destination image, but deleting will remove a |
| 5570 |
pre-existing tag from the image. |
| 5571 |
|
| 5572 |
3) The maker note information is copied as a block, so it isn't affected |
| 5573 |
like other information by subsequent tag assignments on the command line, |
| 5574 |
and individual makernote tags may not be excluded from a block copy. Also, |
| 5575 |
since the PreviewImage referenced from the maker notes may be rather large, |
| 5576 |
it is not copied, and must be transferred separately if desired. |
| 5577 |
|
| 5578 |
4) The order of operations is to copy all specified tags at the point of the |
| 5579 |
B<-tagsFromFile> option in the command line. Any tag assignment to the |
| 5580 |
right of the B<-tagsFromFile> option is made after all tags are copied. For |
| 5581 |
example, new tag values are set in the order One, Two, Three then Four with |
| 5582 |
this command: |
| 5583 |
|
| 5584 |
exiftool -One=1 -tagsFromFile s.jpg -Two -Four=4 -Three d.jpg |
| 5585 |
|
| 5586 |
This is significant in the case where an overlap exists between the copied |
| 5587 |
and assigned tags because later operations may override earlier ones. |
| 5588 |
|
| 5589 |
5) The normal behaviour of copied tags differs from that of assigned tags |
| 5590 |
for list-type tags and conditional replacements because each copy operation |
| 5591 |
on a tag overrides any previous operations. While this avoids duplicate |
| 5592 |
list items when copying groups of tags from a file containing redundant |
| 5593 |
information, it also prevents values of different tags from being copied |
| 5594 |
into the same list when this is the intent. To accumulate values |
| 5595 |
from different operations into the same list, add a C<+> after the initial |
| 5596 |
C<-> of the argument or use the B<-addTagsFromFile> option. For example: |
| 5597 |
|
| 5598 |
exiftool -tagsfromfile @ '-subject<make' '-+subject<model' ... |
| 5599 |
|
| 5600 |
or |
| 5601 |
|
| 5602 |
exiftool -addtagsfromfile @ '-subject<make' '-subject<model' ... |
| 5603 |
|
| 5604 |
Similarly, C<-+DSTTAG> or B<-addTagsFromFile> must be used when |
| 5605 |
conditionally replacing a tag to prevent overriding earlier conditions. |
| 5606 |
|
| 5607 |
Other than these differences, the B<-tagsFromFile> and B<-addTagsFromFile> |
| 5608 |
options are equivalent. |
| 5609 |
|
| 5610 |
6) The B<-a> option (allow duplicate tags) is always in effect when copying |
| 5611 |
tags from I<SRCFILE>, but the highest priority tag is always copied last so |
| 5612 |
it takes precedence. |
| 5613 |
|
| 5614 |
7) Structured tags are copied by default when copying tags. See the |
| 5615 |
B<-struct> option for details. |
| 5616 |
|
| 5617 |
8) With the redirection feature, copying a tag directly (ie. |
| 5618 |
E<quot>'-I<DSTTAG>E<lt>I<SRCTAG>'E<quot>) is not the same as interpolating |
| 5619 |
its value inside a string (ie. E<quot>'-I<DSTTAG>E<lt>$I<SRCTAG>'E<quot>) |
| 5620 |
for source tags which are list-type tags, |
| 5621 |
L<shortcut tags|Image::ExifTool::Shortcuts>, or tag names containing |
| 5622 |
wildcards. When copying directly, the values of each matching source tag |
| 5623 |
are copied individually to the destination tag (as if they were separate |
| 5624 |
assignments). However, when interpolated inside a string, list items and |
| 5625 |
the values of shortcut tags are concatenated (with a separator set by the |
| 5626 |
B<-sep> option), and wildcards are not allowed. Another difference is that a |
| 5627 |
minor warning is generated if a tag doesn't exist when interpolating its |
| 5628 |
value in a string (with C<$>), but isn't when copying the tag directly. |
| 5629 |
|
| 5630 |
Finally, the behaviour is different when a destination tag or group of |
| 5631 |
C<All> is used. When copying directly, a destination group and/or tag name |
| 5632 |
of C<All> writes to the same family 1 group and/or tag name as the source. |
| 5633 |
But when interpolated in a string, the identity of the source tags are lost |
| 5634 |
and the value is written to all possible groups/tags. For example, the |
| 5635 |
string form must be used in the following command since the intent is to set |
| 5636 |
the value of all existing date/time tags from C<CreateDate>: |
| 5637 |
|
| 5638 |
exiftool '-time:all<$createdate' -wm w FILE |
| 5639 |
|
| 5640 |
=item B<-x> I<TAG> (B<-exclude>) |
| 5641 |
|
| 5642 |
Exclude the specified tag. There may be multiple B<-x> options. This has |
| 5643 |
the same effect as --I<TAG> on the command line. See the --I<TAG> |
| 5644 |
documentation above for a complete description. |
| 5645 |
|
| 5646 |
=back |
| 5647 |
|
| 5648 |
=head3 Input-output text formatting |
| 5649 |
|
| 5650 |
Note that trailing spaces are removed from extracted values for most output |
| 5651 |
text formats. The exceptions are B<-b>, B<-csv>, B<-j> and B<-X>. |
| 5652 |
|
| 5653 |
=over 5 |
| 5654 |
|
| 5655 |
=item B<-args> (B<-argFormat>) |
| 5656 |
|
| 5657 |
Output information in the form of exiftool arguments, suitable for use with |
| 5658 |
the B<-@> option when writing. May be combined with the B<-G> option to |
| 5659 |
include group names. This feature may be used to effectively copy tags |
| 5660 |
between images, but allows the metadata to be altered by editing the |
| 5661 |
intermediate file (C<out.args> in this example): |
| 5662 |
|
| 5663 |
exiftool -args -G1 --filename --directory src.jpg > out.args |
| 5664 |
exiftool -@ out.args -sep ', ' dst.jpg |
| 5665 |
|
| 5666 |
Note: Be careful when copying information with this technique since it is |
| 5667 |
easy to write tags which are normally considered "Unsafe". For instance, |
| 5668 |
the FileName and Directory tags are excluded in the example above to avoid |
| 5669 |
renaming and moving the destination file. Also note that the second command |
| 5670 |
above will produce warning messages for any tags which are not writable. |
| 5671 |
|
| 5672 |
As well, the B<-sep> option should be used as in the second command above to |
| 5673 |
maintain separate list items when writing metadata back to image files, and |
| 5674 |
the B<-struct> option may be used when extracting to preserve structured XMP |
| 5675 |
information. |
| 5676 |
|
| 5677 |
=item B<-b>, B<--b> (B<-binary>, B<--binary>) |
| 5678 |
|
| 5679 |
Output requested metadata in binary format without tag names or descriptions |
| 5680 |
(B<-b> or B<-binary>). This option is mainly used for extracting embedded |
| 5681 |
images or other binary data, but it may also be useful for some text strings |
| 5682 |
since control characters (such as newlines) are not replaced by '.' as they |
| 5683 |
are in the default output. By default, list items are separated by a |
| 5684 |
newline when extracted with the B<-b> option and no terminator is added |
| 5685 |
after each tag value, but the list separator may be changed with a B<-sep> |
| 5686 |
option and a terminator may be set by adding a second B<-sep> option (see |
| 5687 |
the B<-sep> option for details). May be combined with B<-j>, B<-php> or |
| 5688 |
B<-X> to extract binary data in JSON, PHP or XML format, but note that |
| 5689 |
"Unsafe" tags are not extracted as binary unless they are specified |
| 5690 |
explicitly or the API RequestAll option is set to 3 or higher. |
| 5691 |
|
| 5692 |
With a leading double dash (B<--b> or B<--binary>), tags which contain |
| 5693 |
binary data are suppressed in the output when reading. |
| 5694 |
|
| 5695 |
=item B<-c> I<FMT> (B<-coordFormat>) |
| 5696 |
|
| 5697 |
Set the print format for GPS coordinates. I<FMT> uses the same syntax as |
| 5698 |
a C<printf> format string. The specifiers correspond to degrees, minutes |
| 5699 |
and seconds in that order, but minutes and seconds are optional. For |
| 5700 |
example, the following table gives the output for the same coordinate using |
| 5701 |
various formats: |
| 5702 |
|
| 5703 |
FMT Output |
| 5704 |
------------------- ------------------ |
| 5705 |
"%d deg %d' %.2f"\" 54 deg 59' 22.80" (default for reading) |
| 5706 |
"%d %d %.8f" 54 59 22.80000000 (default for copying) |
| 5707 |
"%d deg %.4f min" 54 deg 59.3800 min |
| 5708 |
"%.6f degrees" 54.989667 degrees |
| 5709 |
|
| 5710 |
Notes: |
| 5711 |
|
| 5712 |
1) To avoid loss of precision, the default coordinate format is different |
| 5713 |
when copying tags using the B<-tagsFromFile> option. |
| 5714 |
|
| 5715 |
2) If the hemisphere is known, a reference direction (N, S, E or W) is |
| 5716 |
appended to each printed coordinate, but adding a C<+> or C<-> to the format |
| 5717 |
specifier (eg. C<%+.6f> or C<%-.6f>) prints a signed coordinate instead. |
| 5718 |
(C<+> adds a leading "+" for positive coordinates, but C<-> does not.) |
| 5719 |
|
| 5720 |
3) This print formatting may be disabled with the B<-n> option to extract |
| 5721 |
coordinates as signed decimal degrees. |
| 5722 |
|
| 5723 |
=item B<-charset> [[I<TYPE>=]I<CHARSET>] |
| 5724 |
|
| 5725 |
If I<TYPE> is C<ExifTool> or not specified, this option sets the ExifTool |
| 5726 |
character encoding for output tag values when reading and input values when |
| 5727 |
writing, with a default of C<UTF8>. If no I<CHARSET> is given, a list of |
| 5728 |
available character sets is returned. Valid I<CHARSET> values are: |
| 5729 |
|
| 5730 |
CHARSET Alias(es) Description |
| 5731 |
---------- --------------- ---------------------------------- |
| 5732 |
UTF8 cp65001, UTF-8 UTF-8 characters (default) |
| 5733 |
Latin cp1252, Latin1 Windows Latin1 (West European) |
| 5734 |
Latin2 cp1250 Windows Latin2 (Central European) |
| 5735 |
Cyrillic cp1251, Russian Windows Cyrillic |
| 5736 |
Greek cp1253 Windows Greek |
| 5737 |
Turkish cp1254 Windows Turkish |
| 5738 |
Hebrew cp1255 Windows Hebrew |
| 5739 |
Arabic cp1256 Windows Arabic |
| 5740 |
Baltic cp1257 Windows Baltic |
| 5741 |
Vietnam cp1258 Windows Vietnamese |
| 5742 |
Thai cp874 Windows Thai |
| 5743 |
DOSLatinUS cp437 DOS Latin US |
| 5744 |
DOSLatin1 cp850 DOS Latin1 |
| 5745 |
DOSCyrillic cp866 DOS Cyrillic |
| 5746 |
MacRoman cp10000, Roman Macintosh Roman |
| 5747 |
MacLatin2 cp10029 Macintosh Latin2 (Central Europe) |
| 5748 |
MacCyrillic cp10007 Macintosh Cyrillic |
| 5749 |
MacGreek cp10006 Macintosh Greek |
| 5750 |
MacTurkish cp10081 Macintosh Turkish |
| 5751 |
MacRomanian cp10010 Macintosh Romanian |
| 5752 |
MacIceland cp10079 Macintosh Icelandic |
| 5753 |
MacCroatian cp10082 Macintosh Croatian |
| 5754 |
|
| 5755 |
I<TYPE> may be C<FileName> to specify the encoding of file names on the |
| 5756 |
command line (ie. I<FILE> arguments). In Windows, this triggers use of |
| 5757 |
wide-character i/o routines, thus providing support for Unicode file names. |
| 5758 |
See the L</WINDOWS UNICODE FILE NAMES> section below for details. |
| 5759 |
|
| 5760 |
Other values of I<TYPE> listed below are used to specify the internal |
| 5761 |
encoding of various meta information formats. |
| 5762 |
|
| 5763 |
TYPE Description Default |
| 5764 |
--------- ------------------------------------------- ------- |
| 5765 |
EXIF Internal encoding of EXIF "ASCII" strings (none) |
| 5766 |
ID3 Internal encoding of ID3v1 information Latin |
| 5767 |
IPTC Internal IPTC encoding to assume when Latin |
| 5768 |
IPTC:CodedCharacterSet is not defined |
| 5769 |
Photoshop Internal encoding of Photoshop IRB strings Latin |
| 5770 |
QuickTime Internal encoding of QuickTime strings MacRoman |
| 5771 |
RIFF Internal encoding of RIFF strings 0 |
| 5772 |
|
| 5773 |
See L<https://exiftool.org/faq.html#Q10> for more information about coded |
| 5774 |
character sets, and the L<Image::ExifTool Options|Image::ExifTool/Options> |
| 5775 |
for more details about the B<-charset> settings. |
| 5776 |
|
| 5777 |
=item B<-csv>[[+]=I<CSVFILE>] |
| 5778 |
|
| 5779 |
Export information in CSV format, or import information if I<CSVFILE> is |
| 5780 |
specified. When importing, the CSV file must be in exactly the same format |
| 5781 |
as the exported file. The first row of the I<CSVFILE> must be the ExifTool |
| 5782 |
tag names (with optional group names) for each column of the file, and |
| 5783 |
values must be separated by commas. A special "SourceFile" column specifies |
| 5784 |
the files associated with each row of information (and a SourceFile of "*" |
| 5785 |
may be used to define default tags to be imported for all files, which are |
| 5786 |
then combined with any tags specified for the specific SourceFile |
| 5787 |
processed). To be clear, the imported CSV file acts as a lookup table to |
| 5788 |
obtain the tags for import based on the files/directories and tags specified |
| 5789 |
on the command line. The B<-csvDelim> option may be used to change the |
| 5790 |
input/output field delimiter if something other than a comma is required. |
| 5791 |
|
| 5792 |
The following examples demonstrate basic use of the B<-csv> option: |
| 5793 |
|
| 5794 |
# generate CSV file with common tags from all images in a directory |
| 5795 |
exiftool -common -csv dir > out.csv |
| 5796 |
|
| 5797 |
# update metadata for all images in a directory from CSV file |
| 5798 |
exiftool -csv=a.csv dir |
| 5799 |
|
| 5800 |
When importing, empty values are ignored unless the B<-f> option is used and |
| 5801 |
the API MissingTagValue is set to an empty string (in which case the tag is |
| 5802 |
deleted). Also, FileName and Directory columns are ignored if they exist |
| 5803 |
(ie. ExifTool will not attempt to write these tags with a CSV import), but |
| 5804 |
all other columns are imported. To force a tag to be deleted, use the B<-f> |
| 5805 |
option and set the value to "-" in the CSV file (or to the MissingTagValue |
| 5806 |
if this API option was used). Multiple databases may be imported in a |
| 5807 |
single command. |
| 5808 |
|
| 5809 |
Specific tags may be imported from the CSV database by adding B<->I<TAG> |
| 5810 |
options to the command after B<-csv=>I<CSVFILE>, or excluded with |
| 5811 |
B<-->I<TAG>, with exclusions taking priority. Group names and wildcards in |
| 5812 |
tag names are allowed, but the group name must match exactly the group in |
| 5813 |
the CSV file (eg. a C<XMP-dc:Subject> column in the CSV file won't match |
| 5814 |
C<-XMP:Subject> on the command line. Also, tags from the CSV may be |
| 5815 |
redirected and written to different tags in the target file with support for |
| 5816 |
advanced-formatting expressions using the same syntax as the |
| 5817 |
B<-tagsFromFile> feature. If no tags are specified, then all tags except |
| 5818 |
FileName, Directory and excluded tags are imported (in the same order as the |
| 5819 |
database entries). |
| 5820 |
|
| 5821 |
When exporting a CSV file, the B<-g> or B<-G> option adds group names to the |
| 5822 |
tag headings. If the B<-a> option is used to allow duplicate tag names, the |
| 5823 |
duplicate tags are only included in the CSV output if the column headings |
| 5824 |
are unique. Adding the B<-G4> option ensures a unique column heading for |
| 5825 |
each tag. The B<-b> option may be added to output binary data, encoded in |
| 5826 |
base64 if necessary (indicated by ASCII "base64:" as the first 7 bytes of |
| 5827 |
the value). Values may also be encoded in base64 if the B<-charset> option |
| 5828 |
is used and the value contains invalid characters. |
| 5829 |
|
| 5830 |
When exporting specific tags, the CSV columns are arranged in the same order |
| 5831 |
as the specified tags provided the column headings exactly match the |
| 5832 |
specified tag names, otherwise the columns are sorted in alphabetical order. |
| 5833 |
|
| 5834 |
When importing from a CSV file, only files specified on the command line are |
| 5835 |
processed. Any extra entries in the CSV file are ignored. |
| 5836 |
|
| 5837 |
List-type tags are stored as simple strings in a CSV file, but the B<-sep> |
| 5838 |
option may be used to split them back into separate items when importing. |
| 5839 |
|
| 5840 |
Special feature: B<-csv>+=I<CSVFILE> may be used to add items to existing |
| 5841 |
lists in the file. This affects only list-type tags. Also applies to the |
| 5842 |
B<-j> option. |
| 5843 |
|
| 5844 |
Note that this and the B<-plot> options are fundamentally different than all |
| 5845 |
other output format options because they require information from all input |
| 5846 |
files to be buffered in memory before the output is written. This may |
| 5847 |
result in excessive memory usage when processing a very large number of |
| 5848 |
files with a single command. Also, when used with B<-csv>, the B<-w> option |
| 5849 |
changes to specify a complete file name with no filename formatting codes or |
| 5850 |
append mode allowed, and B<-W> may not be used. When processing a large |
| 5851 |
number of files, it is recommended to either use the JSON (B<-j>) or XML |
| 5852 |
(B<-X>) output format, or use B<-p> to generate a fixed-column CSV file |
| 5853 |
instead of using the B<-csv> option. |
| 5854 |
|
| 5855 |
=item B<-csvDelim> I<STR> |
| 5856 |
|
| 5857 |
Set the delimiter for separating CSV entries for CSV file input/output via |
| 5858 |
the B<-csv> option. I<STR> may contain "\t", "\n", "\r" and "\\" to |
| 5859 |
represent TAB, LF, CR and '\' respectively. A double quote is not allowed |
| 5860 |
in the delimiter. Default is ','. |
| 5861 |
|
| 5862 |
=item B<-d> I<FMT> (B<-dateFormat>) |
| 5863 |
|
| 5864 |
Set the format for date/time tag values. The I<FMT> string may contain |
| 5865 |
formatting codes beginning with a percent character (C<%>) to represent the |
| 5866 |
various components of a date/time value. ExifTool implements 3 format codes |
| 5867 |
internally (see below), but other format codes are system dependent -- |
| 5868 |
consult the C<strftime> man page on your system for details. The default |
| 5869 |
format is equivalent to "%Y:%m:%d %H:%M:%S". This option has no effect on |
| 5870 |
date-only or time-only tags. Requires POSIX::strptime or Time::Piece for |
| 5871 |
the inversion conversion when writing. Only one B<-d> option may be used |
| 5872 |
per command. |
| 5873 |
|
| 5874 |
Additional format codes implemented internally by ExifTool: |
| 5875 |
|
| 5876 |
1) C<%z> represents the time zone in "+/-HHMM" format. Adding a colon (ie. |
| 5877 |
C<%:z>) adds a colon separator (eg. "-05:00"). If the date/time value |
| 5878 |
doesn't contain a time zone then C<%z> gives the system time zone for the |
| 5879 |
specified date/time value. |
| 5880 |
|
| 5881 |
2) C<%f> represents fractional seconds, and supports an optional width to |
| 5882 |
specify the number of digits after the decimal point (eg. C<%3f> would give |
| 5883 |
something like ".437"). Adding a minus sign drops the decimal point (eg. |
| 5884 |
C<%-3f> would give "437"). |
| 5885 |
|
| 5886 |
3) C<%s> represents the number of seconds since 00:00 UTC Jan 1, 1970, |
| 5887 |
taking into account the specified time zone (or system time zone if not |
| 5888 |
specified). |
| 5889 |
|
| 5890 |
=item B<-D> (B<-decimal>) |
| 5891 |
|
| 5892 |
Show tag ID number in decimal when extracting information. |
| 5893 |
|
| 5894 |
=item B<-E>, B<-ex>, B<-ec> (B<-escapeHTML>, B<-escapeXML>, B<-escapeC>) |
| 5895 |
|
| 5896 |
Escape characters in output tag values for HTML (B<-E>), XML (B<-ex>) or C |
| 5897 |
(B<-ec>). For HTML, all characters with Unicode code points above U+007F |
| 5898 |
are escaped as well as the following 5 characters: & (&) E<39> (') |
| 5899 |
E<quot> (") E<gt> (>) and E<lt> (<). For XML, only these 5 |
| 5900 |
characters are escaped. The B<-E> option is implied with B<-h>, B<-ex> is |
| 5901 |
implied with B<-X>, B<-ec> is implied with B<-json>, and none of these |
| 5902 |
options apply to the B<-csv> output. For C, all control characters and the |
| 5903 |
backslash are escaped. The inverse conversion is applied when writing tags. |
| 5904 |
|
| 5905 |
=item B<-f> (B<-forcePrint>) |
| 5906 |
|
| 5907 |
Force printing of tags even if they don't exist. This option applies to |
| 5908 |
tags specified on the command line, or with the B<-p>, B<-if> (unless the |
| 5909 |
API UndefTags option is set), B<-fileNUM> or B<-tagsFromFile> options. When |
| 5910 |
B<-f> is used, the value of any missing tag is set to a dash (C<->) by |
| 5911 |
default, but this may be configured via the API MissingTagValue option. |
| 5912 |
B<-f> is also used to add a 'flags' attribute to the B<-listx> output, or to |
| 5913 |
allow tags to be deleted when writing with the B<-csv>=I<CSVFILE> feature. |
| 5914 |
|
| 5915 |
=item B<-g>[I<NUM>][:I<NUM>...] (B<-groupHeadings>) |
| 5916 |
|
| 5917 |
Organize output by tag group. I<NUM> specifies a group family number, and |
| 5918 |
may be 0 (general location), 1 (specific location), 2 (category), 3 |
| 5919 |
(document number), 4 (instance number), 5 (metadata path), 6 (EXIF/TIFF |
| 5920 |
format), 7 (tag ID) or 8 (file number). B<-g0> is assumed if a family |
| 5921 |
number is not specified. May be combined with other options to add group |
| 5922 |
names to the output. Multiple families may be specified by separating them |
| 5923 |
with colons. By default the resulting group name is simplified by removing |
| 5924 |
any leading C<Main:> and collapsing adjacent identical group names, but this |
| 5925 |
can be avoided by placing a colon before the first family number (eg. |
| 5926 |
B<-g:3:1>). Use the B<-listg> option to list group names for a specified |
| 5927 |
family. The API SavePath and SaveFormat options are automatically enabled |
| 5928 |
if the respective family 5 or 6 group names are requested. See the |
| 5929 |
L<API GetGroup documentation|Image::ExifTool/GetGroup> for more information. |
| 5930 |
|
| 5931 |
=item B<-G>[I<NUM>][:I<NUM>...] (B<-groupNames>) |
| 5932 |
|
| 5933 |
Same as B<-g> but print group name for each tag. B<-G0> is assumed if |
| 5934 |
I<NUM> is not specified. May be combined with a number of other options to |
| 5935 |
add group names to the output. Note that I<NUM> may be added wherever B<-G> |
| 5936 |
is mentioned in the documentation. See the B<-g> option above for details. |
| 5937 |
|
| 5938 |
=item B<-h> (B<-htmlFormat>) |
| 5939 |
|
| 5940 |
Use HTML table formatting for output. Implies the B<-E> option. The |
| 5941 |
formatting options B<-D>, B<-H>, B<-g>, B<-G>, B<-l> and B<-s> may be used |
| 5942 |
in combination with B<-h> to influence the HTML format. |
| 5943 |
|
| 5944 |
=item B<-H> (B<-hex>) |
| 5945 |
|
| 5946 |
Show tag ID number in hexadecimal when extracting information. |
| 5947 |
|
| 5948 |
=item B<-htmlDump>[I<OFFSET>] |
| 5949 |
|
| 5950 |
Generate a dynamic web page containing a hex dump of the EXIF information. |
| 5951 |
This can be a very powerful tool for low-level analysis of EXIF information. |
| 5952 |
The B<-htmlDump> option is also invoked if the B<-v> and B<-h> options are |
| 5953 |
used together. The verbose level controls the maximum length of the blocks |
| 5954 |
dumped. An I<OFFSET> may be given to specify the base for displayed |
| 5955 |
offsets. If not provided, the EXIF/TIFF base offset is used. Use |
| 5956 |
B<-htmlDump0> for absolute offsets. Currently only EXIF/TIFF and JPEG |
| 5957 |
information is dumped, but the -u option can be used to give a raw hex dump |
| 5958 |
of other file formats. |
| 5959 |
|
| 5960 |
=item B<-j>[[+]=I<JSONFILE>] (B<-json>) |
| 5961 |
|
| 5962 |
Use JSON (JavaScript Object Notation) formatting for console output, or |
| 5963 |
import JSON file if I<JSONFILE> is specified. This option may be combined |
| 5964 |
with B<-g> to organize the output into objects by group, or B<-G> to add |
| 5965 |
group names to each tag. List-type tags with multiple items are output as |
| 5966 |
JSON arrays unless B<-sep> is used. By default XMP structures are flattened |
| 5967 |
into individual tags in the JSON output, but the original structure may be |
| 5968 |
preserved with the B<-struct> option (this also causes all list-type XMP |
| 5969 |
tags to be output as JSON arrays, otherwise single-item lists would be |
| 5970 |
output as simple strings). The B<-a> option is implied when B<-json> is |
| 5971 |
used, but entries with identical JSON names are suppressed in the output. |
| 5972 |
(B<-G4> may be used to ensure that all tags have unique JSON names.) |
| 5973 |
|
| 5974 |
Adding the B<-D> or B<-H> option changes tag values to JSON objects with |
| 5975 |
"val" and "id" fields. Adding B<-l> adds a "desc" field, and a "num" field |
| 5976 |
if the numerical value is different from the converted "val", and "fmt" and |
| 5977 |
"hex" fields for EXIF metadata if the API SaveFormat and SaveBin options are |
| 5978 |
set respectively. The length of the "hex" output is limited by the API |
| 5979 |
LimitLongValues setting. Setting the SaveBin option also causes the |
| 5980 |
original values of Rational tags to be returned in string form as an extra |
| 5981 |
"rat" field. The B<-b> option may be added to output binary data, encoded |
| 5982 |
in base64 if necessary (indicated by ASCII "base64:" as the first 7 bytes of |
| 5983 |
the value), and B<-t> may be added to include tag table information (see |
| 5984 |
B<-t> for details). The JSON output is UTF-8 regardless of any B<-L> or |
| 5985 |
B<-charset> option setting, but the UTF-8 validation is disabled if a |
| 5986 |
character set other than UTF-8 is specified. |
| 5987 |
|
| 5988 |
Note that ExifTool quotes JSON values only if they don't look like numbers |
| 5989 |
(regardless of the original storage format or the relevant metadata |
| 5990 |
specification). This may be a problem when reading the JSON via a strongly |
| 5991 |
typed language. However, the API StructFormat option may be set to "JSONQ" |
| 5992 |
to force quoting of numbers. As well, the B<-sep> option may be used to |
| 5993 |
convert arrays into strings. For example: |
| 5994 |
|
| 5995 |
exiftool -j -api structformat=jsonq -sep ", " ... |
| 5996 |
|
| 5997 |
If I<JSONFILE> is specified, the JSON file is imported and the tag |
| 5998 |
definitions from the JSON are used to set tag values on a per-file basis for |
| 5999 |
each file specified on the command line. A special "SourceFile" entry in |
| 6000 |
each JSON object associates the information with a specific target file. An |
| 6001 |
object with a missing SourceFile or a SourceFile of "*" defines default tags |
| 6002 |
for all target files which are combined with any tags specified for the |
| 6003 |
specific SourceFile processed. The imported JSON file must have the same |
| 6004 |
format as the exported JSON files with the exception that options exporting |
| 6005 |
JSON objects instead of simple values are not compatible with the import |
| 6006 |
file format (ie. export with B<-D>, B<-H>, B<-l>, or B<-T> is not |
| 6007 |
compatible, and use B<-G> instead of B<-g>). Additionally, tag names in the |
| 6008 |
input JSON file may be suffixed with a C<#> to disable print conversion. |
| 6009 |
|
| 6010 |
Specific tags may be imported from the JSON database by adding B<->I<TAG> |
| 6011 |
options to the command after B<-j=>I<JSONFILE>, or excluded with |
| 6012 |
B<-->I<TAG>, with exclusions taking priority. Group names and wildcards in |
| 6013 |
tag names are allowed, but the group name must match exactly the group in |
| 6014 |
the JSON file (eg. a C<XMP-dc:Subject> entry in the JSON file won't match |
| 6015 |
C<-XMP:Subject> on the command line. Also, tags from JSON may be redirected |
| 6016 |
and written to different tags in the target file with support for |
| 6017 |
advanced-formatting expressions using the same syntax as the |
| 6018 |
B<-tagsFromFile> feature. If no tags are specified, then all tags except |
| 6019 |
FileName, Directory and excluded tags are imported (in the same order as the |
| 6020 |
database entries). |
| 6021 |
|
| 6022 |
Unlike CSV import, empty values are not ignored, and will cause an empty |
| 6023 |
value to be written if supported by the specific metadata type. Tags are |
| 6024 |
deleted by using the B<-f> option and setting the tag value to "-" (or to |
| 6025 |
the MissingTagValue setting if this API option was used). Importing with |
| 6026 |
B<-j>+=I<JSONFILE> causes new values to be added to existing lists in the |
| 6027 |
target file. |
| 6028 |
|
| 6029 |
=item B<-l> (B<-long>) |
| 6030 |
|
| 6031 |
Use long 2-line Canon-style output format. Adds a description and |
| 6032 |
unconverted value (if it is different from the converted value) to the XML, |
| 6033 |
JSON or PHP output when B<-X>, B<-j> or B<-php> is used. May also be |
| 6034 |
combined with B<-listf>, B<-listr> or B<-listwf> to add descriptions of the |
| 6035 |
file types. |
| 6036 |
|
| 6037 |
=item B<-L> (B<-latin>) |
| 6038 |
|
| 6039 |
Use Windows Latin1 encoding (cp1252) for output tag values instead of the |
| 6040 |
default UTF-8. When writing, B<-L> specifies that input text values are |
| 6041 |
Latin1 instead of UTF-8. Equivalent to C<-charset latin>. |
| 6042 |
|
| 6043 |
=item B<-lang> [I<LANG>] |
| 6044 |
|
| 6045 |
Set current language for tag descriptions and converted values. I<LANG> is |
| 6046 |
C<de>, C<fr>, C<ja>, etc. Use B<-lang> with no other arguments to get a |
| 6047 |
list of available languages. The default language is C<en> if B<-lang> is |
| 6048 |
not specified. Note that tag/group names are always English, independent of |
| 6049 |
the B<-lang> setting, and translation of warning/error messages has not yet |
| 6050 |
been implemented. May also be combined with B<-listx> to output |
| 6051 |
descriptions in one language only. |
| 6052 |
|
| 6053 |
By default, ExifTool uses UTF-8 encoding for special characters, but the |
| 6054 |
B<-L> or B<-charset> option may be used to invoke other encodings. Note |
| 6055 |
that ExifTool uses Unicode::LineBreak if available to help preserve the |
| 6056 |
column alignment of the plain text output for languages with a |
| 6057 |
variable-width character set. |
| 6058 |
|
| 6059 |
Currently, the language support is not complete, but users are welcome to |
| 6060 |
help improve this by submitting their own translations. To submit a |
| 6061 |
translation, follow these steps (you must have Perl installed for this): |
| 6062 |
|
| 6063 |
1. Download and unpack the latest Image-ExifTool full distribution. |
| 6064 |
|
| 6065 |
2. 'cd' into the Image-ExifTool directory. |
| 6066 |
|
| 6067 |
3. Run this command to make an XML file of the desired tags (eg. EXIF): |
| 6068 |
|
| 6069 |
./exiftool -listx -exif:all > out.xml |
| 6070 |
|
| 6071 |
4. Copy this text into a file called 'import.pl' in the exiftool directory: |
| 6072 |
|
| 6073 |
push @INC, 'lib'; |
| 6074 |
require Image::ExifTool::TagInfoXML; |
| 6075 |
my $file = shift or die "Expected XML file name\n"; |
| 6076 |
$Image::ExifTool::TagInfoXML::makeMissing = shift; |
| 6077 |
Image::ExifTool::TagInfoXML::BuildLangModules($file,8); |
| 6078 |
|
| 6079 |
5. Run the 'import.pl' script to Import the XML file, generating the |
| 6080 |
'MISSING' entries for your language (eg. Russian): |
| 6081 |
|
| 6082 |
perl import.pl out.xml ru |
| 6083 |
|
| 6084 |
6. Edit the generated language module lib/Image/ExifTool/Lang/ru.pm, and |
| 6085 |
search and replace all 'MISSING' strings in the file with your translations. |
| 6086 |
|
| 6087 |
7. Email the module ('ru.pm' in this example) to [email protected] |
| 6088 |
|
| 6089 |
8. Thank you!! |
| 6090 |
|
| 6091 |
=item B<-listItem> I<INDEX> |
| 6092 |
|
| 6093 |
For list-type tags, this causes only the item with the specified index to be |
| 6094 |
extracted. I<INDEX> is 0 for the first item in the list. Negative indices |
| 6095 |
may also be used to reference items from the end of the list. Has no effect |
| 6096 |
on single-valued tags. Also applies to tag values when copying from a tag, |
| 6097 |
and in B<-if>, B<-p> and B<-fileNUM> arguments. |
| 6098 |
|
| 6099 |
=item B<-n> (B<--printConv>) |
| 6100 |
|
| 6101 |
Disable print conversion for all tags. By default, extracted values are |
| 6102 |
converted to a more human-readable format, but the B<-n> option disables |
| 6103 |
this conversion, revealing the machine-readable values. For example: |
| 6104 |
|
| 6105 |
> exiftool -Orientation -S a.jpg |
| 6106 |
Orientation: Rotate 90 CW |
| 6107 |
> exiftool -Orientation -S -n a.jpg |
| 6108 |
Orientation: 6 |
| 6109 |
|
| 6110 |
The print conversion may also be disabled on a per-tag basis by suffixing |
| 6111 |
the tag name with a C<#> character: |
| 6112 |
|
| 6113 |
> exiftool -Orientation# -Orientation -S a.jpg |
| 6114 |
Orientation: 6 |
| 6115 |
Orientation: Rotate 90 CW |
| 6116 |
|
| 6117 |
These techniques may also be used to disable the inverse print conversion |
| 6118 |
when writing. For example, the following commands all have the same effect: |
| 6119 |
|
| 6120 |
> exiftool -Orientation='Rotate 90 CW' a.jpg |
| 6121 |
> exiftool -Orientation=6 -n a.jpg |
| 6122 |
> exiftool -Orientation#=6 a.jpg |
| 6123 |
|
| 6124 |
=item B<-p>[-] I<STR> or I<FMTFILE> (B<-printFormat>) |
| 6125 |
|
| 6126 |
Print output in the format specified by the given string or file. The |
| 6127 |
argument is interpreted as a string unless a file of that name exists, in |
| 6128 |
which case the string is loaded from the contents of the file. Tag names in |
| 6129 |
the format string or file begin with a C<$> symbol and may contain leading |
| 6130 |
group names and/or a trailing C<#> (to disable print conversion). Case is |
| 6131 |
not significant. Braces C<{}> may be used around the tag name to separate |
| 6132 |
it from subsequent text (and must be used if subsequent text begins with an |
| 6133 |
alphanumeric character, hyphen, underline, colon or number sign). Use C<$$> |
| 6134 |
to represent a C<$> symbol, and C<$/> for a newline. When the string |
| 6135 |
argument is used (ie. I<STR>), a newline is added to the end of the string |
| 6136 |
unless B<-p-> is specified or the B<-b> option is used. |
| 6137 |
|
| 6138 |
Multiple B<-p> options may be used. Lines beginning with C<#[HEAD]> and |
| 6139 |
C<#[TAIL]> are output before the first processed file and after the last |
| 6140 |
processed file respectively. Lines beginning with C<#[SECT]> and C<#[ENDS]> |
| 6141 |
are output before and after each section of files. A section is defined as |
| 6142 |
a group of consecutive files with the same section header (eg. files are |
| 6143 |
grouped by directory if C<#[SECT]> contains C<$directory>). Lines beginning |
| 6144 |
with C<#[BODY]> and lines not beginning with C<#> are output for each |
| 6145 |
processed file. Lines beginning with C<#[IF]> are not output, but all BODY |
| 6146 |
lines are skipped if any tag on an IF line doesn't exist. Other lines |
| 6147 |
beginning with C<#> are ignored. (To output a line beginning with C<#>, use |
| 6148 |
C<#[BODY]#>.) For example, this format file: |
| 6149 |
|
| 6150 |
# this is a comment line |
| 6151 |
#[HEAD]-- Generated by ExifTool $exifToolVersion -- |
| 6152 |
File: $FileName - $DateTimeOriginal |
| 6153 |
(f/$Aperture, ${ShutterSpeed}s, ISO $EXIF:ISO) |
| 6154 |
#[TAIL]-- end -- |
| 6155 |
|
| 6156 |
with this command: |
| 6157 |
|
| 6158 |
exiftool -p test.fmt a.jpg b.jpg |
| 6159 |
|
| 6160 |
produces output like this: |
| 6161 |
|
| 6162 |
-- Generated by ExifTool 13.55 -- |
| 6163 |
File: a.jpg - 2003:10:31 15:44:19 |
| 6164 |
(f/5.6, 1/60s, ISO 100) |
| 6165 |
File: b.jpg - 2006:05:23 11:57:38 |
| 6166 |
(f/8.0, 1/13s, ISO 100) |
| 6167 |
-- end -- |
| 6168 |
|
| 6169 |
The values of List-type tags with multiple items, Shortcut tags representing |
| 6170 |
multiple tags, and matching tags when the C<All> group is specified are |
| 6171 |
joined according the B<-sep> option setting when interpolated in the string. |
| 6172 |
(Note that when C<All> is used as a group name, dupicate tags are included |
| 6173 |
regardless of the Duplicates option setting.) When C<All> is used as a tag |
| 6174 |
name, a value of 1 is returned if any tag exists in the specified group, or |
| 6175 |
0 otherwise (unless the C<All> group is also specified, in which case the |
| 6176 |
values of all matching tags are joined). |
| 6177 |
|
| 6178 |
The B<-p> output iterates through the family 3 group names, with each |
| 6179 |
sub-document producing additional output when combined with the B<-ee> |
| 6180 |
(ExtractEmbedded) option. |
| 6181 |
|
| 6182 |
If a specified tag does not exist, a minor warning is issued and the line |
| 6183 |
with the missing tag is not printed. However, the B<-f> option may be used |
| 6184 |
to set the value of missing tags to '-' (but this may be configured via the |
| 6185 |
API MissingTagValue option), or the B<-m> option may be used to ignore minor |
| 6186 |
warnings and leave the missing values empty. Alternatively, B<-q -q> may be |
| 6187 |
used to simply suppress the warning messages. |
| 6188 |
|
| 6189 |
The L</Advanced formatting feature> may be used to modify the values of |
| 6190 |
individual tags within the B<-p> option string. |
| 6191 |
|
| 6192 |
Note that the API RequestTags option is automatically set for all tags used |
| 6193 |
in the I<FMTFILE> or I<STR>. This allows all other tags to be ignored using |
| 6194 |
B<-API IgnoreTags=all>, resulting in reduced memory usage and increased |
| 6195 |
speed. |
| 6196 |
|
| 6197 |
=item B<-php> |
| 6198 |
|
| 6199 |
Format output as a PHP Array. The B<-g>, B<-G>, B<-D>, B<-H>, B<-l>, |
| 6200 |
B<-sep> and B<-struct> options combine with B<-php>, and duplicate tags are |
| 6201 |
handled in the same way as with the B<-json> option. As well, the B<-b> |
| 6202 |
option may be added to output binary data, and B<-t> may be added to include |
| 6203 |
tag table information (see B<-t> for details). Here is a simple example |
| 6204 |
showing how this could be used in a PHP script: |
| 6205 |
|
| 6206 |
<?php |
| 6207 |
eval('$array=' . `exiftool -php -q image.jpg`); |
| 6208 |
print_r($array); |
| 6209 |
?> |
| 6210 |
|
| 6211 |
=item B<-plot> |
| 6212 |
|
| 6213 |
Write output for all specified tags and all input files as a single |
| 6214 |
SVG-formatted plot. When combined with this feature, the B<-w> option |
| 6215 |
argument is a complete file name with no format codes and the append feature |
| 6216 |
may not be used. Each tag specified on the command line represents a |
| 6217 |
dataset in the plot (or more for array values or if the Split plot setting |
| 6218 |
is used). Non-numerical values are ignored. Each input file may contribute |
| 6219 |
multiple points to a dataset if it contains sub-documents and the B<-ee> |
| 6220 |
option is used, or if the tag value is a delimited string of numbers (valid |
| 6221 |
delimiters are: space, comma, semicolon, tab and newline). Line, Scatter |
| 6222 |
and Histogram plot types are available. See the API Plot Option and |
| 6223 |
L<https://exiftool.org/plot.html> for more details and information about the |
| 6224 |
plot settings. |
| 6225 |
|
| 6226 |
=item B<-s>[I<NUM>] (B<-short>) |
| 6227 |
|
| 6228 |
Short output format. Prints tag names instead of descriptions. Add I<NUM> |
| 6229 |
or up to 3 B<-s> options for even shorter formats: |
| 6230 |
|
| 6231 |
-s1 or -s - print tag names instead of descriptions |
| 6232 |
-s2 or -s -s - no extra spaces to column-align values |
| 6233 |
-s3 or -s -s -s - print values only (no tag names) |
| 6234 |
|
| 6235 |
Also effective when combined with B<-t>, B<-h>, B<-X> or B<-listx> options. |
| 6236 |
|
| 6237 |
=item B<-S> (B<-veryShort>) |
| 6238 |
|
| 6239 |
Very short format. The same as B<-s2> or two B<-s> options. Tag names are |
| 6240 |
printed instead of descriptions, and no extra spaces are added to |
| 6241 |
column-align values. |
| 6242 |
|
| 6243 |
=item B<-sep> I<STR> (B<-separator>) |
| 6244 |
|
| 6245 |
Specify separator string for items in list-type tags. When reading, the |
| 6246 |
default is to join list items with ", ". When writing, this option causes |
| 6247 |
values assigned to list-type tags to be split into individual items at each |
| 6248 |
substring matching I<STR> (otherwise they are not split by default). Space |
| 6249 |
characters in I<STR> match zero or more whitespace characters in the value. |
| 6250 |
|
| 6251 |
Note that an empty separator ("") is allowed, and will join items with no |
| 6252 |
separator when reading, or split the value into individual characters when |
| 6253 |
writing. |
| 6254 |
|
| 6255 |
For pure binary output (B<-b> used without B<-j>, B<-php> or B<-X>), the |
| 6256 |
first B<-sep> option specifies a list-item separator, and a second B<-sep> |
| 6257 |
option specifies a terminator for the end of the list (or after each value |
| 6258 |
if not a list). In these strings, C<\n>, C<\r> and C<\t> may be used to |
| 6259 |
represent a newline, carriage return and tab respectively. By default, |
| 6260 |
binary list items are separated by a newline, and no terminator is added. |
| 6261 |
|
| 6262 |
=item B<-sort>, B<--sort> |
| 6263 |
|
| 6264 |
Sort output by tag description, or by tag name if the B<-s> option is used. |
| 6265 |
When sorting by description, the sort order will depend on the B<-lang> |
| 6266 |
option setting. Without the B<-sort> option, tags appear in the order they |
| 6267 |
were specified on the command line, or if not specified, the order they were |
| 6268 |
extracted from the file. By default, tags are organized by groups when |
| 6269 |
combined with the B<-g> or B<-G> option, but this grouping may be disabled |
| 6270 |
with B<--sort>. |
| 6271 |
|
| 6272 |
=item B<-struct>, B<--struct> |
| 6273 |
|
| 6274 |
Output structured XMP information instead of flattening to individual tags. |
| 6275 |
This option works well when combined with the XML (B<-X>) and JSON (B<-j>) |
| 6276 |
output formats. For other output formats, XMP structures and lists are |
| 6277 |
serialized into the same format as when writing structured information (see |
| 6278 |
L<https://exiftool.org/struct.html> for details). When copying, structured |
| 6279 |
tags are copied by default unless B<--struct> is used to disable this |
| 6280 |
feature (although flattened tags may still be copied by specifying them |
| 6281 |
individually unless B<-struct> is used). These options have no effect when |
| 6282 |
assigning new values since both flattened and structured tags may always be |
| 6283 |
used when writing. |
| 6284 |
|
| 6285 |
=item B<-t> (B<-tab>) |
| 6286 |
|
| 6287 |
Output a tab-delimited list of description/values (useful for database |
| 6288 |
import). May be combined with B<-s> to print tag names instead of |
| 6289 |
descriptions, or B<-S> to print tag values only, tab-delimited on a single |
| 6290 |
line. The B<-t> option may be combined with B<-j>, B<-php> or B<-X> to add |
| 6291 |
tag table information (C<table>, tag C<id>, and C<index> for cases where |
| 6292 |
multiple conditional tags exist with the same ID), which allows the |
| 6293 |
corresponding tag to be located in the B<-listx> output. |
| 6294 |
|
| 6295 |
=item B<-T> (B<-table>) |
| 6296 |
|
| 6297 |
Output tag values in table form. Equivalent to B<-t -S -q -f>. |
| 6298 |
|
| 6299 |
=item B<-v>[I<NUM>] (B<-verbose>) |
| 6300 |
|
| 6301 |
Print verbose messages. I<NUM> specifies the level of verbosity in the |
| 6302 |
range 0-5, with higher numbers being more verbose. If I<NUM> is not given, |
| 6303 |
then each B<-v> option increases the level of verbosity by 1. With any |
| 6304 |
level greater than 0, most other options are ignored and normal console |
| 6305 |
output is suppressed unless specific tags are extracted. Using B<-v0> |
| 6306 |
causes the console output buffer to be flushed after each line (which may be |
| 6307 |
useful to avoid delays when piping exiftool output), and prints the name of |
| 6308 |
each processed file when writing and the new file name when renaming, |
| 6309 |
moving or copying. Verbose levels above B<-v0> do not flush after each |
| 6310 |
line. Also see the B<-progress> option. |
| 6311 |
|
| 6312 |
=item B<-w>[+][!] I<EXT> or I<FMT> (B<-textOut>) |
| 6313 |
|
| 6314 |
Write console output to files with names ending in I<EXT>, one for each |
| 6315 |
source file. The output file name is obtained by replacing the source file |
| 6316 |
extension (including the '.') with the specified extension (and a '.' is |
| 6317 |
added to the start of I<EXT> if it doesn't already contain one). |
| 6318 |
Alternatively, a I<FMT> string may be used to give more control over the |
| 6319 |
output file name and directory. In the format string, %d, %f and %e |
| 6320 |
represent the directory, filename and extension of the source file, and %c |
| 6321 |
represents a copy number which is automatically incremented if the file |
| 6322 |
already exists. %d includes the trailing '/' if necessary, but %e does not |
| 6323 |
include the leading '.'. For example: |
| 6324 |
|
| 6325 |
-w %d%f.txt # same effect as "-w txt" |
| 6326 |
-w dir/%f_%e.out # write files to "dir" as "FILE_EXT.out" |
| 6327 |
-w dir2/%d%f.txt # write to "dir2", keeping dir structure |
| 6328 |
-w a%c.txt # write to "a.txt" or "a1.txt" or "a2.txt"... |
| 6329 |
|
| 6330 |
Existing files will not be changed unless an exclamation point is added to |
| 6331 |
the option name (ie. B<-w!> or B<-textOut!>) to overwrite the file, or a |
| 6332 |
plus sign (ie. B<-w+> or B<-textOut+>) to append to the existing file. Both |
| 6333 |
may be used (ie. B<-w+!> or B<-textOut+!>) to overwrite output files that |
| 6334 |
didn't exist before the command was run, and append the output from multiple |
| 6335 |
source files. For example, to write one output file for all source files in |
| 6336 |
each directory: |
| 6337 |
|
| 6338 |
exiftool -filename -createdate -T -w+! %d/out.txt -r DIR |
| 6339 |
|
| 6340 |
Capitalized format codes %D, %F, %E and %C provide slightly different |
| 6341 |
alternatives to the lower case versions. %D does not include the trailing |
| 6342 |
'/', %F is the full filename including extension, %E includes the leading |
| 6343 |
'.', and %C increments the count for each processed file (see below). |
| 6344 |
|
| 6345 |
Notes: |
| 6346 |
|
| 6347 |
1) In a Windows BAT file the C<%> character is represented by C<%%>, so an |
| 6348 |
argument like C<%d%f.txt> is written as C<%%d%%f.txt>. |
| 6349 |
|
| 6350 |
2) If the argument for B<-w> does not contain a valid format code (eg. %f), |
| 6351 |
then it is interpreted as a file extension, but there are three different |
| 6352 |
ways to create a single output file from multiple source files: |
| 6353 |
|
| 6354 |
# 1. Shell redirection |
| 6355 |
exiftool FILE1 FILE2 ... > out.txt |
| 6356 |
|
| 6357 |
# 2. With the -w option and a zero-width format code |
| 6358 |
exiftool -w+! %0fout.txt FILE1 FILE2 ... |
| 6359 |
|
| 6360 |
# 3. With the -W option (see the -W option below) |
| 6361 |
exiftool -W+! out.txt FILE1 FILE2 ... |
| 6362 |
|
| 6363 |
3) The B<-w> option changes when used with a multi-file output format |
| 6364 |
(B<-csv> or B<-plot>). With these, the argument of B<-w> is a complete file |
| 6365 |
name with no formatting codes, and the append feature may not be used. |
| 6366 |
|
| 6367 |
Advanced features: |
| 6368 |
|
| 6369 |
A substring of the original file name, directory or extension may be taken |
| 6370 |
by specifying a field width immediately following the '%' character. If the |
| 6371 |
width is negative, the substring is taken from the end. The substring |
| 6372 |
position (characters to ignore at the start or end of the string) may be |
| 6373 |
given by a second optional value after a decimal point. For example: |
| 6374 |
|
| 6375 |
Input File Name Format Specifier Output File Name |
| 6376 |
---------------- ---------------- ---------------- |
| 6377 |
Picture-123.jpg %7f.txt Picture.txt |
| 6378 |
Picture-123.jpg %-.4f.out Picture.out |
| 6379 |
Picture-123.jpg %7f.%-3f Picture.123 |
| 6380 |
Picture-123a.jpg Meta%-3.1f.txt Meta123.txt |
| 6381 |
|
| 6382 |
(Note that special characters may have a width of greater than one.) |
| 6383 |
|
| 6384 |
For %d and %D, the field width/position specifiers may be applied to the |
| 6385 |
directory levels instead of substring position by using a colon instead of a |
| 6386 |
decimal point in the format specifier. For example: |
| 6387 |
|
| 6388 |
Source Dir Format Result Notes |
| 6389 |
------------ ------ ---------- ------------------ |
| 6390 |
pics/2012/02 %2:d pics/2012/ take top 2 levels |
| 6391 |
pics/2012/02 %-:1d pics/2012/ up one directory level |
| 6392 |
pics/2012/02 %:1d 2012/02/ ignore top level |
| 6393 |
pics/2012/02 %1:1d 2012/ take 1 level after top |
| 6394 |
pics/2012/02 %-1:D 02 bottom level folder name |
| 6395 |
/Users/phil %:2d phil/ ignore top 2 levels |
| 6396 |
|
| 6397 |
(Note that the root directory counts as one level when an absolute path is |
| 6398 |
used as in the last example above.) |
| 6399 |
|
| 6400 |
For %c, these modifiers have a different effects. If a field width is |
| 6401 |
given, the copy number is padded with zeros to the specified width. A |
| 6402 |
leading '-' adds a dash before the copy number, and a '+' adds an underline. |
| 6403 |
By default, the copy number is omitted from the first file of a given name, |
| 6404 |
but this can be changed by adding a decimal point to the modifier. For |
| 6405 |
example: |
| 6406 |
|
| 6407 |
-w A%-cZ.txt # AZ.txt, A-1Z.txt, A-2Z.txt ... |
| 6408 |
-w B%5c.txt # B.txt, B00001.txt, B00002.txt ... |
| 6409 |
-w C%.c.txt # C0.txt, C1.txt, C2.txt ... |
| 6410 |
-w D%-.c.txt # D-0.txt, D-1.txt, D-2.txt ... |
| 6411 |
-w E%-.4c.txt # E-0000.txt, E-0001.txt, E-0002.txt ... |
| 6412 |
-w F%-.4nc.txt # F-0001.txt, F-0002.txt, F-0003.txt ... |
| 6413 |
-w G%+c.txt # G.txt, G_1.txt G_2.txt ... |
| 6414 |
-w H%-lc.txt # H.txt, H-b.txt, H-c.txt ... |
| 6415 |
-w I.%.3uc.txt # I.AAA.txt, I.AAB.txt, I.AAC.txt ... |
| 6416 |
|
| 6417 |
A special feature allows the copy number to be incremented for each |
| 6418 |
processed file by using %C (upper case) instead of %c. This allows a |
| 6419 |
sequential number to be added to output file names, even if the names are |
| 6420 |
different. For %C, a copy number of zero is not omitted as it is with %c. |
| 6421 |
A leading '-' causes the number to be reset at the start of each new |
| 6422 |
directory (in the original directory structure if the files are being |
| 6423 |
moved), and '+' has no effect. The number before the decimal place gives |
| 6424 |
the starting index, the number after the decimal place gives the field |
| 6425 |
width. To preserve synchronization with the processed file number, by |
| 6426 |
default the copy number is not incremented to avoid file name collisions, so |
| 6427 |
any existing same-named file will cause an error. However using a colon |
| 6428 |
instead of a decimal point causes the number to be incremented to avoid |
| 6429 |
collisions with existing files. |
| 6430 |
|
| 6431 |
The following examples show the output filenames when used with the |
| 6432 |
command C<exiftool rose.jpg star.jpg jet.jpg ...>: |
| 6433 |
|
| 6434 |
-w %C%f.txt # 0rose.txt, 1star.txt, 2jet.txt |
| 6435 |
-w %f-%10C.txt # rose-10.txt, star-11.txt, jet-12.txt |
| 6436 |
-w %.3C-%f.txt # 000-rose.txt, 001-star.txt, 002-jet.txt |
| 6437 |
-w %57.4C%f.txt # 0057rose.txt, 0058star.txt, 0059jet.txt |
| 6438 |
|
| 6439 |
All format codes may be modified by 'l' or 'u' to specify lower or upper |
| 6440 |
case respectively (ie. C<%le> for a lower case file extension). When used |
| 6441 |
to modify %c or %C, the numbers are changed to an alphabetical base (see |
| 6442 |
example H above). Also, %c and %C may be modified by 'n' to count using |
| 6443 |
natural numbers starting from 1, instead of 0 (see example F above). |
| 6444 |
|
| 6445 |
This same I<FMT> syntax is used with the B<-o> and B<-tagsFromFile> options, |
| 6446 |
although %c and %C are only valid for output file names. |
| 6447 |
|
| 6448 |
=item B<-W>[+|!] I<FMT> (B<-tagOut>) |
| 6449 |
|
| 6450 |
This enhanced version of the B<-w> option allows a separate output file to |
| 6451 |
be created for each extracted tag. See the B<-w> option documentation above |
| 6452 |
for details of the basic functionality. Listed here are the differences |
| 6453 |
between B<-W> and B<-w>: |
| 6454 |
|
| 6455 |
1) With B<-W>, a new output file is created for each extracted tag. |
| 6456 |
|
| 6457 |
2) B<-W> supports four additional format codes: %t, %g and %s represent the |
| 6458 |
tag name, group name, and suggested extension for the output file (based on |
| 6459 |
the format of the data), and %o represents the value of the |
| 6460 |
OriginalRawFileName or OriginalFileName tag from the input file (including |
| 6461 |
extension). The %g code may be followed by a single digit to specify the |
| 6462 |
group family number (eg. %g1), otherwise family 0 is assumed. The substring |
| 6463 |
width/position/case specifiers may be used with these format codes in |
| 6464 |
exactly the same way as with %f and %e. |
| 6465 |
|
| 6466 |
3) The argument for B<-W> is interpreted as a file name if it contains no |
| 6467 |
format codes. (For B<-w>, this would be a file extension.) This change |
| 6468 |
allows a simple file name to be specified, which, when combined with the |
| 6469 |
append feature, provides a method to write metadata from multiple source |
| 6470 |
files to a single output file without the need for shell redirection. For |
| 6471 |
example, the following pairs of commands give the same result: |
| 6472 |
|
| 6473 |
# overwriting existing text file |
| 6474 |
exiftool test.jpg > out.txt # shell redirection |
| 6475 |
exiftool test.jpg -W+! out.txt # equivalent -W option |
| 6476 |
|
| 6477 |
# append to existing text file |
| 6478 |
exiftool test.jpg >> out.txt # shell redirection |
| 6479 |
exiftool test.jpg -W+ out.txt # equivalent -W option |
| 6480 |
|
| 6481 |
4) Adding the B<-v> option to B<-W> sends a list of the tags and output file |
| 6482 |
names to the console instead of giving a verbose dump of the entire file. |
| 6483 |
(Unless appending all output to one file for each source file by using |
| 6484 |
B<-W+> with an output file I<FMT> that does not contain %t, %g, %s or %o.) |
| 6485 |
|
| 6486 |
5) Individual list items are stored in separate files when B<-W> is combined |
| 6487 |
with B<-b>, but note that for separate files to be created %c or %C must be |
| 6488 |
used in I<FMT> to give the files unique names. |
| 6489 |
|
| 6490 |
=item B<-Wext> I<EXT>, B<--Wext> I<EXT> (B<-tagOutExt>) |
| 6491 |
|
| 6492 |
This option is used to specify the type of output file(s) written by the |
| 6493 |
B<-W> option. An output file is written only if the suggested extension |
| 6494 |
matches I<EXT>. Multiple B<-Wext> options may be used to write more than |
| 6495 |
one type of file. Use B<--Wext> to write all but the specified type(s). |
| 6496 |
|
| 6497 |
=item B<-X> (B<-xmlFormat>) |
| 6498 |
|
| 6499 |
Use ExifTool-specific RDF/XML formatting for console output. Implies the |
| 6500 |
B<-a> option, so duplicate tags are extracted. The formatting options |
| 6501 |
B<-b>, B<-D>, B<-H>, B<-l>, B<-s>, B<-sep>, B<-struct> and B<-t> may be used |
| 6502 |
in combination with B<-X> to affect the output, but note that the tag ID |
| 6503 |
(B<-D>, B<-H> and B<-t>), binary data (B<-b>) and structured output |
| 6504 |
(B<-struct>) options are not effective for the short output (B<-s>). Another |
| 6505 |
restriction of B<-s> is that only one tag with a given group and name may |
| 6506 |
appear in the output. Note that the tag ID options (B<-D>, B<-H> and B<-t>) |
| 6507 |
will produce non-standard RDF/XML unless the B<-l> option is also used. |
| 6508 |
|
| 6509 |
By default, B<-X> outputs flattened tags, so B<-struct> should be added if |
| 6510 |
required to preserve XMP structures. List-type tags with multiple values |
| 6511 |
are formatted as an RDF Bag, but they are combined into a single string when |
| 6512 |
B<-s> or B<-sep> is used. Using B<-L> changes the XML encoding from "UTF-8" |
| 6513 |
to "windows-1252". Other B<-charset> settings change the encoding only if |
| 6514 |
there is a corresponding standard XML character set. The B<-b> option |
| 6515 |
causes binary data values to be written, encoded in base64 if necessary. |
| 6516 |
The B<-t> option adds tag table information to the output (see B<-t> for |
| 6517 |
details). |
| 6518 |
|
| 6519 |
Note: This output is NOT the same as XMP because it uses |
| 6520 |
dynamically-generated property names corresponding to the ExifTool tag names |
| 6521 |
with ExifTool family 1 group names as namespaces, and not the standard XMP |
| 6522 |
properties and namespaces. To write XMP instead, use the B<-o> option with |
| 6523 |
an XMP extension for the output file. |
| 6524 |
|
| 6525 |
=back |
| 6526 |
|
| 6527 |
=head3 Processing control |
| 6528 |
|
| 6529 |
=over 5 |
| 6530 |
|
| 6531 |
=item B<-a>, B<--a> (B<-duplicates>, B<--duplicates>) |
| 6532 |
|
| 6533 |
Allow (B<-a>) or suppress (B<--a>) duplicate tag names to be extracted. By |
| 6534 |
default, duplicate tags are suppressed when reading unless the B<-ee> or B<-X> |
| 6535 |
options are used or the Duplicates option is enabled in the configuration file. |
| 6536 |
When writing, this option allows multiple Warning messages to be shown. |
| 6537 |
Duplicate tags are always extracted when copying. |
| 6538 |
|
| 6539 |
=item B<-e> (B<--composite>) |
| 6540 |
|
| 6541 |
Extract existing tags only -- don't generate composite tags. |
| 6542 |
|
| 6543 |
=item B<-ee>[I<NUM>] (B<-extractEmbedded>) |
| 6544 |
|
| 6545 |
Extract information from embedded documents in EPS files, embedded EPS |
| 6546 |
information and JPEG and Jpeg2000 images in PDF files, embedded MPF images |
| 6547 |
in JPEG and MPO files, streaming metadata in AVCHD videos, and the resource |
| 6548 |
fork of Mac OS files. Implies the B<-a> option. Use B<-g3> or B<-G3> to |
| 6549 |
identify the originating document for extracted information. Embedded |
| 6550 |
documents containing sub-documents are indicated with dashes in the family 3 |
| 6551 |
group name. (eg. C<Doc2-3> is the 3rd sub-document of the 2nd embedded |
| 6552 |
document.) Note that this option may increase processing time substantially, |
| 6553 |
especially for PDF files with many embedded images or videos with streaming |
| 6554 |
metadata. |
| 6555 |
|
| 6556 |
When used with B<-ee>, the B<-p> option is evaluated for each embedded |
| 6557 |
document as if it were a separate input file. This allows, for example, |
| 6558 |
generation of GPS track logs from timed metadata in videos. See |
| 6559 |
L<https://exiftool.org/geotag.html#Inverse> for examples. |
| 6560 |
|
| 6561 |
Setting I<NUM> to 2 causes the H264 video stream in MP4 videos to be parsed |
| 6562 |
until the first Supplemental Enhancement Information (SEI) message is |
| 6563 |
decoded, or 3 to parse the entire H624 stream and decode all SEI |
| 6564 |
information. For M2TS videos, a setting of 3 causes the entire file to be |
| 6565 |
parsed in search of unlisted programs which may contain timed GPS. |
| 6566 |
|
| 6567 |
=item B<-ext>[+] I<EXT>, B<--ext> I<EXT> (B<-extension>) |
| 6568 |
|
| 6569 |
Process only files with (B<-ext>) or without (B<--ext>) a specified |
| 6570 |
extension. There may be multiple B<-ext> and B<--ext> options. A plus sign |
| 6571 |
may be added (ie. B<-ext+>) to add the specified extension to the normally |
| 6572 |
processed files. EXT may begin with a leading '.', which is ignored. Case |
| 6573 |
is not significant. C<"*"> may be used to process files with any extension |
| 6574 |
(or none at all), as in the last three examples: |
| 6575 |
|
| 6576 |
exiftool -ext JPG DIR # process only JPG files |
| 6577 |
exiftool --ext cr2 --ext dng DIR # supported files but CR2/DNG |
| 6578 |
exiftool -ext+ txt DIR # supported files plus TXT |
| 6579 |
exiftool -ext "*" DIR # process all files |
| 6580 |
exiftool -ext "*" --ext xml DIR # process all but XML files |
| 6581 |
exiftool -ext "*" --ext . DIR # all but those with no ext |
| 6582 |
|
| 6583 |
Using this option has two main advantages over specifying C<*.I<EXT>> on the |
| 6584 |
command line: 1) It applies to files in subdirectories when combined with |
| 6585 |
the B<-r> option. 2) The B<-ext> option is case-insensitive, which is |
| 6586 |
useful when processing files on case-sensitive filesystems. |
| 6587 |
|
| 6588 |
Note that all files specified on the command line will be processed |
| 6589 |
regardless of extension unless the B<-ext> option is used. |
| 6590 |
|
| 6591 |
=item B<-F>[I<OFFSET>] (B<-fixBase>) |
| 6592 |
|
| 6593 |
Fix the base for maker notes offsets. A common problem with some image |
| 6594 |
editors is that offsets in the maker notes are not adjusted properly when |
| 6595 |
the file is modified. This may cause the wrong values to be extracted for |
| 6596 |
some maker note entries when reading the edited file. This option allows an |
| 6597 |
integer I<OFFSET> to be specified for adjusting the maker notes base offset. |
| 6598 |
If no I<OFFSET> is given, ExifTool takes its best guess at the correct base. |
| 6599 |
Note that exiftool will automatically fix the offsets for images which store |
| 6600 |
original offset information (eg. newer Canon models). Offsets are fixed |
| 6601 |
permanently if B<-F> is used when writing EXIF to an image. eg) |
| 6602 |
|
| 6603 |
exiftool -F -exif:resolutionunit=inches image.jpg |
| 6604 |
|
| 6605 |
=item B<-fast>[I<NUM>] |
| 6606 |
|
| 6607 |
Increase speed of extracting information. With B<-fast> (or B<-fast1>), |
| 6608 |
ExifTool will not scan to the end of a JPEG image to check for an AFCP or |
| 6609 |
PreviewImage trailer, or past the first comment in GIF images or the |
| 6610 |
audio/video data in WAV/AVI files to search for additional metadata. These |
| 6611 |
speed benefits are small when reading images directly from disk, but can be |
| 6612 |
substantial if piping images through a network connection. Also bypasses |
| 6613 |
CRC validation when writing PNG images which can be very slow. For more |
| 6614 |
substantial speed benefits, B<-fast2> also causes exiftool to avoid |
| 6615 |
extracting any EXIF MakerNote information, and to stop processing at the |
| 6616 |
IDAT chunk of PNG images and the mdat atom of QuickTime-format files (but |
| 6617 |
note that some files may store metadata after this). B<-fast3> avoids |
| 6618 |
extracting metadata from the file, and returns only pseudo System tags, but |
| 6619 |
still reads the file header to obtain an educated guess at FileType. |
| 6620 |
B<-fast4> doesn't even read the file header, and returns only System tags |
| 6621 |
and a FileType based on the file extension. B<-fast5> also disables |
| 6622 |
generation of the Composite tags (like B<-e>). Has no effect when writing. |
| 6623 |
|
| 6624 |
Note that a separate B<-fast> setting may be used for evaluation of a B<-if> |
| 6625 |
condition, or when ordering files with the B<-fileOrder> option. See the |
| 6626 |
B<-if> and B<-fileOrder> options for details. |
| 6627 |
|
| 6628 |
=item B<-fileOrder>[I<NUM>] [-]I<TAG> |
| 6629 |
|
| 6630 |
Set file processing order according to the sorted value of the specified |
| 6631 |
I<TAG>. Without this option, files are processed in the order returned by |
| 6632 |
the system, which is commonly by file name, but this is filesystem |
| 6633 |
dependent. For example, to process files in order of date: |
| 6634 |
|
| 6635 |
exiftool -fileOrder DateTimeOriginal DIR |
| 6636 |
|
| 6637 |
Additional B<-fileOrder> options may be added for secondary sort keys. |
| 6638 |
Numbers are sorted numerically, and all other values are sorted |
| 6639 |
alphabetically. Files missing the specified tag are sorted last. The sort |
| 6640 |
order may be reversed by prefixing the tag name with a C<-> (eg. |
| 6641 |
C<-fileOrder -createdate>). Print conversion of the sorted values is |
| 6642 |
disabled with the B<-n> option, or a C<#> appended to the tag name. Other |
| 6643 |
formatting options (eg. B<-d>) have no effect on the sorted values. Note |
| 6644 |
that the B<-fileOrder> option can incur large performance penalty since it |
| 6645 |
involves an additional initial processing pass of all files, but this impact |
| 6646 |
may be reduced by specifying a I<NUM> to effectively set the B<-fast> level |
| 6647 |
for the initial pass. For example, B<-fileOrder4> may be used if I<TAG> is |
| 6648 |
a pseudo System tag. If multiple B<-fileOrder> options are used, the |
| 6649 |
extraction is done at the lowest B<-fast> level. Note that files are sorted |
| 6650 |
across directory boundaries if multiple input directories are specified. |
| 6651 |
|
| 6652 |
=item B<-i> I<DIR> (B<-ignore>) |
| 6653 |
|
| 6654 |
Ignore specified directory name. I<DIR> may be either an individual folder |
| 6655 |
name, or a full path, and is case sensitive. If a full path is specified, |
| 6656 |
it must match the Directory tag exactly to be ignored. Use multiple B<-i> |
| 6657 |
options to ignore more than one directory name. A special I<DIR> value of |
| 6658 |
C<SYMLINKS> may be specified to avoid recursing into directories which are |
| 6659 |
symbolic links when the B<-r> option is used (note this does not currently |
| 6660 |
work under Windows). As well, a value of C<HIDDEN> may be used to ignore |
| 6661 |
files with names that start with a "." (ie. hidden files on Unix systems) |
| 6662 |
when scanning a directory. |
| 6663 |
|
| 6664 |
=item B<-if>[I<NUM>] I<EXPR> |
| 6665 |
|
| 6666 |
Specify a condition to be evaluated before processing each I<FILE>. I<EXPR> |
| 6667 |
is a Perl-like logic expression containing tag names prefixed by C<$> |
| 6668 |
symbols. It is evaluated with the tags from each I<FILE> in turn, and the |
| 6669 |
file is processed only if the expression returns true. Unlike Perl variable |
| 6670 |
names, tag names are not case sensitive and may contain a hyphen. As well, |
| 6671 |
tag names may have a leading group names separated by colons, and/or a |
| 6672 |
trailing C<#> character to disable print conversion. The expression |
| 6673 |
C<$GROUP:all> evaluates to 1 if any tag exists in the specified C<GROUP>, or |
| 6674 |
0 otherwise (see note 2 below). When multiple B<-if> options are used, all |
| 6675 |
conditions must be satisfied to process the file. Returns an exit status of |
| 6676 |
2 if all files fail the condition. Below are a few examples: |
| 6677 |
|
| 6678 |
# extract shutterspeed from all Canon images in a directory |
| 6679 |
exiftool -shutterspeed -if '$make eq "Canon"' dir |
| 6680 |
|
| 6681 |
# add one hour to all images created on or after Apr. 2, 2006 |
| 6682 |
exiftool -alldates+=1 -if '$CreateDate ge "2006:04:02"' dir |
| 6683 |
|
| 6684 |
# set EXIF ISO value if possible, unless it is set already |
| 6685 |
exiftool '-exif:iso<iso' -if 'not $exif:iso' dir |
| 6686 |
|
| 6687 |
# find images containing a specific keyword (case insensitive) |
| 6688 |
exiftool -if '$keywords =~ /harvey/i' -filename dir |
| 6689 |
|
| 6690 |
Adding I<NUM> to the B<-if> option causes a separate processing pass to be |
| 6691 |
executed for evaluating I<EXPR> at a B<-fast> level given by I<NUM> (see the |
| 6692 |
B<-fast> option documentation for details). Without I<NUM>, only one |
| 6693 |
processing pass is done at the level specified by the B<-fast> option. For |
| 6694 |
example, using B<-if5> is possible if I<EXPR> uses only pseudo System tags, |
| 6695 |
and may significantly speed processing if enough files fail the condition. |
| 6696 |
|
| 6697 |
The expression has access to the current ExifTool object through C<$self>, |
| 6698 |
and the following special functions are available to allow short-circuiting |
| 6699 |
of the file processing. Both functions have a return value of 1. Case is |
| 6700 |
significant for function names. |
| 6701 |
|
| 6702 |
End() - end processing after this file |
| 6703 |
EndDir() - end processing of files in the current directory |
| 6704 |
after this file (not compatible with -fileOrder) |
| 6705 |
|
| 6706 |
Notes: |
| 6707 |
|
| 6708 |
1) The B<-n> and B<-b> options also apply to tags used in I<EXPR>. |
| 6709 |
|
| 6710 |
2) The API RequestTags option is automatically set for all tags used in the |
| 6711 |
B<-if> condition. |
| 6712 |
|
| 6713 |
3) Tags in the string are interpolated in a similar way to B<-p> before the |
| 6714 |
expression is evaluated. In this interpolation, C<$/> is converted to a |
| 6715 |
newline and C<$$> represents a single C<$> symbol. So Perl variables, if |
| 6716 |
used, require a double C<$>, and regular expressions ending in C<$/> must |
| 6717 |
use C<$$/> instead. |
| 6718 |
|
| 6719 |
4) The condition accesses only tags from the file being processed unless the |
| 6720 |
B<-fileNUM> option is used to read an alternate file and the corresponding |
| 6721 |
family 8 group name is specified for the tag. See the B<-fileNUM> option |
| 6722 |
details for more information. |
| 6723 |
|
| 6724 |
5) The B<-a> (Duplicates) option is implied when B<-if> is used without a |
| 6725 |
fast I<NUM>, and the values of duplicate tags are accessible by specifying a |
| 6726 |
group name in the expression (such as a family 4 instance number, eg. |
| 6727 |
C<$Copy1:TAG>, C<$Copy2:TAG>, etc). |
| 6728 |
|
| 6729 |
6) A special "OK" UserParam is available to test the success of the previous |
| 6730 |
command when B<-execute> was used, and may be used like any other tag in the |
| 6731 |
condition (ie. "$OK"). |
| 6732 |
|
| 6733 |
7) The values of undefined tags in the expression are affected by the B<-f> |
| 6734 |
and B<-m> options unless the API UndefTags option is also set. |
| 6735 |
|
| 6736 |
8) The condition fails if a Perl error occurs. This could happen for |
| 6737 |
instance if an undefined value (eg. a missing tag) is used improperly. |
| 6738 |
|
| 6739 |
=item B<-m> (B<-ignoreMinorErrors>) |
| 6740 |
|
| 6741 |
Ignore minor errors and warnings. This enables writing to files with minor |
| 6742 |
errors and disables some validation checks which could result in minor |
| 6743 |
warnings. Generally, minor errors/warnings indicate a problem which usually |
| 6744 |
won't result in loss of metadata if ignored. However, there are exceptions, |
| 6745 |
so ExifTool leaves it up to you to make the final decision. Minor errors |
| 6746 |
and warnings are indicated by "[minor]" at the start of the message. |
| 6747 |
Warnings which affect processing when ignored are indicated by "[Minor]" |
| 6748 |
(with a capital "M"). Note that this causes missing values in |
| 6749 |
B<-tagsFromFile>, B<-p>, B<-if> and B<-fileNUM> strings to be set to an |
| 6750 |
empty string rather than an undefined value (but this may be avoided for |
| 6751 |
B<-if> using the API UndefTags option). |
| 6752 |
|
| 6753 |
=item B<-o> I<OUTFILE> or I<FMT> (B<-out>) |
| 6754 |
|
| 6755 |
Set the output file or directory name when writing information. Without |
| 6756 |
this option, when any "real" tags are written the original file is renamed |
| 6757 |
to C<FILE_original> and output is written to I<FILE>. When writing only |
| 6758 |
FileName and/or Directory "pseudo" tags, B<-o> causes the file to be copied |
| 6759 |
instead of moved, but directories specified for either of these tags take |
| 6760 |
precedence over that specified by the B<-o> option. |
| 6761 |
|
| 6762 |
I<OUTFILE> may be C<-> to write to stdout. The output file name may also be |
| 6763 |
specified using a I<FMT> string in which %d, %f and %e represent the |
| 6764 |
directory, file name and extension of I<FILE>. Also, %c may be used to add |
| 6765 |
a copy number. See the B<-w> option for I<FMT> string examples. |
| 6766 |
|
| 6767 |
The output file is taken to be a directory name if it already exists as a |
| 6768 |
directory or if the name ends with '/'. Output directories are created if |
| 6769 |
necessary. Existing files will not be overwritten. Combining the |
| 6770 |
B<-overwrite_original> option with B<-o> causes the original source file to |
| 6771 |
be erased after the output file is successfully written. |
| 6772 |
|
| 6773 |
A special feature of this option allows the creation of certain types of |
| 6774 |
files from scratch, or with the metadata from another type of file. The |
| 6775 |
following file types may be created using this technique: |
| 6776 |
|
| 6777 |
XMP, EXIF, EXV, MIE, ICC/ICM, VRD, DR4 |
| 6778 |
|
| 6779 |
The output file type is determined by the extension of I<OUTFILE> (specified |
| 6780 |
as C<-.EXT> when writing to stdout). The output file is then created from a |
| 6781 |
combination of information in I<FILE> (as if the B<-tagsFromFile> option was |
| 6782 |
used), and tag values assigned on the command line. If no I<FILE> is |
| 6783 |
specified, the output file may be created from scratch using only tags |
| 6784 |
assigned on the command line. |
| 6785 |
|
| 6786 |
=item B<-overwrite_original> |
| 6787 |
|
| 6788 |
Overwrite the original I<FILE> (instead of preserving it by adding |
| 6789 |
C<_original> to the file name) when writing information to an image. |
| 6790 |
Caution: This option should only be used if you already have separate backup |
| 6791 |
copies of your image files. The overwrite is implemented by renaming a |
| 6792 |
temporary file to replace the original. This deletes the original file and |
| 6793 |
replaces it with the edited version in a single operation. When combined |
| 6794 |
with B<-o>, this option causes the original file to be deleted if the output |
| 6795 |
file was successfully written (ie. the file is moved instead of copied). |
| 6796 |
|
| 6797 |
=item B<-overwrite_original_in_place> |
| 6798 |
|
| 6799 |
Similar to B<-overwrite_original> except that an extra step is added to |
| 6800 |
allow the original file attributes to be preserved. For example, on a Mac |
| 6801 |
this causes the original file creation date, type, creator, label color, |
| 6802 |
icon, Finder tags, other extended attributes and hard links to the file to |
| 6803 |
be preserved (but note that the Mac OS resource fork is always preserved |
| 6804 |
unless specifically deleted with C<-rsrc:all=>). This is implemented by |
| 6805 |
opening the original file in update mode and replacing its data with a copy |
| 6806 |
of a temporary file before deleting the temporary. The extra step results |
| 6807 |
in slower performance, so the B<-overwrite_original> option should be used |
| 6808 |
instead unless necessary. |
| 6809 |
|
| 6810 |
Note that this option reverts to the behaviour of the B<-overwrite_original> |
| 6811 |
option when also writing the FileName and/or Directory tags. |
| 6812 |
|
| 6813 |
=item B<-P> (B<-preserve>) |
| 6814 |
|
| 6815 |
Preserve the filesystem modification date/time (C<FileModifyDate>) of the |
| 6816 |
original file when writing. Note that some filesystems store a creation |
| 6817 |
date (ie. C<FileCreateDate> on Windows and Mac systems) which is not |
| 6818 |
affected by this option. This creation date is preserved on Windows systems |
| 6819 |
where Win32API::File and Win32::API are available regardless of this |
| 6820 |
setting. For other systems, the B<-overwrite_original_in_place> option may |
| 6821 |
be used if necessary to preserve the creation date. The B<-P> option is |
| 6822 |
superseded by any value written to the FileModifyDate tag. |
| 6823 |
|
| 6824 |
=item B<-password> I<PASSWD> |
| 6825 |
|
| 6826 |
Specify password to allow processing of password-protected PDF documents. |
| 6827 |
If a password is required but not given, a warning is issued and the |
| 6828 |
document is not processed. This option is ignored if a password is not |
| 6829 |
required. |
| 6830 |
|
| 6831 |
=item B<-progress>[NUM][:[I<TITLE>]] |
| 6832 |
|
| 6833 |
Show the progress when processing files. Without a colon, the B<-progress> |
| 6834 |
option adds a progress count in brackets after the name of each processed |
| 6835 |
file, giving the current file number and the total number of files to be |
| 6836 |
processed. Implies the B<-v0> option, causing the names of processed files |
| 6837 |
to also be printed when writing. When combined with the B<-if> option, the |
| 6838 |
total count includes all files before the condition is applied, but files |
| 6839 |
that fail the condition will not have their names printed. If NUM is |
| 6840 |
specified, the progress is shown every NUM input files. |
| 6841 |
|
| 6842 |
If followed by a colon (ie. B<-progress:>), the console window title is set |
| 6843 |
according to the specified I<TITLE> string. If no I<TITLE> is given, a |
| 6844 |
default I<TITLE> string of "ExifTool %p%%" is assumed. In the string, %f |
| 6845 |
represents the file name, %p is the progress as a percent, %r is the |
| 6846 |
progress as a ratio, %##b is a progress bar of width "##" (where "##" is an |
| 6847 |
integer specifying the bar width in characters, or 20 characters by default |
| 6848 |
if "##" is omitted), and %% is a % character. May be combined with the |
| 6849 |
normal B<-progress> option to also show the progress count in console |
| 6850 |
messages. (Note: For this feature to function correctly on Mac/Linux, stderr |
| 6851 |
must go to the console.) |
| 6852 |
|
| 6853 |
=item B<-q> (B<-quiet>) |
| 6854 |
|
| 6855 |
Quiet processing. One B<-q> suppresses normal informational messages, and a |
| 6856 |
second B<-q> suppresses warnings as well. Error messages can not be |
| 6857 |
suppressed, although minor errors may be downgraded to warnings with the |
| 6858 |
B<-m> option, which may then be suppressed with C<-q -q>. |
| 6859 |
|
| 6860 |
=item B<-r>[.] (B<-recurse>) |
| 6861 |
|
| 6862 |
Recursively process files in subdirectories. Only meaningful if I<FILE> is |
| 6863 |
a directory name. Subdirectories with names beginning with "." are not |
| 6864 |
processed unless "." is added to the option name (ie. B<-r.> or |
| 6865 |
B<-recurse.>). By default, exiftool will also follow symbolic links to |
| 6866 |
directories if supported by the system, but this may be disabled with |
| 6867 |
C<-i SYMLINKS> (see the B<-i> option for details). Combine this with |
| 6868 |
B<-ext> options to control the types of files processed. |
| 6869 |
|
| 6870 |
=item B<-scanForXMP> |
| 6871 |
|
| 6872 |
Scan all files (even unsupported formats) for XMP information unless found |
| 6873 |
already. When combined with the B<-fast> option, only unsupported file |
| 6874 |
types are scanned. Warning: It can be time consuming to scan large files. |
| 6875 |
|
| 6876 |
=item B<-u> (B<-unknown>) |
| 6877 |
|
| 6878 |
Extract values of unknown tags. Add another B<-u> to also extract unknown |
| 6879 |
information from binary data blocks. This option applies to tags with |
| 6880 |
numerical tag ID's, and causes tag names like "Exif_0xc5d9" to be generated |
| 6881 |
for unknown information. It has no effect on information types which have |
| 6882 |
human-readable tag ID's (such as XMP), since unknown tags are extracted |
| 6883 |
automatically from these formats. |
| 6884 |
|
| 6885 |
=item B<-U> (B<-unknown2>) |
| 6886 |
|
| 6887 |
Extract values of unknown tags as well as unknown information from some |
| 6888 |
binary data blocks. This is the same as two B<-u> options. |
| 6889 |
|
| 6890 |
=item B<-wm> I<MODE> (B<-writeMode>) |
| 6891 |
|
| 6892 |
Set mode for writing/creating tags. I<MODE> is a string of one or more |
| 6893 |
characters from the list below. The default write mode is C<wcg>. |
| 6894 |
|
| 6895 |
w - Write existing tags |
| 6896 |
c - Create new tags |
| 6897 |
g - create new Groups as necessary |
| 6898 |
|
| 6899 |
For example, use C<-wm cg> to only create new tags (and avoid editing |
| 6900 |
existing ones). |
| 6901 |
|
| 6902 |
The level of the group is the SubDirectory level in the metadata structure. |
| 6903 |
For XMP or IPTC this is the full XMP/IPTC block (the family 0 group), but |
| 6904 |
for EXIF this is the individual IFD (the family 1 group). |
| 6905 |
|
| 6906 |
=item B<-z> (B<-zip>) |
| 6907 |
|
| 6908 |
When reading, causes information to be extracted from .gz and .bz2 |
| 6909 |
compressed images (only one image per archive; requires gzip and bzip2 to be |
| 6910 |
available). When writing, causes compressed information to be written if |
| 6911 |
supported by the metadata format (eg. PNG supports compressed textual |
| 6912 |
metadata, JXL supports compressed EXIF and XML, and MIE supports any |
| 6913 |
compressed metadata), disables the recommended padding in embedded XMP |
| 6914 |
(saving 2424 bytes when writing XMP in a file), and writes XMP in shorthand |
| 6915 |
format -- the equivalent of setting the API Compress=1 and |
| 6916 |
Compact="NoPadding,Shorthand". |
| 6917 |
|
| 6918 |
=back |
| 6919 |
|
| 6920 |
=head3 Other options |
| 6921 |
|
| 6922 |
=over 5 |
| 6923 |
|
| 6924 |
=item B<-@> I<ARGFILE> |
| 6925 |
|
| 6926 |
Read command-line arguments from the specified file. The file contains one |
| 6927 |
argument per line (NOT one option per line -- some options require |
| 6928 |
additional arguments, and all arguments must be placed on separate lines). |
| 6929 |
Blank lines and lines beginning with C<#> are ignored (unless they start |
| 6930 |
with C<#[CSTR]>, in which case the rest of the line is treated as a C |
| 6931 |
string, allowing standard C escape sequences such as "\n" for a newline). |
| 6932 |
White space at the start of a line is removed. Normal shell processing of |
| 6933 |
arguments is not performed, which among other things means that arguments |
| 6934 |
should not be quoted and spaces are treated as any other character. |
| 6935 |
I<ARGFILE> may exist relative to either the current directory or the |
| 6936 |
exiftool directory unless an absolute pathname is given. |
| 6937 |
|
| 6938 |
For example, the following I<ARGFILE> will set the value of Copyright to |
| 6939 |
"Copyright YYYY, Phil Harvey", where "YYYY" is the year of CreateDate: |
| 6940 |
|
| 6941 |
-d |
| 6942 |
%Y |
| 6943 |
-copyright<Copyright $createdate, Phil Harvey |
| 6944 |
|
| 6945 |
Arguments in I<ARGFILE> behave exactly the same as if they were entered at |
| 6946 |
the location of the B<-@> option on the command line, with the exception |
| 6947 |
that the B<-config> and B<-common_args> options may not be used in an |
| 6948 |
I<ARGFILE>. |
| 6949 |
|
| 6950 |
=item B<-k> (B<-pause>) |
| 6951 |
|
| 6952 |
Pause with the message C<-- press any key --> or C<-- press RETURN --> |
| 6953 |
(depending on your system) before terminating. This option is used to |
| 6954 |
prevent the command window from closing when run as a Windows drag and drop |
| 6955 |
application. |
| 6956 |
|
| 6957 |
=item B<-list>, B<-listw>, B<-listf>, B<-listr>, B<-listwf>, |
| 6958 |
B<-listg>[I<NUM>], B<-listd>, B<-listx>, B<-listgeo> |
| 6959 |
|
| 6960 |
Print a list of all valid tag names (B<-list>), all writable tag names |
| 6961 |
(B<-listw>), all supported file extensions (B<-listf>), all recognized file |
| 6962 |
extensions (B<-listr>), all writable file extensions (B<-listwf>), all tag |
| 6963 |
groups [in a specified family] (B<-listg>[I<NUM>]), all deletable tag groups |
| 6964 |
(B<-listd>), an XML database of tag details including language translations |
| 6965 |
(B<-listx>), or the Geolocation database (B<-listgeo>). The B<-list>, |
| 6966 |
B<-listw> and B<-listx> options may be followed by an additional argument of |
| 6967 |
the form C<-GROUP:All> to list only tags in a specific group, where C<GROUP> |
| 6968 |
is one or more family 0-2 group names (excepting EXIF IFD groups) separated |
| 6969 |
by colons. With B<-listg>, I<NUM> may be given to specify the group family, |
| 6970 |
otherwise family 0 is assumed. The B<-l> or B<-v> option may be combined |
| 6971 |
with B<-listf>, B<-listr> or B<-listwf> to add file descriptions to the |
| 6972 |
list. The B<-lang> option may be combined with B<-listx> to output |
| 6973 |
descriptions in a single language, and the B<-sort> and/or B<-lang> options |
| 6974 |
may be combined with B<-listgeo> (installation of the alternate database is |
| 6975 |
required for the additional languages). Also, the API GeolocMinPop, |
| 6976 |
GeolocFeature and GeolocAltNames options apply to the B<-listgeo> output. |
| 6977 |
Here are some examples: |
| 6978 |
|
| 6979 |
-list # list all tag names |
| 6980 |
-list -EXIF:All # list all EXIF tags |
| 6981 |
-list -xmp:time:all # list all XMP tags relating to time |
| 6982 |
-listw -XMP-dc:All # list all writable XMP-dc tags |
| 6983 |
-listf # list all supported file extensions |
| 6984 |
-listr # list all recognized file extensions |
| 6985 |
-listwf # list all writable file extensions |
| 6986 |
-listg1 # list all groups in family 1 |
| 6987 |
-listd # list all deletable groups |
| 6988 |
-listx -EXIF:All # list database of EXIF tags in XML format |
| 6989 |
-listx -XMP:All -s # list short XML database of XMP tags |
| 6990 |
-listgeo -lang de # list geolocation database in German |
| 6991 |
|
| 6992 |
When combined with B<-listx>, the B<-s> option shortens the output by |
| 6993 |
omitting the descriptions and values (as in the last example above), and |
| 6994 |
B<-f> adds 'flags' and 'struct' attributes if applicable. The flags are |
| 6995 |
formatted as a comma-separated list of the following possible values: |
| 6996 |
Avoid, Binary, List, Mandatory, Permanent, Protected, Unknown and Unsafe |
| 6997 |
(see the L<Tag Name documentation|Image::ExifTool::TagNames>). For XMP List |
| 6998 |
tags, the list type (Alt, Bag or Seq) is also given, and flattened structure |
| 6999 |
tags are indicated by a Flattened flag with 'struct' giving the ID of the |
| 7000 |
parent structure. |
| 7001 |
|
| 7002 |
Note that none of the B<-list> options require an input I<FILE>. |
| 7003 |
|
| 7004 |
=item B<-ver> |
| 7005 |
|
| 7006 |
Print exiftool version number. The B<-v> option may be added to print |
| 7007 |
addition system information (see the README file of the full distribution |
| 7008 |
for more details about optional libraries), or B<-v2> to also list the Perl |
| 7009 |
include directories. |
| 7010 |
|
| 7011 |
=item B<--> |
| 7012 |
|
| 7013 |
Indicates the end of options. Any remaining arguments are treated as file |
| 7014 |
names, even if they begin with a dash (C<->). |
| 7015 |
|
| 7016 |
=back |
| 7017 |
|
| 7018 |
=head3 Special features |
| 7019 |
|
| 7020 |
=over 5 |
| 7021 |
|
| 7022 |
=item B<-diff> I<FILE2> |
| 7023 |
|
| 7024 |
Compare metadata in I<FILE> with I<FILE2>. The I<FILE2> name may include |
| 7025 |
filename formatting codes (see the B<-w> option). All extracted tags from |
| 7026 |
the files are compared, but the extracted tags may be controlled by adding |
| 7027 |
B<->I<TAG> or B<-->I<TAG> options. For example, below is a command to |
| 7028 |
compare all the same-named files in two different directories, ignoring the |
| 7029 |
System tags: |
| 7030 |
|
| 7031 |
exiftool DIR1 -diff DIR2/%f.%e --system:all |
| 7032 |
|
| 7033 |
The B<-g> and B<-G> options may be used to organize the output by the |
| 7034 |
specified family of groups, with B<-G1> being the default. The B<-a> option |
| 7035 |
is implied. Adding B<-v> includes a count of the number of tags that are |
| 7036 |
the same in each group, and B<-v2> also indicates when zero tags were the |
| 7037 |
same. The following text formatting options are valid when B<-diff> is |
| 7038 |
used: B<-c>, B<-charset>, B<-d>, B<-E>, B<-ec>, B<-ex>, B<-L>, B<-lang>, |
| 7039 |
B<-n>, B<-s>, B<-sep>, B<-struct> and B<-w>. |
| 7040 |
|
| 7041 |
=item B<-geotag> I<TRKFILE> |
| 7042 |
|
| 7043 |
Geotag images from the specified GPS track log file. Using the B<-geotag> |
| 7044 |
option is equivalent to writing a value to the C<Geotag> tag. The GPS |
| 7045 |
position is interpolated from the track at a time specified by the value |
| 7046 |
written to the C<Geotime> tag. If C<Geotime> is not specified, the value is |
| 7047 |
copied from C<SubSecDateTimeOriginal#> if it exists, otherwise |
| 7048 |
C<DateTimeOriginal#> (the C<#> is added to copy the unformatted value, |
| 7049 |
avoiding potential conflicts with the B<-d> option). For example, the |
| 7050 |
following two commands are equivalent if SubSecDateTimeOriginal exists in |
| 7051 |
the file: |
| 7052 |
|
| 7053 |
exiftool -geotag trk.log image.jpg |
| 7054 |
exiftool -geotag trk.log "-Geotime<SubSecDateTimeOriginal#" image.jpg |
| 7055 |
|
| 7056 |
If the C<Geotime> value does not contain a time zone then the local system |
| 7057 |
timezone is assumed. Writing C<Geotime> causes the following tags to be |
| 7058 |
written (provided they can be calculated from the track log, and they are |
| 7059 |
supported by the destination metadata format): GPSLatitude, GPSLatitudeRef, |
| 7060 |
GPSLongitude, GPSLongitudeRef, GPSAltitude, GPSAltitudeRef, GPSDateStamp, |
| 7061 |
GPSTimeStamp, GPSDateTime, GPSTrack, GPSTrackRef, GPSSpeed, GPSSpeedRef, |
| 7062 |
GPSImgDirection, GPSImgDirectionRef, GPSMeasureMode, GPSDOP, GPSPitch, |
| 7063 |
GPSRoll, GPSCoordinates, AmbientTemperature and CameraElevationAngle. By |
| 7064 |
default, in image files tags are created in EXIF, and updated in XMP only if |
| 7065 |
they already exist. In QuickTime-format files GPSCoordinates is created in |
| 7066 |
the preferred location (ItemList by default) as well as in XMP. However, |
| 7067 |
C<EXIF:Geotime>, C<XMP:Geotime> or C<QuickTime:Geotime> may be specified to |
| 7068 |
write to write only to one group. Also, C<ItemList:Geotime>, C<Keys:Geotime> |
| 7069 |
or C<UserData:Geotime> may be used to write to a specific location in |
| 7070 |
QuickTime-format files. Note that GPSPitch and GPSRoll are non-standard, |
| 7071 |
and require user-defined tags in order to be written. |
| 7072 |
|
| 7073 |
The C<Geosync> tag may be used to specify a time correction which is applied |
| 7074 |
to each C<Geotime> value for synchronization with GPS time. For example, |
| 7075 |
the following command compensates for image times which are 1 minute and 20 |
| 7076 |
seconds behind GPS: |
| 7077 |
|
| 7078 |
exiftool -geosync=+1:20 -geotag a.log DIR |
| 7079 |
|
| 7080 |
Advanced C<Geosync> features allow a piecewise linear time drift correction |
| 7081 |
and synchronization from previously geotagged images. See "geotag.html" in |
| 7082 |
the full ExifTool distribution for more information. |
| 7083 |
|
| 7084 |
Multiple B<-geotag> options may be used to concatenate GPS track log data. |
| 7085 |
Also, a single B<-geotag> option may be used to load multiple track log |
| 7086 |
files by using wildcards in the I<TRKFILE> name, but note that in this case |
| 7087 |
I<TRKFILE> must be quoted on most systems (with the notable exception of |
| 7088 |
Windows) to prevent filename expansion. For example: |
| 7089 |
|
| 7090 |
exiftool -geotag "TRACKDIR/*.log" IMAGEDIR |
| 7091 |
|
| 7092 |
Currently supported track file formats are GPX, NMEA RMC/GGA/GLL, KML, IGC, |
| 7093 |
Garmin XML and TCX, Magellan PMGNTRK, Honeywell PTNTHPR, Bramor gEO, Winplus |
| 7094 |
Beacon TXT, and GPS/IMU CSV files. See L</GEOTAGGING EXAMPLES> for |
| 7095 |
examples. Also see "geotag.html" in the full ExifTool distribution and the |
| 7096 |
L<Image::ExifTool Options|Image::ExifTool/Options> for more details and for |
| 7097 |
information about geotag configuration options. |
| 7098 |
|
| 7099 |
The API Geolocation option may be set to the value "geotag" to also write |
| 7100 |
the name, province/state and country of the nearest city while geotagging. |
| 7101 |
See L<https://exiftool.org/geolocation.html> for details. |
| 7102 |
|
| 7103 |
=item B<-globalTimeShift> I<SHIFT> |
| 7104 |
|
| 7105 |
Shift all formatted date/time values by the specified amount when reading. |
| 7106 |
Does not apply to unformatted (B<-n>) output. I<SHIFT> takes the same form |
| 7107 |
as the date/time shift when writing (see |
| 7108 |
L<Image::ExifTool::Shift.pl|Image::ExifTool::Shift.pl> for details), with a |
| 7109 |
negative shift being indicated with a minus sign (C<->) at the start of the |
| 7110 |
I<SHIFT> string. For example: |
| 7111 |
|
| 7112 |
# return all date/times, shifted back by 1 hour |
| 7113 |
exiftool -globalTimeShift -1 -time:all a.jpg |
| 7114 |
|
| 7115 |
# set the file name from the shifted CreateDate (-1 day) for |
| 7116 |
# all images in a directory |
| 7117 |
exiftool "-filename<createdate" -globaltimeshift "-0:0:1 0:0:0" \ |
| 7118 |
-d %Y%m%d-%H%M%S.%%e dir |
| 7119 |
|
| 7120 |
=item B<-use> I<MODULE> |
| 7121 |
|
| 7122 |
Add features from specified plug-in I<MODULE>. Currently, the MWG module is |
| 7123 |
the only plug-in module distributed with exiftool. This module adds |
| 7124 |
read/write support for tags as recommended by the Metadata Working Group. As |
| 7125 |
a convenience, C<-use MWG> is assumed if the group name prefix starts with |
| 7126 |
C<MWG:> exactly for any requested tag. See the |
| 7127 |
L<MWG Tags documentation|Image::ExifTool::TagNames/MWG Tags> for more |
| 7128 |
details. Note that this option is not reversible, and remains in effect |
| 7129 |
until the application terminates, even across the B<-execute> option. |
| 7130 |
|
| 7131 |
=back |
| 7132 |
|
| 7133 |
=head3 Utilities |
| 7134 |
|
| 7135 |
=over 5 |
| 7136 |
|
| 7137 |
=item B<-restore_original> |
| 7138 |
|
| 7139 |
=item B<-delete_original>[!] |
| 7140 |
|
| 7141 |
These utility options automate the maintenance of the C<_original> files |
| 7142 |
created by exiftool. They have no effect on files without an C<_original> |
| 7143 |
copy. The B<-restore_original> option restores the specified files from |
| 7144 |
their original copies by renaming the C<_original> files to replace the |
| 7145 |
edited versions. For example, the following command restores the originals |
| 7146 |
of all JPG images in directory C<DIR>: |
| 7147 |
|
| 7148 |
exiftool -restore_original -ext jpg DIR |
| 7149 |
|
| 7150 |
The B<-delete_original> option deletes the C<_original> copies of all files |
| 7151 |
specified on the command line. Without a trailing C<!> this option prompts |
| 7152 |
for confirmation before continuing. For example, the following command |
| 7153 |
deletes C<a.jpg_original> if it exists, after asking "Are you sure?": |
| 7154 |
|
| 7155 |
exiftool -delete_original a.jpg |
| 7156 |
|
| 7157 |
These options may not be used with other options to read or write tag values |
| 7158 |
in the same command, but may be combined with options such B<-ext>, B<-if>, |
| 7159 |
B<-r>, B<-q> and B<-v>. |
| 7160 |
|
| 7161 |
=back |
| 7162 |
|
| 7163 |
=head3 Advanced options |
| 7164 |
|
| 7165 |
Among other things, the advanced options allow complex processing to be |
| 7166 |
performed from a single command without the need for additional scripting. |
| 7167 |
This may be particularly useful for implementations such as Windows |
| 7168 |
drag-and-drop applications. These options may also be used to improve |
| 7169 |
performance in multi-pass processing by reducing the overhead required to |
| 7170 |
load exiftool for each invocation. |
| 7171 |
|
| 7172 |
=over 5 |
| 7173 |
|
| 7174 |
=item B<-api> [I<OPT[[^]=[VAL]]>] |
| 7175 |
|
| 7176 |
Set ExifTool API option. I<OPT> is an API option name. The option value is |
| 7177 |
set to 1 if I<=VAL> is omitted. If just I<VAL> is omitted, the option value |
| 7178 |
is set to undef if C<=> is used, or an empty string with C<^=>. If I<OPT> |
| 7179 |
is not specified a list of available options is returned. The option name |
| 7180 |
is not case sensitive, but the option values are. See |
| 7181 |
L<Image::ExifTool Options|Image::ExifTool/Options> for option details. This |
| 7182 |
overrides API options set via the config file. Note that the exiftool app |
| 7183 |
sets some API options internally, and attempts to change these via the |
| 7184 |
command line will have no effect. |
| 7185 |
|
| 7186 |
=item B<-common_args> |
| 7187 |
|
| 7188 |
Specifies that all arguments following this option are common to all |
| 7189 |
executed commands when B<-execute> is used. This and the B<-config> option |
| 7190 |
are the only options that may not be used inside a B<-@> I<ARGFILE>. Note |
| 7191 |
that by definition this option and its arguments MUST come after all other |
| 7192 |
options on the command line. |
| 7193 |
|
| 7194 |
=item B<-config> I<CFGFILE> |
| 7195 |
|
| 7196 |
Load specified configuration file instead of the default ".ExifTool_config". |
| 7197 |
If used, this option must come before all other arguments on the command |
| 7198 |
line and applies to all B<-execute>'d commands. This file is used to create |
| 7199 |
user-defined tags as well as set default ExifTool options. The I<CFGFILE> |
| 7200 |
must exist relative to the current working directory or the exiftool |
| 7201 |
application directory unless an absolute path is specified. Loading of the |
| 7202 |
default config file may be disabled by setting I<CFGFILE> to an empty string |
| 7203 |
(ie. ""). See L<https://exiftool.org/config.html> and |
| 7204 |
config_files/example.config in the full ExifTool distribution for details |
| 7205 |
about the configuration file syntax. |
| 7206 |
|
| 7207 |
=item B<-echo>[I<NUM>] I<TEXT> |
| 7208 |
|
| 7209 |
Echo I<TEXT> to stdout (B<-echo> or B<-echo1>) or stderr (B<-echo2>). Text |
| 7210 |
is output as the command line is parsed, before the processing of any input |
| 7211 |
files. I<NUM> may also be 3 or 4 to output text (to stdout or stderr |
| 7212 |
respectively) after processing is complete. For B<-echo3> and B<-echo4>, |
| 7213 |
"${status}" may be used in the I<TEXT> string to represent the numerical |
| 7214 |
exit status of the command (see L</EXIT STATUS>). |
| 7215 |
|
| 7216 |
=item B<-efile>[I<NUM>][!] I<TXTFILE> |
| 7217 |
|
| 7218 |
Save the names of files giving errors (I<NUM> missing or 1), files that were |
| 7219 |
unchanged (I<NUM> is 2), files that fail the B<-if> condition (I<NUM> is 4), |
| 7220 |
files that were updated (I<NUM> is 8), files that were created (I<NUM> is |
| 7221 |
16), or any combination thereof by summing I<NUM> (eg. B<-efile3> is the |
| 7222 |
same has having both B<-efile> and B<-efile2> options with the same |
| 7223 |
I<TXTFILE>). By default, file names are appended to any existing I<TXTFILE>, |
| 7224 |
but I<TXTFILE> is overwritten if an exclamation point is added to the option |
| 7225 |
(eg. B<-efile!>). Saves the name of the file specified by the B<-srcfile> |
| 7226 |
option if applicable. |
| 7227 |
|
| 7228 |
=item B<-execute>[I<NUM>] |
| 7229 |
|
| 7230 |
Execute command for all arguments up to this point on the command line (plus |
| 7231 |
any arguments specified by B<-common_args>). The result is as if the |
| 7232 |
commands were executed as separate command lines (with the exception of the |
| 7233 |
B<-config> and B<-use> options which remain in effect for subsequent |
| 7234 |
commands). Allows multiple commands to be executed from a single command |
| 7235 |
line. I<NUM> is an optional number that is echoed in the "{ready}" message |
| 7236 |
when using the B<-stay_open> feature. If a I<NUM> is specified, the B<-q> |
| 7237 |
option no longer suppresses the output "{readyNUM}" message. |
| 7238 |
|
| 7239 |
=item B<-file>I<NUM> I<ALTFILE> |
| 7240 |
|
| 7241 |
Read tags from an alternate source file. Among other things, this allows |
| 7242 |
tags from different files to be compared and combined using the B<-if> and |
| 7243 |
B<-p> options. I<NUM> is any string of digits. Tags from alternate files |
| 7244 |
are accessed via the corresponding family 8 group name (eg. C<File1:TAG> for |
| 7245 |
the B<-file1> option, C<File2:TAG> for B<-file2>, etc). I<ALTFILE> may |
| 7246 |
contain filename formatting codes like the B<-w> option (%d, %f, etc), |
| 7247 |
and/or tag names with a leading C<$> symbol to access tags from the source |
| 7248 |
file in the same way as the B<-p> option (so any other dollar symbol in the |
| 7249 |
file name must be doubled, eg. C<money$$.jpg>). For example, assuming that |
| 7250 |
the OriginalFileName tag has been set in the edited file, a command to copy |
| 7251 |
Rights from the original file could look like this: |
| 7252 |
|
| 7253 |
exiftool -file1 '$originalfilename' '-rights<file1:rights' edited.jpg |
| 7254 |
|
| 7255 |
Subtle note: If a B<-tagsFromFile> option is used, tags in the I<ALTFILE> |
| 7256 |
argument come from the I<SRCFILE> that applies to the first argument |
| 7257 |
accessing tags from the corresponding C<FileNUM> group. |
| 7258 |
|
| 7259 |
I<ALTFILE> may also be C<@> to access tags from the specified I<FILE>, which |
| 7260 |
may be useful when the B<-srcfile> option is used to process a different |
| 7261 |
source file. |
| 7262 |
|
| 7263 |
User-defined Composite tags may access tags from alternate files using the |
| 7264 |
appropriate (case-sensitive) family 8 group name. |
| 7265 |
|
| 7266 |
The B<-fast> option, if used, also applies to processing of the alternate |
| 7267 |
files. |
| 7268 |
|
| 7269 |
=item B<-list_dir> |
| 7270 |
|
| 7271 |
List directories themselves instead of their contents. This option |
| 7272 |
effectively causes directories to be treated as normal files when reading |
| 7273 |
and writing. For example, with this option the output of the C<ls -la> |
| 7274 |
command on Mac/Linux may be approximated by this exiftool command: |
| 7275 |
|
| 7276 |
exiftool -list_dir -T -ls-l -api systemtags -fast5 .* * |
| 7277 |
|
| 7278 |
(The B<-T> option formats the output in tab-separated columns, B<-ls-l> is a |
| 7279 |
L<shortcut tag|Image::ExifTool::Shortcuts>, the API SystemTags option is |
| 7280 |
required to extract some necessary tags, and the B<-fast5> option is added |
| 7281 |
for speed since only system tags are being extracted.) |
| 7282 |
|
| 7283 |
=item B<-srcfile> I<FMT> |
| 7284 |
|
| 7285 |
Specify a different source file to be processed based on the name of the |
| 7286 |
original I<FILE>. This may be useful in some special situations for |
| 7287 |
processing related preview images or sidecar files. See the B<-w> option |
| 7288 |
for a description of the I<FMT> syntax. Note that file name I<FMT> strings |
| 7289 |
for all options are based on the original I<FILE> specified from the command |
| 7290 |
line, not the name of the source file specified by B<-srcfile>. |
| 7291 |
|
| 7292 |
For example, to copy metadata from NEF files to the corresponding JPG |
| 7293 |
previews in a directory where other JPG images may exist: |
| 7294 |
|
| 7295 |
exiftool -ext nef -tagsfromfile @ -srcfile %d%f.jpg dir |
| 7296 |
|
| 7297 |
If more than one B<-srcfile> option is specified, the files are tested in |
| 7298 |
order and the first existing source file is processed. If none of the |
| 7299 |
source files already exist, then exiftool uses the first B<-srcfile> |
| 7300 |
specified. |
| 7301 |
|
| 7302 |
A I<FMT> of C<@> may be used to represent the original I<FILE>, which may be |
| 7303 |
useful when specifying multiple B<-srcfile> options (eg. to fall back to |
| 7304 |
processing the original I<FILE> if no sidecar exists). |
| 7305 |
|
| 7306 |
When this option is used, two special UserParam tags (OriginalFileName and |
| 7307 |
OriginalDirectory) are generated to allow access to the original I<FILE> |
| 7308 |
name and directory. |
| 7309 |
|
| 7310 |
=item B<-stay_open> I<FLAG> |
| 7311 |
|
| 7312 |
If I<FLAG> is C<1> or C<True> (case insensitive), causes exiftool keep |
| 7313 |
reading from the B<-@> I<ARGFILE> even after reaching the end of file. This |
| 7314 |
feature allows calling applications to pre-load exiftool, thus avoiding the |
| 7315 |
overhead of loading exiftool for each command. The procedure is as follows: |
| 7316 |
|
| 7317 |
1) Execute C<exiftool -stay_open True -@ I<ARGFILE>>, where I<ARGFILE> is the |
| 7318 |
name of an existing (possibly empty) argument file or C<-> to pipe arguments |
| 7319 |
from the standard input. |
| 7320 |
|
| 7321 |
2) Write exiftool command-line arguments to I<ARGFILE>, one argument per |
| 7322 |
line (see the B<-@> option for details). |
| 7323 |
|
| 7324 |
3) Write C<-execute\n> to I<ARGFILE>, where C<\n> represents a newline |
| 7325 |
sequence. (Note: You may need to flush your write buffers here if using |
| 7326 |
buffered output.) ExifTool will then execute the command with the arguments |
| 7327 |
received up to this point, send a "{ready}" message to stdout when done |
| 7328 |
(unless the B<-q> or B<-T> option is used), and continue trying to read |
| 7329 |
arguments for the next command from I<ARGFILE>. To aid in command/response |
| 7330 |
synchronization, any number appended to the B<-execute> option is echoed in |
| 7331 |
the "{ready}" message. For example, C<-execute613> results in "{ready613}". |
| 7332 |
When this number is added, B<-q> no longer suppresses the "{ready}" message. |
| 7333 |
(Also, see the B<-echo3> and B<-echo4> options for additional ways to pass |
| 7334 |
signals back to your application.) |
| 7335 |
|
| 7336 |
4) Repeat steps 2 and 3 for each command. |
| 7337 |
|
| 7338 |
5) Write C<-stay_open\nFalse\n> (or C<-stay_open\n0\n>) to I<ARGFILE> when |
| 7339 |
done. This will cause exiftool to process any remaining command-line |
| 7340 |
arguments then exit normally. |
| 7341 |
|
| 7342 |
The input I<ARGFILE> may be changed at any time before step 5 above by |
| 7343 |
writing the following lines to the currently open I<ARGFILE>: |
| 7344 |
|
| 7345 |
-stay_open |
| 7346 |
True |
| 7347 |
-@ |
| 7348 |
NEWARGFILE |
| 7349 |
|
| 7350 |
This causes I<ARGFILE> to be closed, and I<NEWARGFILE> to be kept open. |
| 7351 |
(Without the B<-stay_open> here, exiftool would have returned to reading |
| 7352 |
arguments from I<ARGFILE> after reaching the end of I<NEWARGFILE>.) |
| 7353 |
|
| 7354 |
Note: When writing arguments to a disk file there is a delay of up to 0.01 |
| 7355 |
seconds after writing C<-execute\n> before exiftool starts processing the |
| 7356 |
command. This delay may be avoided by sending a CONT signal to the exiftool |
| 7357 |
process immediately after writing C<-execute\n>. (There is no associated |
| 7358 |
delay when writing arguments via a pipe with C<-@ ->, so the signal is not |
| 7359 |
necessary when using this technique.) |
| 7360 |
|
| 7361 |
=item B<-userParam> I<PARAM[[^]=[VAL]]> |
| 7362 |
|
| 7363 |
Set user parameter. I<PARAM> is an arbitrary user parameter name. This is |
| 7364 |
an interface to the API UserParam option (see the |
| 7365 |
L<Image::ExifTool Options|Image::ExifTool/Options> documentation), and |
| 7366 |
provides a method to access user-defined parameters in arguments to the |
| 7367 |
B<-if>, B<-p> and B<-fileNUM> options as if they were any other tag. |
| 7368 |
Appending a hash tag (C<#>) to I<PARAM> (eg. C<-userParam MyTag#=yes>) also |
| 7369 |
causes the parameter to be extracted as a normal tag in the UserParam group. |
| 7370 |
Similar to the B<-api> option, the parameter value is set to 1 if I<=VAL> |
| 7371 |
is omitted, undef if just I<VAL> is omitted with C<=>, or an empty string if |
| 7372 |
I<VAL> is omitted with C<^=>. |
| 7373 |
|
| 7374 |
exiftool -p '$test from $filename' -userparam test=Hello FILE |
| 7375 |
|
| 7376 |
=back |
| 7377 |
|
| 7378 |
=head3 Advanced formatting feature |
| 7379 |
|
| 7380 |
An advanced formatting feature allows modification of the value of any tag |
| 7381 |
interpolated within a B<-if>, B<-p> or B<-fileNUM> argument, or a |
| 7382 |
B<-tagsFromFile> redirection string. Tag names within these strings are |
| 7383 |
prefixed by a C<$> symbol, and an arbitrary Perl expression may be applied |
| 7384 |
to the tag value by placing braces around the tag name and inserting the |
| 7385 |
expression after the name, separated by a semicolon (ie. C<${TAG;EXPR}>). |
| 7386 |
The expression acts on the value of the tag through the default input |
| 7387 |
variable (C<$_>), and has access to the full ExifTool API through the |
| 7388 |
current ExifTool object (C<$self>) and the tag key (C<$tag>). It may |
| 7389 |
contain any valid Perl code, including translation (C<tr///>) and |
| 7390 |
substitution (C<s///>) operations, but note that braces within the |
| 7391 |
expression must be balanced. If the expression does not modify C<$_> the |
| 7392 |
original tag value is returned. The example below prints the camera Make |
| 7393 |
with spaces translated to underlines, and multiple consecutive underlines |
| 7394 |
replaced by a single underline: |
| 7395 |
|
| 7396 |
exiftool -p '${make;tr/ /_/;s/__+/_/g}' image.jpg |
| 7397 |
|
| 7398 |
An C<@> may be added after the tag name to make the expression act on |
| 7399 |
individual list items for list-type tags, simplifying list processing. Set |
| 7400 |
C<$_> to undef to remove an item from the list. As an example, the |
| 7401 |
following command returns all subjects not containing the string "xxx": |
| 7402 |
|
| 7403 |
exiftool -p '${subject@;$_=undef if /xxx/}' image.jpg |
| 7404 |
|
| 7405 |
A default expression of C<tr(/\\?*:|"E<lt>E<gt>\0)()d> is assumed if the |
| 7406 |
expression is empty (ie. C<${TAG;}>). This removes the characters / \ ? * : |
| 7407 |
| E<lt> E<gt> and null from the printed value. (These characters are |
| 7408 |
illegal in Windows file names, so this feature is useful if tag values are |
| 7409 |
used in file names.) |
| 7410 |
|
| 7411 |
Note that the expression is not evaluated for undefined (non-existant) tags, |
| 7412 |
which may have other values if either the B<-m> or B<-f> command-line option |
| 7413 |
or the API MissingTagValue option is used. |
| 7414 |
|
| 7415 |
=head4 Helper functions |
| 7416 |
|
| 7417 |
Note that function names are case sensitive. |
| 7418 |
|
| 7419 |
B<C<DateFmt>> |
| 7420 |
|
| 7421 |
Simplifies reformatting of individual date/time values. This function acts |
| 7422 |
on a standard EXIF-formatted date/time value in C<$_> and formats it |
| 7423 |
according to the specified format string (see the B<-d> option). To avoid |
| 7424 |
trying to reformat an already-formatted date/time value, a C<#> must be |
| 7425 |
added to the tag name (as in the example below) if the B<-d> option is also |
| 7426 |
used. For example: |
| 7427 |
|
| 7428 |
exiftool -p '${createdate#;DateFmt("%Y-%m-%d_%H%M%S")}' a.jpg |
| 7429 |
|
| 7430 |
B<C<ShiftTime>> |
| 7431 |
|
| 7432 |
Shifts EXIF-formatted date/time string by a specified amount. Start with a |
| 7433 |
leading minus sign to shift backwards in time. See |
| 7434 |
L<Image::ExifTool::Shift.pl|Image::ExifTool::Shift.pl> for details about |
| 7435 |
shift syntax. For example, to shift a date/time value back by one year: |
| 7436 |
|
| 7437 |
exiftool -p '${createdate;ShiftTime("-1:0:0 0")}' a.jpg |
| 7438 |
|
| 7439 |
B<C<NoDups>> |
| 7440 |
|
| 7441 |
Removes duplicate items from a list with a separator specified by the |
| 7442 |
B<-sep> option. This function is most useful when copying list-type tags. |
| 7443 |
For example, the following command may be used to remove duplicate Keywords: |
| 7444 |
|
| 7445 |
exiftool -sep '##' '-keywords<${keywords;NoDups}' a.jpg |
| 7446 |
|
| 7447 |
The B<-sep> option is necessary to split the string back into individual |
| 7448 |
list items when writing to a list-type tag. |
| 7449 |
|
| 7450 |
An optional flag argument may be set to 1 to cause C<NoDups> to set C<$_> to |
| 7451 |
undef if no duplicates existed, thus preventing the file from being |
| 7452 |
rewritten unnecessarily: |
| 7453 |
|
| 7454 |
exiftool -sep '##' '-keywords<${keywords;NoDups(1)}' a.jpg |
| 7455 |
|
| 7456 |
ExifTool 12.64 adds an API NoDups option which makes the NoDups helper |
| 7457 |
function largely redundant, with all the functionality except the ability to |
| 7458 |
avoid rewriting the file if there are no duplicates, but with the advantage |
| 7459 |
the duplicates may be removed when accumulating list items from multiple |
| 7460 |
sources. An equivalent to the above commands using this feature would be: |
| 7461 |
|
| 7462 |
exiftool -tagsfromfile @ -keywords -api nodups a.jpg |
| 7463 |
|
| 7464 |
B<C<SetTags>> |
| 7465 |
|
| 7466 |
Used to set tags in extracted images. With no arguments, copies all tags |
| 7467 |
from the source file to the embedded image: |
| 7468 |
|
| 7469 |
exiftool -p '${previewimage;SetTags}' -b a.arw > preview.jpg |
| 7470 |
|
| 7471 |
Arguments may be added to copy or set specific tags. Arguments take exactly |
| 7472 |
the same form as those on the command line when copying or writing tags, |
| 7473 |
but without the leading dash. For example: |
| 7474 |
|
| 7475 |
exiftool -p '${previewimage;SetTags("comment=test","title<filename")}' ... |
| 7476 |
|
| 7477 |
=head1 WINDOWS UNICODE FILE NAMES |
| 7478 |
|
| 7479 |
In Windows, command-line arguments are specified using the current code page |
| 7480 |
and are recoded automatically to the system code page. This recoding is not |
| 7481 |
done for arguments in ExifTool arg files, so by default filenames in arg |
| 7482 |
files use the system code page. Unfortunately, these code pages are not |
| 7483 |
complete character sets, so not all file names may be represented. |
| 7484 |
|
| 7485 |
ExifTool 9.79 and later allow the file name encoding to be specified with |
| 7486 |
C<-charset filename=CHARSET>, where C<CHARSET> is the name of a valid |
| 7487 |
ExifTool character set, preferably C<UTF8> (see the B<-charset> option for a |
| 7488 |
complete list). Setting this triggers the use of Windows wide-character i/o |
| 7489 |
routines, thus providing support for most Unicode file names (see note 4). |
| 7490 |
But note that it is not trivial to pass properly encoded file names on the |
| 7491 |
Windows command line (see L<https://exiftool.org/faq.html#Q18> for details), |
| 7492 |
so placing them in a UTF-8 encoded B<-@> argfile and using |
| 7493 |
C<-charset filename=utf8> is recommended if possible. |
| 7494 |
|
| 7495 |
A warning is issued if a specified filename contains special characters and |
| 7496 |
the filename character set was not provided. However, the warning may be |
| 7497 |
disabled by setting C<-charset filename="">, and ExifTool may still function |
| 7498 |
correctly if the system code page matches the character set used for the |
| 7499 |
file names. |
| 7500 |
|
| 7501 |
When a directory name is provided, the file name encoding need not be |
| 7502 |
specified (unless the directory name contains special characters), and |
| 7503 |
ExifTool will automatically use wide-character routines to scan the |
| 7504 |
directory. |
| 7505 |
|
| 7506 |
The filename character set applies to the I<FILE> arguments as well as |
| 7507 |
filename arguments of B<-@>, B<-geotag>, B<-o>, B<-p>, B<-srcfile>, |
| 7508 |
B<-tagsFromFile>, B<-csv>=, B<-j>= and B<->I<TAG>E<lt>=. However, it does |
| 7509 |
not apply to the B<-config> filename, which always uses the system character |
| 7510 |
set. The C<-charset filename=> option must come before the B<-@> option to |
| 7511 |
be effective, but the order doesn't matter with respect to other options. |
| 7512 |
|
| 7513 |
Notes: |
| 7514 |
|
| 7515 |
1) FileName and Directory tag values still use the same encoding as other |
| 7516 |
tag values, and are converted to/from the filename character set when |
| 7517 |
writing/reading if specified. |
| 7518 |
|
| 7519 |
2) Unicode support is not yet implemented for other Windows-based systems |
| 7520 |
like Cygwin. |
| 7521 |
|
| 7522 |
3) See L</WRITING READ-ONLY FILES> below for a note about editing read-only |
| 7523 |
files with Unicode names. |
| 7524 |
|
| 7525 |
4) Unicode file names with surrogate pairs (code points over U+FFFF) still |
| 7526 |
cause problems. |
| 7527 |
|
| 7528 |
=head1 WRITING READ-ONLY FILES |
| 7529 |
|
| 7530 |
In general, ExifTool may be used to write metadata to read-only files |
| 7531 |
provided that the user has write permission in the directory. However, |
| 7532 |
there are three cases where file write permission is also required: |
| 7533 |
|
| 7534 |
1) When using the B<-overwrite_original_in_place> option. |
| 7535 |
|
| 7536 |
2) When writing only pseudo System tags (eg. FileModifyDate). |
| 7537 |
|
| 7538 |
3) On Windows if the file has Unicode characters in its name, and a) the |
| 7539 |
B<-overwrite_original> option is used, or b) the C<_original> backup already |
| 7540 |
exists. |
| 7541 |
|
| 7542 |
Hidden files in Windows behave as read-only files when attempting to write |
| 7543 |
any real tags to the file -- an error is generated when using the |
| 7544 |
B<-overwrite_original_in_place>, otherwise writing should be successful and |
| 7545 |
the hidden attribute will be removed. But the B<-if> option may be used to |
| 7546 |
avoid processing hidden files (provided Win32API::File is available): |
| 7547 |
|
| 7548 |
exiftool -if "$fileattributes !~ /Hidden/" ... |
| 7549 |
|
| 7550 |
=head1 READING EXAMPLES |
| 7551 |
|
| 7552 |
B<Note>: Beware when cutting and pasting these examples into your terminal! |
| 7553 |
Some characters such as single and double quotes and hyphens may have been |
| 7554 |
changed into similar-looking yet functionally-different characters by the |
| 7555 |
text formatter used to display this documentation. Also note that in the |
| 7556 |
Windows cmd shell double quotes must be used instead of the single quotes |
| 7557 |
used in the examples. |
| 7558 |
|
| 7559 |
=over 5 |
| 7560 |
|
| 7561 |
=item C<exiftool -a -u -g1 a.jpg> |
| 7562 |
|
| 7563 |
Print all meta information in an image, including duplicate and unknown |
| 7564 |
tags, sorted by group (for family 1). For performance reasons, this command |
| 7565 |
may not extract all available metadata. (Metadata in embedded documents, |
| 7566 |
metadata extracted by external utilities, and metadata requiring excessive |
| 7567 |
processing time may not be extracted). Add C<-ee3> and C<-api RequestAll=3> |
| 7568 |
to the command to extract absolutely everything available. |
| 7569 |
|
| 7570 |
=item C<exiftool -common dir> |
| 7571 |
|
| 7572 |
Print common meta information for all images in C<dir>. C<-common> is a |
| 7573 |
L<shortcut tag|Image::ExifTool::Shortcuts> representing common EXIF meta |
| 7574 |
information. |
| 7575 |
|
| 7576 |
=item C<exiftool -T -createdate -aperture -shutterspeed -iso dir E<gt> out.txt> |
| 7577 |
|
| 7578 |
List specified meta information in tab-delimited column form for all images |
| 7579 |
in C<dir> to an output text file named "out.txt". |
| 7580 |
|
| 7581 |
=item C<exiftool -s -ImageSize -ExposureTime b.jpg> |
| 7582 |
|
| 7583 |
Print ImageSize and ExposureTime tag names and values. |
| 7584 |
|
| 7585 |
=item C<exiftool -l -canon c.jpg d.jpg> |
| 7586 |
|
| 7587 |
Print standard Canon information from two image files. |
| 7588 |
|
| 7589 |
=item C<exiftool -r -w .txt -common pictures> |
| 7590 |
|
| 7591 |
Recursively extract common meta information from files in C<pictures> |
| 7592 |
directory, writing text output to C<.txt> files with the same names. |
| 7593 |
|
| 7594 |
=item C<exiftool -b -ThumbnailImage image.jpg E<gt> thumbnail.jpg> |
| 7595 |
|
| 7596 |
Save thumbnail image from C<image.jpg> to a file called C<thumbnail.jpg>. |
| 7597 |
|
| 7598 |
=item C<exiftool -b -JpgFromRaw -w _JFR.JPG -ext NEF -r .> |
| 7599 |
|
| 7600 |
Recursively extract JPG image from all Nikon NEF files in the current |
| 7601 |
directory, adding C<_JFR.JPG> for the name of the output JPG files. |
| 7602 |
|
| 7603 |
=item C<exiftool -a -b -W %d%f_%t%-c.%s -preview:all dir> |
| 7604 |
|
| 7605 |
Extract all types of preview images (ThumbnailImage, PreviewImage, |
| 7606 |
JpgFromRaw, etc.) from files in directory "dir", adding the tag name to the |
| 7607 |
output preview image file names. |
| 7608 |
|
| 7609 |
=item C<exiftool -d '%r %a, %B %e, %Y' -DateTimeOriginal -S -s -ext jpg .> |
| 7610 |
|
| 7611 |
Print formatted date/time for all JPG files in the current directory. |
| 7612 |
|
| 7613 |
=item C<exiftool -IFD1:XResolution -IFD1:YResolution image.jpg> |
| 7614 |
|
| 7615 |
Extract image resolution from EXIF IFD1 information (thumbnail image IFD). |
| 7616 |
|
| 7617 |
=item C<exiftool '-*resolution*' image.jpg> |
| 7618 |
|
| 7619 |
Extract all tags with names containing the word "Resolution" from an image. |
| 7620 |
|
| 7621 |
=item C<exiftool -xmp:author:all -a image.jpg> |
| 7622 |
|
| 7623 |
Extract all author-related XMP information from an image. |
| 7624 |
|
| 7625 |
=item C<exiftool -xmp -b a.jpg E<gt> out.xmp> |
| 7626 |
|
| 7627 |
Extract complete XMP data record intact from C<a.jpg> and write it to |
| 7628 |
C<out.xmp> using the special C<XMP> tag (see the Extra tags in |
| 7629 |
L<Image::ExifTool::TagNames|Image::ExifTool::TagNames>). |
| 7630 |
|
| 7631 |
=item C<exiftool -p '$filename has date $dateTimeOriginal' -q -f dir> |
| 7632 |
|
| 7633 |
Print one line of output containing the file name and DateTimeOriginal for |
| 7634 |
each image in directory C<dir>. |
| 7635 |
|
| 7636 |
=item C<exiftool -ee3 -p '$gpslatitude, $gpslongitude, $gpstimestamp' a.m2ts> |
| 7637 |
|
| 7638 |
Extract all GPS positions from an AVCHD video. |
| 7639 |
|
| 7640 |
=item C<exiftool -icc_profile -b -w icc image.jpg> |
| 7641 |
|
| 7642 |
Save complete ICC_Profile from an image to an output file with the same name |
| 7643 |
and an extension of C<.icc>. |
| 7644 |
|
| 7645 |
=item C<exiftool -htmldump -w tmp/%f_%e.html t/images> |
| 7646 |
|
| 7647 |
Generate HTML pages from a hex dump of EXIF information in all images from |
| 7648 |
the C<t/images> directory. The output HTML files are written to the C<tmp> |
| 7649 |
directory (which is created if it didn't exist), with names of the form |
| 7650 |
'FILENAME_EXT.html'. |
| 7651 |
|
| 7652 |
=item C<exiftool -a -b -ee -embeddedimage -W Image_%.3g3.%s file.pdf> |
| 7653 |
|
| 7654 |
Extract embedded JPG and JP2 images from a PDF file. The output images will |
| 7655 |
have file names like "Image_#.jpg" or "Image_#.jp2", where "#" is the |
| 7656 |
ExifTool family 3 embedded document number for the image. |
| 7657 |
|
| 7658 |
=back |
| 7659 |
|
| 7660 |
=head1 WRITING EXAMPLES |
| 7661 |
|
| 7662 |
Note that quotes are necessary around arguments which contain certain |
| 7663 |
special characters such as C<E<gt>>, C<E<lt>> or any white space. These |
| 7664 |
quoting techniques are shell dependent, but the examples below will work for |
| 7665 |
most Unix shells. With the Windows cmd shell however, double quotes should |
| 7666 |
be used (eg. -Comment=E<34>This is a new commentE<34>). |
| 7667 |
|
| 7668 |
=over 5 |
| 7669 |
|
| 7670 |
=item C<exiftool -tagsfromfile src.jpg -exif:all --subifd:all dst.jpg> |
| 7671 |
|
| 7672 |
Write new comment to a JPG image (replaces any existing comment). |
| 7673 |
|
| 7674 |
=item C<exiftool -comment= -o newdir -ext jpg .> |
| 7675 |
|
| 7676 |
Remove comment from all JPG images in the current directory, writing the |
| 7677 |
modified images to a new directory. |
| 7678 |
|
| 7679 |
=item C<exiftool -keywords=EXIF -keywords=editor dst.jpg> |
| 7680 |
|
| 7681 |
Replace existing keyword list with two new keywords (C<EXIF> and C<editor>). |
| 7682 |
|
| 7683 |
=item C<exiftool -Keywords+=word -o newfile.jpg src.jpg> |
| 7684 |
|
| 7685 |
Copy a source image to a new file, and add a keyword (C<word>) to the |
| 7686 |
current list of keywords. |
| 7687 |
|
| 7688 |
=item C<exiftool -exposurecompensation+=-0.5 a.jpg> |
| 7689 |
|
| 7690 |
Decrement the value of ExposureCompensation by 0.5 EV. Note that += with a |
| 7691 |
negative value is used for decrementing because the -= operator is used for |
| 7692 |
conditional deletion (see next example). |
| 7693 |
|
| 7694 |
=item C<exiftool -credit-=xxx dir> |
| 7695 |
|
| 7696 |
Delete Credit information from all files in a directory where the Credit |
| 7697 |
value was C<xxx>. |
| 7698 |
|
| 7699 |
=item C<exiftool -xmp:description-de='kühl' -E dst.jpg> |
| 7700 |
|
| 7701 |
Write alternate language for XMP:Description, using HTML character escaping |
| 7702 |
to input special characters. |
| 7703 |
|
| 7704 |
=item C<exiftool -all= dst.jpg> |
| 7705 |
|
| 7706 |
Delete all meta information from an image. Note: You should NOT do this to |
| 7707 |
RAW images (except DNG) since proprietary RAW image formats often contain |
| 7708 |
information in the makernotes that is necessary for converting the image. |
| 7709 |
|
| 7710 |
=item C<exiftool -all= -comment='lonely' dst.jpg> |
| 7711 |
|
| 7712 |
Delete all meta information from an image and add a comment back in. (Note |
| 7713 |
that the order is important: C<-comment='lonely' -all=> would also delete |
| 7714 |
the new comment.) |
| 7715 |
|
| 7716 |
=item C<exiftool -all= --jfif:all dst.jpg> |
| 7717 |
|
| 7718 |
Delete all meta information except JFIF group from an image. |
| 7719 |
|
| 7720 |
=item C<exiftool -Photoshop:All= dst.jpg> |
| 7721 |
|
| 7722 |
Delete Photoshop meta information from an image (note that the Photoshop |
| 7723 |
information also includes IPTC). |
| 7724 |
|
| 7725 |
=item C<exiftool -r -XMP-crss:all= DIR> |
| 7726 |
|
| 7727 |
Recursively delete all XMP-crss information from images in a directory. |
| 7728 |
|
| 7729 |
=item C<exiftool '-ThumbnailImageE<lt>=thumb.jpg' dst.jpg> |
| 7730 |
|
| 7731 |
Set the thumbnail image from specified file (Note: The quotes are necessary |
| 7732 |
to prevent shell redirection). |
| 7733 |
|
| 7734 |
=item C<exiftool '-JpgFromRawE<lt>=%d%f_JFR.JPG' -ext NEF -r .> |
| 7735 |
|
| 7736 |
Recursively write JPEG images with filenames ending in C<_JFR.JPG> to the |
| 7737 |
JpgFromRaw tag of like-named files with extension C<.NEF> in the current |
| 7738 |
directory. (This is the inverse of the C<-JpgFromRaw> command of the |
| 7739 |
L</READING EXAMPLES> section above.) |
| 7740 |
|
| 7741 |
=item C<exiftool -DateTimeOriginal-='0:0:0 1:30:0' dir> |
| 7742 |
|
| 7743 |
Adjust original date/time of all images in directory C<dir> by subtracting |
| 7744 |
one hour and 30 minutes. (This is equivalent to C<-DateTimeOriginal-=1.5>. |
| 7745 |
See L<Image::ExifTool::Shift.pl|Image::ExifTool::Shift.pl> for details.) |
| 7746 |
|
| 7747 |
=item C<exiftool -createdate+=3 -modifydate+=3 a.jpg b.jpg> |
| 7748 |
|
| 7749 |
Add 3 hours to the CreateDate and ModifyDate timestamps of two images. |
| 7750 |
|
| 7751 |
=item C<exiftool -AllDates+=1:30 -if '$make eq E<34>CanonE<34>' dir> |
| 7752 |
|
| 7753 |
Shift the values of DateTimeOriginal, CreateDate and ModifyDate forward by 1 |
| 7754 |
hour and 30 minutes for all Canon images in a directory. (The AllDates tag |
| 7755 |
is provided as a shortcut for these three tags, allowing them to be accessed |
| 7756 |
via a single tag.) |
| 7757 |
|
| 7758 |
=item C<exiftool -xmp:city=Kingston image1.jpg image2.nef> |
| 7759 |
|
| 7760 |
Write a tag to the XMP group of two images. (Without the C<xmp:> this tag |
| 7761 |
would get written to the IPTC group since C<City> exists in both, and IPTC |
| 7762 |
is preferred by default.) |
| 7763 |
|
| 7764 |
=item C<exiftool -LightSource-='Unknown (0)' dst.tiff> |
| 7765 |
|
| 7766 |
Delete C<LightSource> tag only if it is unknown with a value of 0. |
| 7767 |
|
| 7768 |
=item C<exiftool -whitebalance-=auto -WhiteBalance=tung dst.jpg> |
| 7769 |
|
| 7770 |
Set C<WhiteBalance> to C<Tungsten> only if it was previously C<Auto>. |
| 7771 |
|
| 7772 |
=item C<exiftool -comment-= -comment='new comment' a.jpg> |
| 7773 |
|
| 7774 |
Write a new comment only if the image doesn't have one already. |
| 7775 |
|
| 7776 |
=item C<exiftool -o %d%f.xmp dir> |
| 7777 |
|
| 7778 |
Create XMP meta information data files for all images in C<dir>. |
| 7779 |
|
| 7780 |
=item C<exiftool -o test.xmp -owner=Phil -title='XMP File'> |
| 7781 |
|
| 7782 |
Create an XMP data file only from tags defined on the command line. |
| 7783 |
|
| 7784 |
=item C<exiftool '-ICC_Profile<=%d%f.icc' image.jpg> |
| 7785 |
|
| 7786 |
Write ICC_Profile to an image from a C<.icc> file of the same name. |
| 7787 |
|
| 7788 |
=item C<exiftool -hierarchicalkeywords='{keyword=one,children={keyword=B}}'> |
| 7789 |
|
| 7790 |
Write structured XMP information. See L<https://exiftool.org/struct.html> |
| 7791 |
for more details. |
| 7792 |
|
| 7793 |
=item C<exiftool -trailer:all= image.jpg> |
| 7794 |
|
| 7795 |
Delete any trailer found after the end of image (EOI) in a JPEG file. A |
| 7796 |
number of digital cameras store a large PreviewImage after the JPEG EOI, and |
| 7797 |
the file size may be reduced significantly by deleting this trailer. See |
| 7798 |
the L<JPEG Tags documentation|Image::ExifTool::TagNames/JPEG Tags> for a |
| 7799 |
list of recognized JPEG trailers. |
| 7800 |
|
| 7801 |
=back |
| 7802 |
|
| 7803 |
=head1 COPYING EXAMPLES |
| 7804 |
|
| 7805 |
These examples demonstrate the ability to copy tag values between files. |
| 7806 |
|
| 7807 |
=over 5 |
| 7808 |
|
| 7809 |
=item C<exiftool -tagsFromFile src.cr2 dst.jpg> |
| 7810 |
|
| 7811 |
Copy the values of all writable tags from C<src.cr2> to C<dst.jpg>, writing |
| 7812 |
the information to same-named tags in the preferred groups. |
| 7813 |
|
| 7814 |
=item C<exiftool -TagsFromFile src.jpg -all:all dst.jpg> |
| 7815 |
|
| 7816 |
Copy the values of all writable tags from C<src.jpg> to C<dst.jpg>, |
| 7817 |
preserving the original tag groups. |
| 7818 |
|
| 7819 |
=item C<exiftool -all= -tagsfromfile src.jpg -exif:all dst.jpg> |
| 7820 |
|
| 7821 |
Erase all meta information from C<dst.jpg> image, then copy EXIF tags from |
| 7822 |
C<src.jpg>. |
| 7823 |
|
| 7824 |
=item C<exiftool -exif:all= -tagsfromfile @ -all:all -unsafe bad.jpg> |
| 7825 |
|
| 7826 |
Rebuild all EXIF meta information from scratch in an image. This technique |
| 7827 |
can be used in JPEG images to repair corrupted EXIF information which |
| 7828 |
otherwise could not be written due to errors. The C<Unsafe> tag is a |
| 7829 |
shortcut for unsafe EXIF tags in JPEG images which are not normally copied. |
| 7830 |
See the L<tag name documentation|Image::ExifTool::TagNames> for more details |
| 7831 |
about unsafe tags. |
| 7832 |
|
| 7833 |
=item C<exiftool -Tagsfromfile a.jpg out.xmp> |
| 7834 |
|
| 7835 |
Copy meta information from C<a.jpg> to an XMP data file. If the XMP data |
| 7836 |
file C<out.xmp> already exists, it will be updated with the new information. |
| 7837 |
Otherwise the XMP data file will be created. Only metadata-only files may |
| 7838 |
be created like this (files containing images may be edited but not |
| 7839 |
created). See L</WRITING EXAMPLES> above for another technique to generate |
| 7840 |
XMP files. |
| 7841 |
|
| 7842 |
=item C<exiftool -tagsFromFile a.jpg -XMP:All= -ThumbnailImage= -m b.jpg> |
| 7843 |
|
| 7844 |
Copy all meta information from C<a.jpg> to C<b.jpg>, deleting all XMP |
| 7845 |
information and the thumbnail image from the destination. |
| 7846 |
|
| 7847 |
=item C<exiftool -TagsFromFile src.jpg -title -author=Phil dst.jpg> |
| 7848 |
|
| 7849 |
Copy title from one image to another and set a new author name. |
| 7850 |
|
| 7851 |
=item C<exiftool -TagsFromFile a.jpg -ISO -TagsFromFile b.jpg -comment |
| 7852 |
dst.jpg> |
| 7853 |
|
| 7854 |
Copy ISO from one image and Comment from another image to a destination |
| 7855 |
image. |
| 7856 |
|
| 7857 |
=item C<exiftool -tagsfromfile src.jpg -exif:all --subifd:all dst.jpg> |
| 7858 |
|
| 7859 |
Copy only the EXIF information from one image to another, excluding SubIFD |
| 7860 |
tags. |
| 7861 |
|
| 7862 |
=item C<exiftool '-FileModifyDateE<lt>DateTimeOriginal' dir> |
| 7863 |
|
| 7864 |
Use the original date from the meta information to set the same file's |
| 7865 |
filesystem modification date for all images in a directory. (Note that |
| 7866 |
C<-TagsFromFile @> is assumed if no other B<-TagsFromFile> is specified when |
| 7867 |
redirecting information as in this example.) |
| 7868 |
|
| 7869 |
=item C<exiftool -TagsFromFile src.jpg '-xmp:allE<lt>all' dst.jpg> |
| 7870 |
|
| 7871 |
Copy all possible information from C<src.jpg> and write in XMP format to |
| 7872 |
C<dst.jpg>. |
| 7873 |
|
| 7874 |
=item C<exiftool '-Description<${FileName;s/\.[^.]*$//}' dir> |
| 7875 |
|
| 7876 |
Set the image Description from the file name after removing the extension. |
| 7877 |
This example uses the L</Advanced formatting feature> to perform a |
| 7878 |
substitution operation to remove the last dot and subsequent characters from |
| 7879 |
the file name. |
| 7880 |
|
| 7881 |
=item C<exiftool -@ iptc2xmp.args -iptc:all= a.jpg> |
| 7882 |
|
| 7883 |
Translate IPTC information to XMP with appropriate tag name conversions, and |
| 7884 |
delete the original IPTC information from an image. This example uses |
| 7885 |
iptc2xmp.args, which is a file included with the ExifTool distribution that |
| 7886 |
contains the required arguments to convert IPTC information to XMP format. |
| 7887 |
Also included with the distribution are xmp2iptc.args (which performs the |
| 7888 |
inverse conversion) and a few more .args files for other conversions between |
| 7889 |
EXIF, IPTC and XMP. |
| 7890 |
|
| 7891 |
=item C<exiftool -tagsfromfile %d%f.CR2 -r -ext JPG dir> |
| 7892 |
|
| 7893 |
Recursively rewrite all C<JPG> images in C<dir> with information copied from |
| 7894 |
the corresponding C<CR2> images in the same directories. |
| 7895 |
|
| 7896 |
=item C<exiftool '-keywords+E<lt>make' image.jpg> |
| 7897 |
|
| 7898 |
Add camera make to list of keywords. |
| 7899 |
|
| 7900 |
=item C<exiftool '-commentE<lt>ISO=$exif:iso Exposure=${shutterspeed}' dir> |
| 7901 |
|
| 7902 |
Set the Comment tag of all images in C<dir> from the values of the EXIF:ISO |
| 7903 |
and ShutterSpeed tags. The resulting comment will be in the form "ISO=100 |
| 7904 |
Exposure=1/60". |
| 7905 |
|
| 7906 |
=item C<exiftool -TagsFromFile src.jpg -icc_profile dst.jpg> |
| 7907 |
|
| 7908 |
Copy ICC_Profile from one image to another. |
| 7909 |
|
| 7910 |
=item C<exiftool -TagsFromFile src.jpg -all:all dst.mie> |
| 7911 |
|
| 7912 |
Copy all meta information in its original form from a JPEG image to a MIE |
| 7913 |
file. The MIE file will be created if it doesn't exist. This technique can |
| 7914 |
be used to store the metadata of an image so it can be inserted back into |
| 7915 |
the image (with the inverse command) later in a workflow. |
| 7916 |
|
| 7917 |
=item C<exiftool -o dst.mie -all:all src.jpg> |
| 7918 |
|
| 7919 |
This command performs exactly the same task as the command above, except |
| 7920 |
that the B<-o> option will not write to an output file that already exists. |
| 7921 |
|
| 7922 |
=item C<exiftool -b -jpgfromraw -w %d%f_%ue.jpg -execute -b -previewimage -w |
| 7923 |
%d%f_%ue.jpg -execute -tagsfromfile @ -srcfile %d%f_%ue.jpg |
| 7924 |
-overwrite_original -common_args --ext jpg DIR> |
| 7925 |
|
| 7926 |
[Advanced] Extract JpgFromRaw or PreviewImage from all but JPG files in DIR, |
| 7927 |
saving them with file names like C<image_EXT.jpg>, then add all meta |
| 7928 |
information from the original files to the extracted images. Here, the |
| 7929 |
command line is broken into three sections (separated by B<-execute> |
| 7930 |
options), and each is executed as if it were a separate command. The |
| 7931 |
B<-common_args> option causes the C<--ext jpg DIR> arguments to be applied |
| 7932 |
to all three commands, and the B<-srcfile> option allows the extracted JPG |
| 7933 |
image to be the source file for the third command (whereas the RAW files are |
| 7934 |
the source files for the other two commands). |
| 7935 |
|
| 7936 |
=back |
| 7937 |
|
| 7938 |
=head1 RENAMING EXAMPLES |
| 7939 |
|
| 7940 |
By writing the C<FileName> and C<Directory> tags, files are renamed and/or |
| 7941 |
moved to new directories. This can be particularly useful and powerful for |
| 7942 |
organizing files by date when combined with the B<-d> option. New |
| 7943 |
directories are created as necessary, but existing files will not be |
| 7944 |
overwritten. The format codes %d, %f and %e may be used in the new file |
| 7945 |
name to represent the directory, name and extension of the original file, |
| 7946 |
and %c may be used to add a copy number if the file already exists (see the |
| 7947 |
B<-w> option for details). Note that if used within a date format string, |
| 7948 |
an extra '%' must be added to pass these codes through the date/time parser. |
| 7949 |
(And further note that in a Windows batch file, all '%' characters must also |
| 7950 |
be escaped, so in this extreme case '%%%%f' is necessary to pass a simple |
| 7951 |
'%f' through the two levels of parsing.) See |
| 7952 |
L<https://exiftool.org/filename.html> for additional documentation and |
| 7953 |
examples. |
| 7954 |
|
| 7955 |
=over 5 |
| 7956 |
|
| 7957 |
=item C<exiftool -filename=new.jpg dir/old.jpg> |
| 7958 |
|
| 7959 |
Rename C<old.jpg> to C<new.jpg> in directory C<dir>. |
| 7960 |
|
| 7961 |
=item C<exiftool -directory=%e dir> |
| 7962 |
|
| 7963 |
Move all files from directory C<dir> into directories named by the original |
| 7964 |
file extensions. |
| 7965 |
|
| 7966 |
=item C<exiftool '-DirectoryE<lt>DateTimeOriginal' -d %Y/%m/%d dir> |
| 7967 |
|
| 7968 |
Move all files in C<dir> into a directory hierarchy based on year, month and |
| 7969 |
day of C<DateTimeOriginal>. eg) This command would move the file |
| 7970 |
C<dir/image.jpg> with a C<DateTimeOriginal> of C<2005:10:12 16:05:56> to |
| 7971 |
C<2005/10/12/image.jpg>. |
| 7972 |
|
| 7973 |
=item C<exiftool -o . '-DirectoryE<lt>DateTimeOriginal' -d %Y/%m/%d dir> |
| 7974 |
|
| 7975 |
Same effect as above except files are copied instead of moved. |
| 7976 |
|
| 7977 |
=item C<exiftool '-filenameE<lt>%f_${model;}.%e' dir> |
| 7978 |
|
| 7979 |
Rename all files in C<dir> by adding the camera model name to the file name. |
| 7980 |
The semicolon after the tag name inside the braces causes characters which |
| 7981 |
are invalid in Windows file names to be deleted from the tag value (see the |
| 7982 |
L</Advanced formatting feature> for an explanation). |
| 7983 |
|
| 7984 |
=item C<exiftool '-FileNameE<lt>CreateDate' -d %Y%m%d_%H%M%S%%-c.%%e dir> |
| 7985 |
|
| 7986 |
Rename all images in C<dir> according to the C<CreateDate> date and time, |
| 7987 |
adding a copy number with leading '-' if the file already exists (C<%-c>), |
| 7988 |
and preserving the original file extension (C<%e>). Note the extra '%' |
| 7989 |
necessary to escape the filename codes (C<%c> and C<%e>) in the date format |
| 7990 |
string. |
| 7991 |
|
| 7992 |
=item C<exiftool -r '-FileNameE<lt>CreateDate' -d %Y-%m-%d/%H%M_%%f.%%e dir> |
| 7993 |
|
| 7994 |
Both the directory and the filename may be changed together via the |
| 7995 |
C<FileName> tag if the new C<FileName> contains a '/'. The example above |
| 7996 |
recursively renames all images in a directory by adding a C<CreateDate> |
| 7997 |
timestamp to the start of the filename, then moves them into new directories |
| 7998 |
named by date. |
| 7999 |
|
| 8000 |
=item C<exiftool '-FileNameE<lt>${CreateDate}_$filenumber.jpg' -d %Y%m%d -ext jpg .> |
| 8001 |
|
| 8002 |
Set the filename of all JPG images in the current directory from the |
| 8003 |
CreateDate and FileNumber tags, in the form "20060507_118-1861.jpg". |
| 8004 |
|
| 8005 |
=back |
| 8006 |
|
| 8007 |
=head1 GEOTAGGING EXAMPLES |
| 8008 |
|
| 8009 |
ExifTool implements geotagging from GPS log files via 3 special tags: Geotag |
| 8010 |
(which for convenience is also implemented as an exiftool option), Geosync |
| 8011 |
and Geotime. The examples below highlight some geotagging features. See |
| 8012 |
L<https://exiftool.org/geotag.html> for additional documentation. (Note |
| 8013 |
that geotagging from known GPS coordinates is done by writing the |
| 8014 |
L<GPS tags|Image::ExifTool::TagNames/GPS Tags> directly rather than using |
| 8015 |
the B<-geotag> option.) |
| 8016 |
|
| 8017 |
=over 5 |
| 8018 |
|
| 8019 |
=item C<exiftool -geotag track.log a.jpg> |
| 8020 |
|
| 8021 |
Geotag an image (C<a.jpg>) from position information in a GPS track log |
| 8022 |
(C<track.log>). Since the C<Geotime> tag is not specified, the value of |
| 8023 |
SubSecDateTimeOriginal (preferentially) or DateTimeOriginal is used for |
| 8024 |
geotagging. Local system time is assumed unless the time contains a |
| 8025 |
timezone. |
| 8026 |
|
| 8027 |
=item C<exiftool -geotag track.log -geolocate=geotag a.jpg> |
| 8028 |
|
| 8029 |
Geotag an image and also write geolocation information of the nearest city |
| 8030 |
(city name, state/province and country). Read here for more details about |
| 8031 |
the Geolocation feature: L<https://exiftool.org/geolocation.html#Write> |
| 8032 |
|
| 8033 |
=item C<exiftool -geotag t.log -geotime='2009:04:02 13:41:12-05:00' a.jpg> |
| 8034 |
|
| 8035 |
Geotag an image with the GPS position for a specific time. |
| 8036 |
|
| 8037 |
=item C<exiftool -geotag log.gpx '-xmp:geotimeE<lt>createdate' dir> |
| 8038 |
|
| 8039 |
Geotag all images in directory C<dir> with XMP tags instead of EXIF tags, |
| 8040 |
based on the image CreateDate. |
| 8041 |
|
| 8042 |
=item C<exiftool -geotag a.log -geosync=-20 dir> |
| 8043 |
|
| 8044 |
Geotag images in directory C<dir>, accounting for image timestamps which |
| 8045 |
were 20 seconds ahead of GPS. |
| 8046 |
|
| 8047 |
=item C<exiftool -geotag a.log -geosync=1.jpg -geosync=2.jpg dir> |
| 8048 |
|
| 8049 |
Geotag images using time synchronization from two previously geotagged images |
| 8050 |
(1.jpg and 2.jpg), synchronizing the image and GPS times using a linear time |
| 8051 |
drift correction. |
| 8052 |
|
| 8053 |
=item C<exiftool -geotag a.log '-geotimeE<lt>${createdate}+01:00' dir> |
| 8054 |
|
| 8055 |
Geotag images in C<dir> using CreateDate with the specified timezone. If |
| 8056 |
CreateDate already contained a timezone, then the timezone specified on the |
| 8057 |
command line is ignored. |
| 8058 |
|
| 8059 |
=item C<exiftool -geotag= a.jpg> |
| 8060 |
|
| 8061 |
Delete GPS tags which may have been added by the geotag feature. Note that |
| 8062 |
this does not remove all GPS tags -- to do this instead use C<-gps:all=>. |
| 8063 |
|
| 8064 |
=item C<exiftool -xmp:geotag= a.jpg> |
| 8065 |
|
| 8066 |
Delete XMP GPS tags which were added by the geotag feature. |
| 8067 |
|
| 8068 |
=item C<exiftool -xmp:geotag=track.log a.jpg> |
| 8069 |
|
| 8070 |
Geotag an image with XMP tags, using the time from SubSecDateTimeOriginal or |
| 8071 |
DateTimeOriginal. |
| 8072 |
|
| 8073 |
=item C<exiftool -geotag a.log -geotag b.log -r dir> |
| 8074 |
|
| 8075 |
Combine multiple track logs and geotag an entire directory tree of images. |
| 8076 |
|
| 8077 |
=item C<exiftool -geotag 'tracks/*.log' -r dir> |
| 8078 |
|
| 8079 |
Read all track logs from the C<tracks> directory. |
| 8080 |
|
| 8081 |
=item C<exiftool -p gpx.fmt dir E<gt> out.gpx> |
| 8082 |
|
| 8083 |
Generate a GPX track log from all images in directory C<dir>. This example |
| 8084 |
uses the C<gpx.fmt> file included in the full ExifTool distribution package |
| 8085 |
and assumes that the images in C<dir> have all been previously geotagged. |
| 8086 |
|
| 8087 |
=back |
| 8088 |
|
| 8089 |
=head1 PIPING EXAMPLES |
| 8090 |
|
| 8091 |
=over 5 |
| 8092 |
|
| 8093 |
=item C<cat a.jpg | exiftool -> |
| 8094 |
|
| 8095 |
Extract information from stdin. |
| 8096 |
|
| 8097 |
=item C<exiftool image.jpg -thumbnailimage -b | exiftool -> |
| 8098 |
|
| 8099 |
Extract information from an embedded thumbnail image. |
| 8100 |
|
| 8101 |
=item C<cat a.jpg | exiftool -iptc:keywords+=fantastic - E<gt> b.jpg> |
| 8102 |
|
| 8103 |
Add an IPTC keyword in a pipeline, saving output to a new file. |
| 8104 |
|
| 8105 |
=item C<curl -s http://a.domain.com/bigfile.jpg | exiftool -fast -> |
| 8106 |
|
| 8107 |
Extract information from an image over the internet using the cURL utility. |
| 8108 |
The B<-fast> option prevents exiftool from scanning for trailer information, |
| 8109 |
so only the meta information header is transferred. |
| 8110 |
|
| 8111 |
=item C<exiftool a.jpg -thumbnailimage -b | exiftool -comment=wow - | |
| 8112 |
exiftool a.jpg -thumbnailimage'E<lt>=-'> |
| 8113 |
|
| 8114 |
Add a comment to an embedded thumbnail image. (Why anyone would want to do |
| 8115 |
this I don't know, but I've included this as an example to illustrate the |
| 8116 |
flexibility of ExifTool.) |
| 8117 |
|
| 8118 |
=back |
| 8119 |
|
| 8120 |
=head1 INTERRUPTING EXIFTOOL |
| 8121 |
|
| 8122 |
Interrupting exiftool with a CTRL-C or SIGINT will not result in partially |
| 8123 |
written files or temporary files remaining on the hard disk. The exiftool |
| 8124 |
application traps SIGINT and defers it until the end of critical processes |
| 8125 |
if necessary, then does a proper cleanup before exiting. |
| 8126 |
|
| 8127 |
=head1 EXIT STATUS |
| 8128 |
|
| 8129 |
The exiftool application exits with a status of 0 on success, or 1 if an |
| 8130 |
error occurred, or 2 if all files failed the B<-if> condition (for any of |
| 8131 |
the commands if B<-execute> was used). |
| 8132 |
|
| 8133 |
=head1 AUTHOR |
| 8134 |
|
| 8135 |
Copyright 2003-2026, Phil Harvey |
| 8136 |
|
| 8137 |
This is free software; you can redistribute it and/or modify it under the |
| 8138 |
same terms as Perl itself. |
| 8139 |
|
| 8140 |
=head1 SEE ALSO |
| 8141 |
|
| 8142 |
L<Image::ExifTool(3pm)|Image::ExifTool>, |
| 8143 |
L<Image::ExifTool::TagNames(3pm)|Image::ExifTool::TagNames>, |
| 8144 |
L<Image::ExifTool::Shortcuts(3pm)|Image::ExifTool::Shortcuts>, |
| 8145 |
L<Image::ExifTool::Shift.pl|Image::ExifTool::Shift.pl> |
| 8146 |
|
| 8147 |
=cut |
| 8148 |
|
| 8149 |
#------------------------------------------------------------------------------ |
| 8150 |
# end |