Skip to content

Commit 18e4da7

Browse files
authored
fix(fujifilm_ratings.lua): improve the script and make it work again
I don't know what changed, but it broke the previous iteration of the script. So I fixed it and improved it a bit.
1 parent dc81c0b commit 18e4da7

1 file changed

Lines changed: 44 additions & 25 deletions

File tree

contrib/fujifilm_ratings.lua

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ local script_data = {}
4444
script_data.metadata = {
4545
name = "fujifilm_ratings",
4646
purpose = _("import Fujifilm in-camera ratings"),
47-
author = "Ben Mendis <ben.mendis@gmail.com>",
47+
author = "Ben Mendis <ben.mendis@gmail.com> and LucasGGamerM <LucasGGamerM@protonmail.com>",
4848
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/fujifilm_ratings"
4949
}
5050

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

5656
local function detect_rating(event, image)
57-
if not string.match(image.filename, "%.RAF$") and not string.match(image.filename, "%.raf$") then
58-
return
59-
end
6057
if not df.check_if_bin_exists("exiftool") then
6158
dt.print_error(_("exiftool not found"))
6259
return
6360
end
64-
local RAF_filename = df.sanitize_filename(tostring(image))
65-
local JPEG_filename = string.gsub(RAF_filename, "%.RAF$", ".JPG")
66-
local command = "exiftool -Rating " .. JPEG_filename
67-
dt.print_log(command)
68-
local output = dtsys.io_popen(command)
69-
local jpeg_result = output:read("*all")
70-
output:close()
71-
if string.len(jpeg_result) > 0 then
72-
jpeg_result = string.gsub(jpeg_result, "^Rating.*(%d)", "%1")
73-
image.rating = tonumber(jpeg_result)
74-
dt.print_log("using JPEG rating: " .. jpeg_result)
75-
return
61+
if string.match(image.filename, "%.JPG$") or string.match(image.filename, "%.jpg$") then
62+
local JPEG_filename = df.sanitize_filename(tostring(image))
63+
local command = "exiftool -Rating " .. JPEG_filename
64+
dt.print_log(command)
65+
local output = dtsys.io_popen(command)
66+
local jpeg_result = output:read("*all")
67+
output:close()
68+
if string.len(jpeg_result) > 0 then
69+
jpeg_result = string.gsub(jpeg_result, "^Rating.*(%d)", "%1")
70+
image.rating = tonumber(jpeg_result)
71+
return
72+
end
7673
end
77-
command = "exiftool -Rating " .. RAF_filename
78-
dt.print_log(command)
79-
output = dtsys.io_popen(command)
80-
local raf_result = output:read("*all")
81-
output:close()
82-
if string.len(raf_result) > 0 then
83-
raf_result = string.gsub(raf_result, "^Rating.*(%d)", "%1")
84-
image.rating = tonumber(raf_result)
85-
dt.print_log("using RAF rating: " .. raf_result)
74+
75+
if string.match(image.filename, "%.RAF$") or string.match(image.filename, "%.raf$") then
76+
local RAF_filename = df.sanitize_filename(tostring(image))
77+
local JPEG_filename
78+
if string.match(RAF_filename, "%.RAF") then
79+
JPEG_filename = string.gsub(RAF_filename, "%.RAF", ".JPG")
80+
elseif string.match(RAF_filename, "%.raf") then
81+
JPEG_filename = string.gsub(RAF_filename, "%.raf", ".jpg")
82+
end
83+
local command = "exiftool -Rating " .. JPEG_filename
84+
dt.print_log(command)
85+
local output = dtsys.io_popen(command)
86+
local jpeg_result = output:read("*all")
87+
output:close()
88+
if string.len(jpeg_result) > 0 then
89+
jpeg_result = string.gsub(jpeg_result, "^Rating.*(%d)", "%1")
90+
image.rating = tonumber(jpeg_result)
91+
dt.print_log("using JPEG rating: " .. jpeg_result)
92+
return
93+
end
94+
95+
command = "exiftool -Rating " .. RAF_filename
96+
dt.print_log(command)
97+
output = dtsys.io_popen(command)
98+
local raf_result = output:read("*all")
99+
output:close()
100+
if string.len(raf_result) > 0 then
101+
raf_result = string.gsub(raf_result, "^Rating.*(%d)", "%1")
102+
image.rating = tonumber(raf_result)
103+
dt.print_log("using RAF rating: " .. raf_result)
104+
end
86105
end
87106
end
88107

0 commit comments

Comments
 (0)