-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPWSendMetadata.lua
More file actions
128 lines (111 loc) · 4.82 KB
/
PWSendMetadata.lua
File metadata and controls
128 lines (111 loc) · 4.82 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
--[[
PWSendMetadata.lua
Copyright (C) 2024 Fiona Boston <fiona@fbphotography.uk>.
This file is part of PiwigoPublish
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/>.
]]
---@diagnostic disable: undefined-global
--*******************************************
local function SendMetadata()
log:info("SendMetadata")
local callStatus = {}
local catalog = LrApplication.activeCatalog()
local selPhotos = catalog:getTargetPhotos()
local sources = catalog:getActiveSources()
if utils.nilOrEmpty(selPhotos) then
LrDialogs.message("Please select photos to resend metadata", "", "warning")
return false
end
-- is source a LrPublishedCollection or LrPublishedCollectionSet in selected published service
local useService = nil
local useSource = nil
local catId = nil
local publishSettings = nil
for s, source in pairs(sources) do
if type(source) == "table" and source.type then
local srcType = source:type()
if srcType == "LrPublishedCollection" or srcType == "LrPublishedCollectionSet" then
local thisService = source:getService()
local thisSettings = thisService:getPublishSettings()
-- is this publish service using this plugin?
local thisPluginId = thisService:getPluginId()
if thisPluginId == _PLUGIN.id then
useService = thisService
useSource = source
catId = source:getRemoteId()
publishSettings = thisSettings
break
end
end
end
end
if not useService then
LrDialogs.message("Please select photos in a Piwigo Publisher service", "", "warning")
return false
end
if not publishSettings then
LrDialogs.message("SendMetadata - Can't find publish settings for this publish collection", "", "warning")
return false
end
if not useSource then
LrDialogs.message("SendMetadata - Can't find publish collection source", "", "warning")
return false
end
local result = LrDialogs.confirm("Send Metadata to Piwigo",
"Send metadata to Piwigo for " .. #selPhotos .. " photo(s) in album " .. useSource:getName() .. "?", "Ok",
"Cancel")
if result ~= 'ok' then
return false
end
local progressScope = LrProgressScope {
title = "Update Metadata...",
caption = "Starting...",
functionContext = context,
}
for pp, lrPhoto in pairs(selPhotos) do
if progressScope:isCanceled() then
break
end
progressScope:setPortionComplete(pp, #selPhotos)
progressScope:setCaption("Processing " .. pp .. " of " .. #selPhotos .. " photographs")
-- find publised photo in this collection / set
local thisPubPhoto = utils.findPhotoInCollectionSet(useSource, lrPhoto)
if not thisPubPhoto then
LrDialogs.message(
"SendMetadata - Can't find this photo in collection set or collections - has it been published?", "",
"warning")
progressScope:done()
return false
end
local remoteId = thisPubPhoto:getRemoteId()
if not remoteId then
LrDialogs.message("SendMetadata - Can't find Piwigo photo ID for this photo - has it been published?", "",
"warning")
progressScope:done()
return false
end
callStatus = {}
local metaData = {}
local collectionSettings = {}
-- todo - get collections for collection this photo is in so collection level overrides can be applied when building metadata structure
-- build metadata structure
metaData = utils.getPhotoMetadata(publishSettings, lrPhoto, collectionSettings)
metaData.Remoteid = remoteId
-- get keyword filters from publishSettings and build include / exclude patterns
callStatus = PiwigoAPI.updateMetadata(publishSettings, lrPhoto, metaData)
if not callStatus.status then
LrDialogs.message("Unable to set metadata for uploaded photo - " .. callStatus.statusMsg)
end
end
progressScope:done()
end
LrTasks.startAsyncTask(SendMetadata)