-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
dc81c0b
commit 18e4da7
Showing
1 changed file
with
44 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
} | ||
|
||
|
@@ -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 | ||
|
||
|