Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fujifilm_ratings.lua): improve the script and make it work again #495

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 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 = 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