Skip to content

Commit

Permalink
fix(fujifilm_ratings.lua): improve the script and make it work again
Browse files Browse the repository at this point in the history
I don't know what changed, but it broke the previous iteration of the script. So I fixed it and improved it a bit.
  • Loading branch information
LucasGGamerM committed Jul 13, 2024
1 parent dc81c0b commit 18e4da7
Showing 1 changed file with 44 additions and 25 deletions.
69 changes: 44 additions & 25 deletions contrib/fujifilm_ratings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ local script_data = {}
script_data.metadata = {
name = "fujifilm_ratings",
purpose = _("import Fujifilm in-camera ratings"),
author = "Ben Mendis <[email protected]>",
author = "Ben Mendis <[email protected]> and LucasGGamerM <[email protected]>",
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/fujifilm_ratings"
}

Expand All @@ -54,35 +54,54 @@ script_data.restart = nil -- how to restart the (lib) script after it's been hid
script_data.show = nil -- only required for libs since the destroy_method only hides them

local function detect_rating(event, image)
if not string.match(image.filename, "%.RAF$") and not string.match(image.filename, "%.raf$") then
return
end
if not df.check_if_bin_exists("exiftool") then
dt.print_error(_("exiftool not found"))
return
end
local RAF_filename = df.sanitize_filename(tostring(image))
local JPEG_filename = string.gsub(RAF_filename, "%.RAF$", ".JPG")
local command = "exiftool -Rating " .. JPEG_filename
dt.print_log(command)
local output = dtsys.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)
dt.print_log("using JPEG rating: " .. jpeg_result)
return
if string.match(image.filename, "%.JPG$") or string.match(image.filename, "%.jpg$") then
local JPEG_filename = df.sanitize_filename(tostring(image))
local command = "exiftool -Rating " .. JPEG_filename
dt.print_log(command)
local output = dtsys.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)
return
end
end
command = "exiftool -Rating " .. RAF_filename
dt.print_log(command)
output = dtsys.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)
dt.print_log("using RAF rating: " .. raf_result)

if string.match(image.filename, "%.RAF$") or string.match(image.filename, "%.raf$") then
local RAF_filename = df.sanitize_filename(tostring(image))
local JPEG_filename
if string.match(RAF_filename, "%.RAF") then
JPEG_filename = string.gsub(RAF_filename, "%.RAF", ".JPG")
elseif string.match(RAF_filename, "%.raf") then
JPEG_filename = string.gsub(RAF_filename, "%.raf", ".jpg")
end
local command = "exiftool -Rating " .. JPEG_filename
dt.print_log(command)
local output = dtsys.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)
dt.print_log("using JPEG rating: " .. jpeg_result)
return
end

command = "exiftool -Rating " .. RAF_filename
dt.print_log(command)
output = dtsys.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)
dt.print_log("using RAF rating: " .. raf_result)
end
end
end

Expand Down

0 comments on commit 18e4da7

Please sign in to comment.