Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented album option: Folder based in export module. #43

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions immich-plugin.lrplugin/ExportDialogSections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function ExportDialogSections.sectionsForTopOfDialog(_, propertyTable)
{ title = 'Choose on export', value = 'onexport' },
{ title = 'Existing album', value = 'existing' },
{ title = 'Create new album', value = 'new' },
{ title = 'Create/use folder name as album', value = 'folder' },
{ title = 'Do not use an album', value = 'none' },
},
value = bind 'albumMode',
Expand Down
9 changes: 9 additions & 0 deletions immich-plugin.lrplugin/ExportTask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function ExportTask.processRenderedPhotos(functionContext, exportContext)
{ title = 'Do not use an album', value = 'none' },
{ title = 'Existing album', value = 'existing' },
{ title = 'Create new album', value = 'new' },
{ title = 'Create/use folder name as album', value = 'folder' },
},
value = LrView.bind('albumMode'),
immediate = true,
Expand Down Expand Up @@ -132,6 +133,8 @@ function ExportTask.processRenderedPhotos(functionContext, exportContext)
useAlbum = true
elseif exportParams.albumMode == 'none' then
log:trace('Not using any albums, just uploading assets.')
elseif exportParams.albumMode == 'folder' then
log:trace('Create/use folder name as album.')
else
log:trace('Unknown albumMode: ' .. exportParams.albumMode .. '. Ignoring.')
end
Expand Down Expand Up @@ -167,6 +170,12 @@ function ExportTask.processRenderedPhotos(functionContext, exportContext)
if useAlbum then
log:trace('Adding asset to album')
immich:addAssetToAlbum(albumId, id)
elseif exportParams.albumMode == 'folder' then
local folderName = rendition.photo:getFormattedMetadata("folderName")
local folderAlbumId = immich:createOrGetAlbumFolderBased(folderName)
if folderAlbumId ~= nil then
immich:addAssetToAlbum(folderAlbumId, id)
end
end
end

Expand Down
44 changes: 44 additions & 0 deletions immich-plugin.lrplugin/ImmichAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,31 @@ function ImmichAPI:createAlbum(albumName)
return nil
end


function ImmichAPI:createOrGetAlbumFolderBased(albumName)
if util.nilOrEmpty(albumName) then
util.handleError('createAlbum: albumName empty', 'No album name given. Check logs.')
return nil
end

local existingAlbums = ImmichAPI:getAlbumsByNameFolderBased(albumName)
if existingAlbums ~= nil then
if #existingAlbums > 0 then
log:trace("Found existing folder based album with id: " .. existingAlbums[1].value)
return existingAlbums[1].value
end
end

local apiPath = '/albums'
local postBody = { albumName = albumName, description = 'Based on Lightroom folder: ' .. albumName }

local parsedResponse = ImmichAPI.doPostRequest(self, apiPath, postBody)
if parsedResponse ~= nil then
return parsedResponse.id
end
return nil
end

function ImmichAPI:deleteAlbum(albumId)
local path = '/albums/' .. albumId

Expand Down Expand Up @@ -349,6 +374,25 @@ function ImmichAPI:getAlbums()
end
end


function ImmichAPI:getAlbumsByNameFolderBased(albumName)
local path = '/albums'
local parsedResponse = ImmichAPI.doGetRequest(self, path)
local albums = {}
if parsedResponse then
for i = 1, #parsedResponse do
local row = parsedResponse[i]
if row.albumName == albumName and row.description == 'Based on Lightroom folder: ' .. albumName then
table.insert(albums,
{ title = row.albumName .. ' (' .. string.sub(row.createdAt, 1, 19) .. ')', value = row.id })
end
end
return albums
else
return nil
end
end

function ImmichAPI:getActivities(albumId, assetId)
local path = '/activities?albumId=' .. albumId

Expand Down