forked from darktable-org/lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexiftool_export.lua
165 lines (115 loc) · 4.55 KB
/
exiftool_export.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
--[[
This file is part of darktable,
copyright 2016 by Christian Kanzian.
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 3 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, see <http://www.gnu.org/licenses/>.
]]
--[[
EXIFTOOL ACTIONS ON EXPORT
This script adds a new UI element in the lighttable mode beyond the export modul.
If the tickbox is checked the script calls the 'exiftool' with the selected command line options on currently exported images.
The original exported image will be overwritten. Following options are selectable:
* -XMP-dc:Subject > IPTC:Keywords -> will copy tags from xmp to IPTC
* -XMP:all= -> remove darktable history
* -all= -> remove all metadata
* -@ -> load ARGuments from text file which contains several options line by line.
ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT
* exiftool - from Phil Harvey http://www.sno.phy.queensu.ca/~phil/exiftool/.
Linux distribtions typically ship this as a package.
Please check if it is installed.
LIMITATIONS
You can not save any presets.
INSTALATION
* copy this file in $CONFIGDIR/lua/ where CONFIGDIR is your darktable configuration directory
* add the following line in the file $CONFIGDIR/luarc require "exiftool_export"
USAGE
]]
local dt = require "darktable"
dt.configuration.check_version(...,{3,0,0},{4,0,0},{5,0,0})
-- function copied from hugin.lua
local function checkIfBinExists(bin)
local handle = io.popen("which "..bin)
local result = handle:read()
local ret
handle:close()
if (result) then
dt.print_error("true checkIfBinExists: "..bin)
ret = true
else
dt.print_error(bin.." not found")
ret = false
end
return ret
end
if not checkIfBinExists("exiftool") then
dt.print_error("exiftool not found")
return
end
local exiftool_enable = dt.new_widget("check_button") { label = "enable exiftool" }
-- TODO: add another checkbox to switch the overwrite option on/off
--local exif_overwrite_img = dt.new_widget("check_button") { label = "overwrite original"}
local cmd_options = dt.new_widget("combobox"){
label = "options:",
tooltip = "-XMP-dc:Subject > IPTC:Keywords -> will copy tags from xmp to IPTC\n-XMP:all= -> remove darktable history\n-all= -> remove all metadata\n-@ -> load ARGuments file"}
cmd_options[1] = "-XMP-dc:Subject > IPTC:Keywords"
cmd_options[2] = "-XMP:all="
cmd_options[3] = "-all="
cmd_options[4] = "-@"
cmd_options.editable = "TRUE"
-- add file chooser button for the '-@' option
local arg_file_label = dt.new_widget("label"){
label = "Argumentsfile",
halign = "start"
}
local arg_file = dt.new_widget("file_chooser_button"){
title = "Please choose an arguments file"
}
local exif_widget = dt.new_widget("box"){
orientation = horizontal,
-- exif_overwrite_img
exiftool_enable,
cmd_options,
arg_file_label,
arg_file
}
dt.register_lib("exiftool_ui","exiftool on export",true,false,{
[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 0}
}, exif_widget
);
-- function to build command
local function exiftool_call(img)
local exif_cmd
local imgexp = tostring(img)
print(imgexp)
if (cmd_options.value == "-@") then
--check if argumentsfile
dt.print_error(tostring(arg_file.value))
if (arg_file.value == nil)
then
dt.print("Command exiftool on export failed: Please select an arguments file!")
return
end
exif_cmd = "exiftool "..tostring(cmd_options.value).." '"..arg_file.value.."'".." -overwrite_original ".."'" .. imgexp .. "'"
else
exif_cmd = "exiftool ".."'"..tostring(cmd_options.value).."'".." -overwrite_original ".."'" .. imgexp .. "'"
end
return exif_cmd
end
-- final call exiftool if enabled on export events
dt.register_event("intermediate-export-image", function(event,img,filename)
if not exiftool_enable.value == true then
return
end
local cmd = exiftool_call(filename)
dt.print("Call "..cmd)
dt.control.execute(cmd)
end
)