From 178528508ba5e491a92fea02ac6177b026bc989c Mon Sep 17 00:00:00 2001 From: Ben Mendis Date: Tue, 10 Oct 2017 21:10:00 -0400 Subject: [PATCH 1/2] Support for importing the in-camera ratings from Fujifilm cameras --- contrib/fujifilm_ratings.lua | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 contrib/fujifilm_ratings.lua diff --git a/contrib/fujifilm_ratings.lua b/contrib/fujifilm_ratings.lua new file mode 100644 index 0000000..926cf9a --- /dev/null +++ b/contrib/fujifilm_ratings.lua @@ -0,0 +1,56 @@ +--[[ fujifilm_ratings-0.1 + +Support for importing Fujifilm in-camera ratings in darktable. + +Copyright (C) 2017 Ben Mendis + +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 +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Dependencies: +- exiftool (https://www.sno.phy.queensu.ca/~phil/exiftool/) + +--]] + +darktable = require "darktable" + +local function detect_rating(event, image) + local RAF_filename = tostring(image) + local JPEG_filename = string.gsub(RAF_filename, "%.RAF$", ".JPG") + local command = "exiftool -Rating " .. JPEG_filename + darktable.print_error(command) + local output = io.popen(command) + local jpeg_result = output:read("*all") + output:close() + if string.len(jpeg_result) > 0 then + jpeg_result = string.gsub(jpeg_result, "^Rating.*(%d)", "%1") + image.rating = tonumber(jpeg_result) + darktable.print_error("Using JPEG Rating: " .. tostring(jpeg_result)) + return + end + command = "exiftool -Rating " .. RAF_filename + darktable.print_error(command) + output = io.popen(command) + local raf_result = output:read("*all") + output:close() + if string.len(raf_result) > 0 then + raf_result = string.gsub(raf_result, "^Rating.*(%d)", "%1") + image.rating = tonumber(raf_result) + darktable.print_error("Using RAF Rating: " .. tostring(raf_result)) + end +end + +darktable.register_event("post-import-image", detect_rating) + +darktable.print_error("fujifilm_ratings loaded.") From 693c535428ac7bca9aa7a7861a2932473ab42a32 Mon Sep 17 00:00:00 2001 From: Ben Mendis Date: Sat, 14 Oct 2017 11:24:14 -0400 Subject: [PATCH 2/2] Improving with feedback from @supertobi --- contrib/fujifilm_ratings.lua | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/contrib/fujifilm_ratings.lua b/contrib/fujifilm_ratings.lua index 926cf9a..e19ef79 100644 --- a/contrib/fujifilm_ratings.lua +++ b/contrib/fujifilm_ratings.lua @@ -23,34 +23,48 @@ Dependencies: --]] -darktable = require "darktable" +local dt = require "darktable" +local df = require "lib/dtutils.file" +local gettext = dt.gettext + +dt.configuration.check_version(..., {4,0,0}) + +gettext.bindtextdomain("fujifilm_ratings", dt.configuration.config_dir.."/lua/locale/") + +local function _(msgid) + return gettext.dgettext("fujifilm_ratings", msgid) +end local function detect_rating(event, image) + if not df.check_if_bin_exists("exiftool") then + dt.print_error(_("exiftool not found")) + return + end local RAF_filename = tostring(image) local JPEG_filename = string.gsub(RAF_filename, "%.RAF$", ".JPG") local command = "exiftool -Rating " .. JPEG_filename - darktable.print_error(command) + dt.print_error(command) local output = io.popen(command) local jpeg_result = output:read("*all") output:close() if string.len(jpeg_result) > 0 then jpeg_result = string.gsub(jpeg_result, "^Rating.*(%d)", "%1") image.rating = tonumber(jpeg_result) - darktable.print_error("Using JPEG Rating: " .. tostring(jpeg_result)) + dt.print_error(_("Using JPEG Rating: ") .. tostring(jpeg_result)) return end command = "exiftool -Rating " .. RAF_filename - darktable.print_error(command) + dt.print_error(command) output = io.popen(command) local raf_result = output:read("*all") output:close() if string.len(raf_result) > 0 then raf_result = string.gsub(raf_result, "^Rating.*(%d)", "%1") image.rating = tonumber(raf_result) - darktable.print_error("Using RAF Rating: " .. tostring(raf_result)) + dt.print_error(_("Using RAF Rating: ") .. tostring(raf_result)) end end -darktable.register_event("post-import-image", detect_rating) +dt.register_event("post-import-image", detect_rating) -darktable.print_error("fujifilm_ratings loaded.") +print(_("fujifilm_ratings loaded."))