New plugin - set file mtime to Exif.Image.DateTime
authorColin Clark <colin.clark@cclark.uk>
Sun, 24 Mar 2024 10:38:07 +0000 (10:38 +0000)
committerColin Clark <colin.clark@cclark.uk>
Sun, 24 Mar 2024 10:38:07 +0000 (10:38 +0000)
doc/docbook/GuideReferenceStandardPlugins.xml
plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file [new file with mode: 0755]
plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file.sh [new symlink]
plugins/exif-datetime-to-file/meson.build [new file with mode: 0644]
plugins/exif-datetime-to-file/org.geeqie.exif-datetime-to-file.desktop.in [new file with mode: 0644]
plugins/meson.build

index 6f3298a..05d3cc7 100644 (file)
       menu.
     </para>
   </section>
+  <section id="Exifdatetimetofile">
+    <title>Exif datetime to file</title>
+    <para>
+      Sets the file datetime (mtime) to the Exif.Image.DateTimeOriginal value. If the exif tag does not exist, no action is taken.
+      <para />
+      This may be useful if you wish to sort on Exif.Image.DateTimeOriginal. This requires that the metadata for all files in the folder must be read each time. This is time consuming. If this operation is carried out when images are imported from the camera, future sorting can utilize file datetime which will be much faster.
+    </para>
+    <para>
+      This item is displayed in the
+      <emphasis role="strong">Plugins</emphasis>
+      menu.
+    </para>
+  </section>
   <section id="Exportjpeg">
     <title>Export jpeg</title>
     <para>
diff --git a/plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file b/plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file
new file mode 100755 (executable)
index 0000000..b830eb9
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+## @file
+## @brief Sets file mtime to the Exif.Image.DateTime of the file
+##
+## $@ List of files to be processed
+##
+## Requires exiv2 or exiftool
+##
+
+if [ -z "$(command -v exiv2)" ]
+then
+       if [ -z "$(command -v exiftool)" ]
+       then
+               zenity --title="Geeqie exif datetime to file" --info --width=200 --text="Neither exiv2 nor exiftran is installed" --window-icon=/usr/local/share/pixmaps/geeqie.png 2> /dev/null
+               exit 1
+       else
+               use_exiv2=false
+       fi
+else
+       use_exiv2=true
+fi
+
+if ! zenity --title="Geeqie - exif datetime to file" --question --text "Set file datetime (mtime) to  Exif.Image.DateTime\n\nContinue?" --width=300 --window-icon=/usr/local/share/pixmaps/geeqie.png
+then
+       exit 0
+fi
+
+# exiv2 should be faster
+if [ "$use_exiv2" = "true" ]
+then
+       while [ $# -gt 0 ]
+       do
+               if date_time=$(exiv2 -g Exif.Image.DateTime -Pv "$1")
+               then
+                       y_m_d_h_m_s=$(echo "$date_time" | tr ' ' ':')
+                       y_m_d_h_m=$(echo "$y_m_d_h_m_s" | cut --delimiter ':' --fields '1 2 3 4 5' | tr --delete ':')
+                       s=$(echo "$y_m_d_h_m_s" | cut --delimiter ':' --fields '6')
+                       touch -m -t "$y_m_d_h_m.$s" "$1"
+               else
+                       printf "Geeqie plugin exif-datetime-to-file -\nFile: %s does not have Exif.Image.DateTime\n" "$1"
+               fi
+               shift
+       done
+else
+       while [ $# -gt 0 ]
+       do
+               if date_time=$(exiftool -t -createdate "$1")
+               then
+                       y_m_d_h_m_s=$(echo "$date_time" | cut --characters '13-31' | tr ' ' ':')
+                       y_m_d_h_m=$(echo "$y_m_d_h_m_s" | cut --delimiter ':' --fields '1 2 3 4 5' | tr --delete ':')
+                       s=$(echo "$y_m_d_h_m_s" | cut --delimiter ':' --fields '6')
+                       touch -m -t "$y_m_d_h_m.$s" "$1"
+               else
+                       printf "Geeqie plugin exif-datetime-to-file -\nFile: %s does not have Exif.Image.DateTime\n" "$1"
+               fi
+               shift
+       done
+fi
diff --git a/plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file.sh b/plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file.sh
new file mode 120000 (symlink)
index 0000000..df5dfc8
--- /dev/null
@@ -0,0 +1 @@
+geeqie-exif-datetime-to-file
\ No newline at end of file
diff --git a/plugins/exif-datetime-to-file/meson.build b/plugins/exif-datetime-to-file/meson.build
new file mode 100644 (file)
index 0000000..efb237a
--- /dev/null
@@ -0,0 +1,22 @@
+# This file is a part of Geeqie project (https://www.geeqie.org/).
+# Copyright (C) 2008 - 2022 The Geeqie Team
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#
+
+install_data('geeqie-exif-datetime-to-file', install_dir : gq_bindir)
+
+i18n.merge_file(
+    input : 'org.geeqie.exif-datetime-to-file.desktop.in',
+    output : 'org.geeqie.exif-datetime-to-file.desktop',
+    type : 'desktop',
+    po_dir : podir,
+    install : true,
+    install_dir : desktopdir)
diff --git a/plugins/exif-datetime-to-file/org.geeqie.exif-datetime-to-file.desktop.in b/plugins/exif-datetime-to-file/org.geeqie.exif-datetime-to-file.desktop.in
new file mode 100644 (file)
index 0000000..8b36cdd
--- /dev/null
@@ -0,0 +1,18 @@
+[Desktop Entry]
+Version=1.0
+Type=Application
+Name=Exif datetime to file
+Comment=Sets file mtime to the Exif.Image.DateTimeOriginal of the file
+
+# Requires exiv2 or exiftools
+
+Exec=geeqie-exif-datetime-to-file %F
+
+# Desktop files that are usable only in Geeqie should be marked like this:
+Categories=Graphics;
+OnlyShowIn=X-Geeqie;
+
+# It can be made verbose
+#X-Geeqie-Verbose=true
+
+Icon=geeqie
index 503c94c..9e4ce5f 100644 (file)
@@ -12,6 +12,7 @@
 #
 
 subdir('camera-import')
+subdir('exif-datetime-to-file')
 subdir('export-jpeg')
 subdir('geocode-parameters')
 subdir('image-crop')