forked from 500px/500pxPublisher.lrplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginInit.lua
executable file
·95 lines (80 loc) · 2.91 KB
/
PluginInit.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
PluginInit = {}
local LrDate = import "LrDate"
local LrDialogs = import "LrDialogs"
local LrHttp = import "LrHttp"
local LrFunctionContext = import "LrFunctionContext"
local LrTasks = import "LrTasks"
local logger = import "LrLogger"("500pxPublisher")
logger:enable("logfile")
local lastCheck = 0
-- Deprecated
-- function PluginInit.checkForUpdates()
-- LrFunctionContext.postAsyncTaskWithContext( "update check", function(context)
-- local time = LrDate.currentTime()
-- if time - lastCheck >= 86400 then
-- local response, headers = LrHttp.get( "https://api.500px.com/v1/version/lightroom" )
-- if headers and headers.status == 200 then
-- lastCheck = time
-- Plugin.outOfDate = (tostring( string.gsub( response, "%s+", "" ) ) == "0.1.8.0" )
-- end
-- end
-- end )
-- end
function PluginInit.forceNewCollections()
local LrApplication = import "LrApplication"
LrFunctionContext.postAsyncTaskWithContext( "New Collections", function(context)
local catalog = LrApplication:activeCatalog()
for _, publishService in ipairs( catalog:getPublishServices( _PLUGIN.id ) ) do
local allPhotosCollection
local profileCollection
catalog:withPrivateWriteAccessDo( "New Collections", function()
for _, collection in ipairs( publishService:getChildCollections() ) do
if collection:getName() == "Library" or collection:getName() == "Organizer" then
collection:setName( "Library" )
collection:setCollectionSettings( { toCummunity = false } )
allPhotosCollection = collection
end
end
profileCollection = publishService:createPublishedCollection( "Public Profile", nil, false )
if profileCollection then
profileCollection:setCollectionSettings( { toCummunity = true } )
end
end )
if profileCollection then
catalog:withWriteAccessDo( "", function()
for _, collection in ipairs( publishService:getChildCollections() ) do
local isAllPhotos = ( collection:getName() == "Library" )
for _, publishedPhoto in ipairs( collection:getPublishedPhotos() ) do
local photoId
local photoUrl
local photo = publishedPhoto:getPhoto()
catalog:withReadAccessDo( function()
photoId = photo:getPropertyForPlugin( _PLUGIN, "photoId" )
photoUrl = string.format( "http://500px.com/photo/%s", photoId )
end )
if isAllPhotos then
profileCollection:addPhotoByRemoteId( photo, string.format( "%s-profile", photoId ), photoUrl, true )
else
allPhotosCollection:addPhotoByRemoteId( photo, string.format( "%s-nil", photoId ), photoUrl, true )
end
end
end
end )
end
end
end )
end
local locked = false
function PluginInit.lock()
local delay = 0.1
repeat
LrTasks.sleep( delay )
delay = delay * 2
until not locked
locked = true
return true
end
function PluginInit.unlock( )
locked = false
end
PluginInit.outOfDate = false