From 18e4da7bbfa426cbbd64844f1f878cf55a99d01c Mon Sep 17 00:00:00 2001 From: LucasGGamerM <71328265+LucasGGamerM@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:36:16 -0300 Subject: [PATCH] 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. --- contrib/fujifilm_ratings.lua | 69 +++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/contrib/fujifilm_ratings.lua b/contrib/fujifilm_ratings.lua index b2f11fe3..10001a17 100644 --- a/contrib/fujifilm_ratings.lua +++ b/contrib/fujifilm_ratings.lua @@ -44,7 +44,7 @@ local script_data = {} script_data.metadata = { name = "fujifilm_ratings", purpose = _("import Fujifilm in-camera ratings"), - author = "Ben Mendis ", + author = "Ben Mendis and LucasGGamerM ", help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/fujifilm_ratings" } @@ -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