-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfujifilm_ratings.lua
76 lines (60 loc) · 2.34 KB
/
fujifilm_ratings.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--[[ fujifilm_ratings-0.1
Support for importing Fujifilm in-camera ratings in darktable.
Copyright (C) 2017 Ben Mendis <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Dependencies:
- exiftool (https://www.sno.phy.queensu.ca/~phil/exiftool/)
--]]
local dt = require "darktable"
local df = require "lib/dtutils.file"
local gettext = dt.gettext
dt.configuration.check_version(..., {4,0,0}, {5,0,0})
gettext.bindtextdomain("fujifilm_ratings", dt.configuration.config_dir.."/lua/locale/")
local function _(msgid)
return gettext.dgettext("fujifilm_ratings", msgid)
end
local function detect_rating(event, image)
if not df.check_if_bin_exists("exiftool") then
dt.print_error(_("exiftool not found"))
return
end
local rating = 0
local RAF_filename = tostring(image)
local JPEG_filename = string.gsub(RAF_filename, "%.RAF$", ".JPG")
local command = "exiftool -Rating " .. JPEG_filename
dt.print_error(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")
rating = tonumber(jpeg_result)
if rating > 0 then
image.rating = rating
dt.print_error(_("Using JPEG Rating: ") .. tostring(jpeg_result))
return
end
end
command = "exiftool -Rating " .. RAF_filename
dt.print_error(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_error(_("Using RAF Rating: ") .. tostring(raf_result))
end
end
dt.register_event("post-import-image", detect_rating)
print(_("fujifilm_ratings loaded."))