Improving with feedback from @supertobi

This commit is contained in:
Ben Mendis
2017-10-14 11:24:14 -04:00
parent 178528508b
commit 693c535428

View File

@@ -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."))