forked from darktable-org/lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_paste_metadata.lua
More file actions
129 lines (115 loc) · 3.42 KB
/
Copy pathcopy_paste_metadata.lua
File metadata and controls
129 lines (115 loc) · 3.42 KB
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
--[[
This file is part of darktable,
copyright (c) 2016 Tobias Ellinghaus
darktable 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.
darktable 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 darktable. If not, see <http://www.gnu.org/licenses/>.
]]
--[[
ADD SUPPORT FOR COPYING METADATA+RATING+COLOR LABELS+TAGS BETWEEN IMAGES
This script adds keyboard shortcuts and buttons to copy/paste metadata between images.
USAGE
* require this script from your main lua file
* it adds buttons to the selected images module
* it adds two keyboard shortcuts
]]
local dt = require "darktable"
local du = require "lib/dtutils"
du.check_min_api_version("3.0.0", "copy_paste_metadata")
-- set this to "false" if you don't want to overwrite metadata fields
-- (title, description, creator, publisher and rights) that are already set
local overwrite = true
local have_data = false
local rating = 1
local red = false
local green = false
local yellow = false
local blue = false
local purple = false
local title = ""
local description = ""
local creator = ""
local publisher = ""
local rights = ""
local tags = {}
local function copy(image)
if not image then
have_data = false
else
have_data = true
rating = image.rating
red = image.red
green = image.green
yellow = image.yellow
blue = image.blue
purple = image.purple
title = image.title
description = image.description
creator = image.creator
publisher = image.publisher
rights = image.rights
tags = {}
for _, tag in ipairs(image:get_tags()) do
if not (string.sub(tag.name, 1, string.len("darktable|")) == "darktable|") then
table.insert(tags, tag)
end
end
end
end
local function paste(images)
if have_data then
for _, image in ipairs(images) do
image.rating = rating
image.red = red
image.green = green
image.yellow = yellow
image.blue = blue
image.purple = purple
if image.title == "" or overwrite then
image.title = title
end
if image.description == "" or overwrite then
image.description = description
end
if image.creator == "" or overwrite then
image.creator = creator
end
if image.publisher == "" or overwrite then
image.publisher = publisher
end
if image.rights == "" or overwrite then
image.rights = rights
end
for _, tag in ipairs(tags) do
image:attach_tag(tag)
end
end
end
end
dt.gui.libs.image.register_action(
"copy metadata",
function(event, images) copy(images[1]) end,
"copy metadata of the first selected image"
)
dt.gui.libs.image.register_action(
"paste metadata",
function(event, images) paste(images) end,
"paste metadata to the selected images"
)
dt.register_event(
"shortcut",
function(event, shortcut) copy(dt.gui.action_images[1]) end,
"copy metadata"
)
dt.register_event(
"shortcut",
function(event, shortcut) paste(dt.gui.action_images) end,
"paste metadata"
)