Skip to content

Commit

Permalink
Merge pull request #19 from aviationphoto/v1.2
Browse files Browse the repository at this point in the history
v1.2
  • Loading branch information
aviationphoto authored Apr 8, 2017
2 parents a384d47 + c5058d2 commit 6a494a1
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 31 deletions.
9 changes: 6 additions & 3 deletions Filter Presets/Aircraft Metadata.lrtemplate
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ s = {
{
criteria = "sdktext:ch.aviationphoto.aircraftmetadata.airline",
},
{
criteria = "sdktext:ch.aviationphoto.aircraftmetadata.registration",
},
{
criteria = "sdktext:ch.aviationphoto.aircraftmetadata.aircraft_manufacturer",
},
{
criteria = "sdktext:ch.aviationphoto.aircraftmetadata.aircraft_type",
},
{
criteria = "sdktext:ch.aviationphoto.aircraftmetadata.registration",
},
{
criteria = "sdktext:ch.aviationphoto.aircraftmetadata.airport_iata",
},
{
criteria = "sdktext:ch.aviationphoto.aircraftmetadata.aircraft_notes",
},
Expand Down
23 changes: 19 additions & 4 deletions aircraft-metadata.lrplugin/AircraftMetadataLookup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ function AircraftMetadataImport()
if progressScope:isCanceled() then
messageEnd = 'Aircraft Metadata Lookup canceled'
else
-- read photo name
local photoFilename = photo:getFormattedMetadata('fileName')
-- read photo name for logging
-- check if we are working on a copy
if photo:getFormattedMetadata('copyName') == nil then
photoFilename = photo:getFormattedMetadata('fileName')
else
photoFilename = photo:getFormattedMetadata('fileName')..' ('..photo:getFormattedMetadata('copyName')..')'
end
-- read aircraft registration from photo
searchRegistration = photo:getPropertyForPlugin(_PLUGIN, 'registration')
-- do we have a registration?
if not (searchRegistration == '' or searchRegistration == nil) then
-- yes, photo has registration
local searchRegistration = trim(searchRegistration)
searchRegistration = string.upper(trim(searchRegistration))
-- is registration already in cache?
if not metadataCache[searchRegistration] then
-- no, we need to do a lookup
Expand Down Expand Up @@ -146,7 +151,7 @@ function AircraftMetadataImport()
end
foundAircraftType = trim(string.sub(foundAircraft, string.len(foundAircraftManufacturer)+1, string.len(foundAircraft)))
-- cache found metadata
metadataCache[searchRegistration] = {foundRegistration = foundRegistration, foundAirline = foundAirline, foundAircraft = foundAircraft, foundAircraftManufacturer = foundAircraftManufacturer, foundAircraftType = foundAircraftType}
metadataCache[searchRegistration] = {foundRegistration = foundRegistration, foundAirline = foundAirline, foundAircraft = foundAircraft, foundAircraftManufacturer = foundAircraftManufacturer, foundAircraftType = foundAircraftType, lookupURL = lookupURL}
logger:info(photoFilename..' - metadata found: Reg: '..foundRegistration..', Airline: '..foundAirline..', Manufacturer: '..foundAircraftManufacturer..', Type: '..foundAircraftType)
else
-- no, lookup returned wrong registration
Expand All @@ -165,6 +170,14 @@ function AircraftMetadataImport()
-- write metadata to photo
catalog:withWriteAccessDo('set aircraft metadata',
function()
-- check if user allows overwrite of existing registration metadata
if photo:getPropertyForPlugin(_PLUGIN, 'registration') == nil then
photo:setPropertyForPlugin(_PLUGIN, 'registration', metadataCache[searchRegistration].foundRegistration)
else
if prefs.prefFlagOverwrite then
photo:setPropertyForPlugin(_PLUGIN, 'registration', metadataCache[searchRegistration].foundRegistration)
end
end
-- check if user allows overwrite of existing airline metadata
if photo:getPropertyForPlugin(_PLUGIN, 'airline') == nil then
photo:setPropertyForPlugin(_PLUGIN, 'airline', metadataCache[searchRegistration].foundAirline)
Expand All @@ -189,6 +202,8 @@ function AircraftMetadataImport()
photo:setPropertyForPlugin(_PLUGIN, 'aircraft_type', metadataCache[searchRegistration].foundAircraftType)
end
end
-- set aircraft url - we overwrite this in any case
photo:setPropertyForPlugin(_PLUGIN, 'aircraft_url', metadataCache[searchRegistration].lookupURL)
-- remove reg_not_found if set
photo:removeKeyword(keyword)
end)
Expand Down
146 changes: 146 additions & 0 deletions aircraft-metadata.lrplugin/AircraftUrlUpdate.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
--[[----------------------------------------------------------------------------
AircraftUrlUpdate.lua
This file is part of LR Aircraft Metadata.
Copyright(c) 2017, aviationphoto
LR Aircraft Metadata 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.
LR Aircraft Metadata 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 LR Aircraft Metadata. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------]]
local LrApplication = import 'LrApplication'
local LrFunctionContext = import 'LrFunctionContext'
local LrDialogs = import 'LrDialogs'
local LrFileUtils = import 'LrFileUtils'
local LrPathUtils = import 'LrPathUtils'
local LrProgressScope = import 'LrProgressScope'
local LrErrors = import 'LrErrors'
local prefs = import 'LrPrefs'.prefsForPlugin()

local AircraftUrlUpdate = {}

local logger = import 'LrLogger'('AircraftUrlUpdate')

function AircraftUrlUpdate()
LrFunctionContext.callWithContext( "Aircraft Metadata Import", function(context)
-- define progress bar
local progressScope = LrProgressScope({title = 'Aircraft URL Update'})
progressScope:setCancelable(true)
-- cleanup if error is thrown
context:addCleanupHandler(function()
progressScope:done()
end)
local messageEnd = 'Aircraft URL Update finished'

local countSelected = 0
local countProcessed = 0
local countSkipped = 0

local flagRun = true

-- check if logging enabled
if prefs.prefFlagLogging then
logger:enable('logfile')
clearLogfile()
else
logger:disable()
end

logger:info('>>>> running url update')

-- lookup URL
if (prefs.prefLookupUrl == nil or prefs.prefLookupUrl == '') then
LrErrors.throwUserError('Please set URL for lookup')
else
lookupURL = trim(prefs.prefLookupUrl)
end

-- get a reference to the photos within the current catalog
local catalog = LrApplication.activeCatalog()
local selectedPhotos = catalog:getTargetPhotos()

-- check if user selected at least one photos
if catalog:getTargetPhoto() == nil then
local dialogAction = LrDialogs.confirm('Aircraft URL Update', 'No photo selected - run update on all photos in filmstrip?', 'Yes', 'No')
if dialogAction == 'cancel' then
-- cleanup if canceled by user
flagRun = false
progressScope:done()
messageEnd = 'Aircraft URL Update canceled'
logger:info('no active photo selection - user canceled run on entire filmstrip')
end
end

-- check if user hit cancel in dialog
if flagRun then
-- count selected photos
for _ in pairs(selectedPhotos) do
countSelected = countSelected + 1
end
logger:info('performing update on '..countSelected..' selected photos')
for _, photo in ipairs (selectedPhotos) do
countProcessed = countProcessed + 1
-- read photo name for logging
-- check if we are working on a copy
if photo:getFormattedMetadata('copyName') == nil then
photoFilename = photo:getFormattedMetadata('fileName')
else
photoFilename = photo:getFormattedMetadata('fileName')..' ('..photo:getFormattedMetadata('copyName')..')'
end
-- check if a registration is set
if photo:getPropertyForPlugin(_PLUGIN, 'registration') == nil then
-- photo has no url
logger:info(photoFilename..' - skipped: no registration set')
countSkipped = countSkipped + 1
else
-- check if url is set
if photo:getPropertyForPlugin(_PLUGIN, 'aircraft_url') == nil then
-- photo has no registration
logger:info(photoFilename..' - skipped: no url set')
countSkipped = countSkipped + 1
else
-- looks good, do the update
oldURL = photo:getPropertyForPlugin(_PLUGIN, 'aircraft_url')
newURL = lookupURL..trim(photo:getPropertyForPlugin(_PLUGIN, 'registration'))
catalog:withWriteAccessDo('set aircraft metadata',
function()
photo:setPropertyForPlugin(_PLUGIN, 'aircraft_url', newURL)
end)
logger:info(photoFilename..' - url updated: '..oldURL..' --> '..newURL)
end
end
progressScope:setPortionComplete(countProcessed, countSelected)
end
end
progressScope:done()
logger:info('processed '..countProcessed..' photos ('..countSkipped..' skipped)')
LrDialogs.showBezel(messageEnd)
logger:info('>>>> lookup done')
end)
end

-- remove trailing and leading whitespace from string
function trim(s)
return (s:gsub('^%s*(.-)%s*$', '%1'))
end

-- clear old logfile
function clearLogfile()
local logPath = LrPathUtils.child(LrPathUtils.getStandardFilePath('documents'), 'AircraftUrlUpdate.log')
if LrFileUtils.exists( logPath ) then
success, reason = LrFileUtils.delete( logPath )
if not success then
logger:error('error deleting existing logfile!'..reason)
end
end
end

import 'LrTasks'.startAsyncTask(AircraftUrlUpdate)
12 changes: 10 additions & 2 deletions aircraft-metadata.lrplugin/Info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
along with LR Aircraft Metadata. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------]]
return {
LrSdkVersion = 5.0,
VERSION = {major=1, minor=1, revision=2,},
LrSdkVersion = 6.0,
VERSION = {major=1, minor=2, revision=0,},

LrPluginName = 'Aircraft Metadata',
LrToolkitIdentifier = 'ch.aviationphoto.aircraftmetadata',
Expand All @@ -37,13 +37,21 @@ return {
title = 'Lookup Aircraft Metadata',
file = 'AircraftMetadataLookup.lua',
},
{
title = 'Update Aircraft URL',
file = 'AircraftUrlUpdate.lua',
},
},
--show in library menu
LrLibraryMenuItems = {
{
title = 'Lookup Aircraft Metadata',
file = 'AircraftMetadataLookup.lua',
},
{
title = 'Update Aircraft URL',
file = 'AircraftUrlUpdate.lua',
},
},

}
4 changes: 3 additions & 1 deletion aircraft-metadata.lrplugin/MetadataProvider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ You should have received a copy of the GNU General Public License
along with LR Aircraft Metadata. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------]]
return {
schemaVersion = 6,
schemaVersion = 15,

metadataFieldsForPhotos = {
{dataType='string', searchable=true, browsable=true, id='registration', title='Registration'},
{dataType='string', searchable=true, browsable=true, id='aircraft_manufacturer', title='Manufacturer'},
{dataType='string', searchable=true, browsable=true, id='aircraft_type', title='Type'},
{dataType='string', searchable=true, browsable=true, id='aircraft_notes', title='Notes'},
{dataType='string', searchable=true, browsable=true, id='airline', title='Airline'},
{dataType='url', searchable=false, browsable=false, readOnly=true, id='aircraft_url', title='Aircraft URL'},
{dataType='string', searchable=true, browsable=true, id='airport_iata', title='Airport (IATA)'},
--{dataType='string', searchable=true, browsable=true, id='flight', title='Flight'},
--{dataType='string', searchable=true, browsable=true, id='flight_from', title='from'},
--{dataType='string', searchable=true, browsable=true, id='flight_to', title='to'},
Expand Down
20 changes: 13 additions & 7 deletions aircraft-metadata.lrplugin/MetadataTagset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@ return {
id = 'ch.aviationphoto.aircraftmetadatatagset',

items = {
{formatter = 'com.adobe.title', height_in_lines=3},
{formatter = 'com.adobe.caption', height_in_lines=3},
'com.adobe.separator',
--{formatter = 'com.adobe.title', height_in_lines=3},
--{formatter = 'com.adobe.caption', height_in_lines=3},
--'com.adobe.separator',
{formatter = "com.adobe.label", label = "Aircraft",},
'ch.aviationphoto.aircraftmetadata.registration',
'ch.aviationphoto.aircraftmetadata.airline',
'ch.aviationphoto.aircraftmetadata.aircraft_manufacturer',
'ch.aviationphoto.aircraftmetadata.aircraft_type',
'ch.aviationphoto.aircraftmetadata.aircraft_notes',
'ch.aviationphoto.aircraftmetadata.aircraft_url',
'com.adobe.separator',
'ch.aviationphoto.aircraftmetadata.flight',
'ch.aviationphoto.aircraftmetadata.flight_from',
'ch.aviationphoto.aircraftmetadata.flight_to',
{formatter = "com.adobe.label", label = "Location",},
'ch.aviationphoto.aircraftmetadata.airport_iata',
--'com.adobe.separator',
--{formatter = "com.adobe.label", label = "Flight",},
--'ch.aviationphoto.aircraftmetadata.flight',
--'ch.aviationphoto.aircraftmetadata.flight_from',
--'ch.aviationphoto.aircraftmetadata.flight_to',
}
};
};
Loading

0 comments on commit 6a494a1

Please sign in to comment.