Difference between revisions of "ReNamer:Scripts:ExifTool"

From den4b Wiki
Jump to navigation Jump to search
(→‎Script: Date corrected.)
(→‎Script: UTF8 filename handling)
 
Line 12: Line 12:
  
 
== Script ==
 
== Script ==
 
Author: Denis Kozlov. Date: 2020-01-06.
 
  
 
Replace the filename with the "Date/Time Original" meta tag.
 
Replace the filename with the "Date/Time Original" meta tag.
Line 19: Line 17:
 
The meta tag output is used "as is" and it often contains invalid filename characters, so you may need to use additional rules to clean up the filename afterwards.
 
The meta tag output is used "as is" and it often contains invalid filename characters, so you may need to use additional rules to clean up the filename afterwards.
  
You can check the full list of available meta tags by running <code>exiftool.exe <file></code> comamnd and then you can modify the <tt>TAG</tt> constant to work with any of the listed tags.
+
You can check the full list of available meta tags by running <code>exiftool.exe &lt;file&gt;</code> command and then you can modify the <code>TAG</code> constant to work with any of the listed tags.
  
* Tested with ReNamer 7.1 and ExifTool 11.81.
+
* Tested with ReNamer 7.4 and ExifTool 12.52.
  
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
const
 
const
   EXE = 'exiftool.exe -t';
+
   EXE = 'exiftool.exe -t -charset filename=utf8';
 
   TAG = 'Date/Time Original' + '\t(.*?)[\r\n]';
 
   TAG = 'Date/Time Original' + '\t(.*?)[\r\n]';
  

Latest revision as of 22:07, 12 December 2022

This script integrates ExifTool command tool in order to extract EXIF/IPTC/XMP tags from many types of images. CRW, CR2, RAW, HEIF/HEVC images are also supported.

Requirements

  • exiftool.exe in ReNamer's folder.

Download and extract the ExifTool package into ReNamer's folder.

Note that the ExifTool for Windows package contains a file named exiftool(-k).exe, which must be renamed to exiftool.exe before using in ReNamer. Otherwise, the command line tool interprets the (-k) text as a trigger to wait for the user to press the ENTER key at the end of the output, which ReNamer won't be able to do and the application will just freeze.

Script

Replace the filename with the "Date/Time Original" meta tag.

The meta tag output is used "as is" and it often contains invalid filename characters, so you may need to use additional rules to clean up the filename afterwards.

You can check the full list of available meta tags by running exiftool.exe <file> command and then you can modify the TAG constant to work with any of the listed tags.

  • Tested with ReNamer 7.4 and ExifTool 12.52.
const
  EXE = 'exiftool.exe -t -charset filename=utf8';
  TAG = 'Date/Time Original' + '\t(.*?)[\r\n]';

var
  Command, Output: String;
  Matches: TWideStringArray;

begin
  Command := EXE + ' "' + FilePath + '"';
  if ExecConsoleApp(Command, Output) = 0 then
  begin
    Matches := SubMatchesRegEx(Output, TAG, False);
    if Length(Matches) > 0 then
      FileName := Matches[0] + WideExtractFileExt(FileName);
  end;
end.