From 9acf96b3e25227f4d723397bd0d000450c63b048 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sun, 24 Mar 2024 10:38:07 +0000 Subject: [PATCH] New plugin - set file mtime to Exif.Image.DateTime --- doc/docbook/GuideReferenceStandardPlugins.xml | 13 ++++ .../geeqie-exif-datetime-to-file | 59 +++++++++++++++++++ .../geeqie-exif-datetime-to-file.sh | 1 + plugins/exif-datetime-to-file/meson.build | 22 +++++++ ...rg.geeqie.exif-datetime-to-file.desktop.in | 18 ++++++ plugins/meson.build | 1 + 6 files changed, 114 insertions(+) create mode 100755 plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file create mode 120000 plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file.sh create mode 100644 plugins/exif-datetime-to-file/meson.build create mode 100644 plugins/exif-datetime-to-file/org.geeqie.exif-datetime-to-file.desktop.in diff --git a/doc/docbook/GuideReferenceStandardPlugins.xml b/doc/docbook/GuideReferenceStandardPlugins.xml index 6f3298a8..05d3cc7c 100644 --- a/doc/docbook/GuideReferenceStandardPlugins.xml +++ b/doc/docbook/GuideReferenceStandardPlugins.xml @@ -30,6 +30,19 @@ menu. +
+ Exif datetime to file + + Sets the file datetime (mtime) to the Exif.Image.DateTimeOriginal value. If the exif tag does not exist, no action is taken. + + 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. + + + This item is displayed in the + Plugins + menu. + +
Export jpeg 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 index 00000000..b830eb9c --- /dev/null +++ b/plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file @@ -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 index 00000000..df5dfc80 --- /dev/null +++ b/plugins/exif-datetime-to-file/geeqie-exif-datetime-to-file.sh @@ -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 index 00000000..efb237a4 --- /dev/null +++ b/plugins/exif-datetime-to-file/meson.build @@ -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 index 00000000..8b36cdd0 --- /dev/null +++ b/plugins/exif-datetime-to-file/org.geeqie.exif-datetime-to-file.desktop.in @@ -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 diff --git a/plugins/meson.build b/plugins/meson.build index 503c94c4..9e4ce5ff 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -12,6 +12,7 @@ # subdir('camera-import') +subdir('exif-datetime-to-file') subdir('export-jpeg') subdir('geocode-parameters') subdir('image-crop') -- 2.20.1