From c4b013c9149190691463e7c76c51b20fb4af824e Mon Sep 17 00:00:00 2001 From: aviationphoto Date: Thu, 13 Apr 2017 22:08:10 +0200 Subject: [PATCH 1/3] set version to v1.3.2 --- aircraft-metadata.lrplugin/Info.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aircraft-metadata.lrplugin/Info.lua b/aircraft-metadata.lrplugin/Info.lua index 42a97e6..da96ddb 100644 --- a/aircraft-metadata.lrplugin/Info.lua +++ b/aircraft-metadata.lrplugin/Info.lua @@ -18,7 +18,7 @@ along with LR Aircraft Metadata. If not, see . ------------------------------------------------------------------------------]] return { LrSdkVersion = 6.0, - VERSION = {major=1, minor=3, revision=1,}, + VERSION = {major=1, minor=3, revision=2,}, LrPluginName = 'Aircraft Metadata', LrToolkitIdentifier = 'ch.aviationphoto.aircraftmetadata', From b37fbd52f6d6512ab4e0bafc0fd130a5eecf5232 Mon Sep 17 00:00:00 2001 From: aviationphoto Date: Thu, 13 Apr 2017 22:08:32 +0200 Subject: [PATCH 2/3] improved keywords --- aircraft-metadata.lrplugin/InitPlugin.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aircraft-metadata.lrplugin/InitPlugin.lua b/aircraft-metadata.lrplugin/InitPlugin.lua index 9a1e469..0ce3702 100644 --- a/aircraft-metadata.lrplugin/InitPlugin.lua +++ b/aircraft-metadata.lrplugin/InitPlugin.lua @@ -24,10 +24,10 @@ if prefs.prefFlagOverwrite == nil then prefs.prefFlagOverwrite = false end if prefs.prefKeywordRegNotFound == nil or prefs.prefKeywordRegNotFound == '' then - prefs.prefKeywordRegNotFound = 'RegNotFound' + prefs.prefKeywordRegNotFound = 'AircraftMetadata-RegNotFound' end if prefs.prefKeywordWrongReg == nil or prefs.prefKeywordWrongReg == '' then - prefs.prefKeywordWrongReg = 'WronReg' + prefs.prefKeywordWrongReg = 'AircraftMetadata-WrongReg' end if prefs.prefLookupUrl == nil or prefs.prefLookupUrl == '' then prefs.prefLookupUrl = 'https://www.jetphotos.com/showphotos.php?regsearch=' From 16ec8b5fd316725aabba8b4640b27868fdf6c3c5 Mon Sep 17 00:00:00 2001 From: aviationphoto Date: Thu, 13 Apr 2017 22:28:53 +0200 Subject: [PATCH 3/3] prevent lookup for searching a wrong reg again and again --- .../AircraftMetadataLookup.lua | 100 ++++++++++-------- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/aircraft-metadata.lrplugin/AircraftMetadataLookup.lua b/aircraft-metadata.lrplugin/AircraftMetadataLookup.lua index 6abee3e..10cc8d0 100644 --- a/aircraft-metadata.lrplugin/AircraftMetadataLookup.lua +++ b/aircraft-metadata.lrplugin/AircraftMetadataLookup.lua @@ -30,6 +30,7 @@ function AircraftMetadataImport() local selectedPhotos = catalog:getTargetPhotos() local messageEnd = 'Aircraft Metadata Lookup finished' local metadataCache = {} + local regNotFoundCache = {} local countSelected = 0 local countProcessed = 0 local countCacheHit = 0 @@ -101,55 +102,70 @@ function AircraftMetadataImport() if not (searchRegistration == '' or searchRegistration == nil) then -- yes, photo has registration searchRegistration = string.upper(LrStringUtils.trimWhitespace(searchRegistration)) - -- is registration already in cache? - if not metadataCache[searchRegistration] then - -- no, we need to do a lookup - countLookup = countLookup + 1 - lookupURL = LrStringUtils.trimWhitespace(LrPrefs.prefLookupUrl)..searchRegistration - LrLogger:info(photoFilename..' - looking up registration at '..lookupURL..' for: '..searchRegistration) - -- do the lookup - content = LrHttp.get(lookupURL) - --LrDialogs.message(photoFilename, content, 'info') - -- check if lookup returned something usefull - if string.find(content, LrPrefs.prefSuccessfulSearch) == nil then - -- lookup returned nothing usefull - countRegNotFound = countRegNotFound + 1 - flagRegFound = false - LrLogger:warn(photoFilename..' - REG NOT FOUND: no metadata found for registration '..searchRegistration) - -- mark photo with keyword reg_not_found - catalog:withWriteAccessDo('set keyword', - function() - photo:addKeyword(keywordRegNotFound) - end) - else - -- lookup returned something usefull - foundRegistration = extractMetadata(content, LrPrefs.prefRegistrationToken1, LrPrefs.prefRegistrationToken2) - -- check if lookup returned the right registration - if searchRegistration == foundRegistration then - -- yes, isolate metadata - foundAirline = extractMetadata(content, LrPrefs.prefAirlineToken1, LrPrefs.prefAirlineToken2) - foundAircraft = extractMetadata(content, LrPrefs.prefAircraftToken1, LrPrefs.prefAircraftToken2) - foundAircraftManufacturer = extractMetadata(content, LrPrefs.prefManufacturerToken1, LrPrefs.prefManufacturerToken2) - foundAircraftType = LrStringUtils.trimWhitespace(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, lookupURL = lookupURL} - LrLogger:info(photoFilename..' - metadata found: Reg: '..foundRegistration..', Airline: '..foundAirline..', Manufacturer: '..foundAircraftManufacturer..', Type: '..foundAircraftType) - else - -- no, lookup returned wrong registration - LrLogger:warn(photoFilename..' - WRONG REG: lookup returned wrong registration: '..foundRegistration..' instead of '..searchRegistration) - countNoReg = countNoReg + 1 + -- check if a previous lookup returnded a error for this registration + if not regNotFoundCache[searchRegistration] then + -- no, check if registration is already in cache + if not metadataCache[searchRegistration] then + -- no, we need to do a lookup + countLookup = countLookup + 1 + lookupURL = LrStringUtils.trimWhitespace(LrPrefs.prefLookupUrl)..searchRegistration + LrLogger:info(photoFilename..' - looking up registration at '..lookupURL..' for: '..searchRegistration) + -- do the lookup + content = LrHttp.get(lookupURL) + --LrDialogs.message(photoFilename, content, 'info') + -- check if lookup returned something useful + if string.find(content, LrPrefs.prefSuccessfulSearch) == nil then + -- lookup returned nothing useful + countRegNotFound = countRegNotFound + 1 flagRegFound = false - -- mark photo with keyword wrong_reg + LrLogger:warn(photoFilename..' - REG NOT FOUND: no metadata found for registration '..searchRegistration) + -- mark photo with keyword reg_not_found catalog:withWriteAccessDo('set keyword', function() - photo:addKeyword(keywordWrongReg) + photo:addKeyword(keywordRegNotFound) end) + -- cache registration to prevent further lookups + regNotFoundCache[searchRegistration] = {searchRegistration = searchRegistration} + else + -- yes, lookup returned something useful + foundRegistration = extractMetadata(content, LrPrefs.prefRegistrationToken1, LrPrefs.prefRegistrationToken2) + -- check if lookup returned the right registration + if searchRegistration == foundRegistration then + -- yes, isolate metadata + foundAirline = extractMetadata(content, LrPrefs.prefAirlineToken1, LrPrefs.prefAirlineToken2) + foundAircraft = extractMetadata(content, LrPrefs.prefAircraftToken1, LrPrefs.prefAircraftToken2) + foundAircraftManufacturer = extractMetadata(content, LrPrefs.prefManufacturerToken1, LrPrefs.prefManufacturerToken2) + foundAircraftType = LrStringUtils.trimWhitespace(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, lookupURL = lookupURL} + LrLogger:info(photoFilename..' - metadata found: Reg: '..foundRegistration..', Airline: '..foundAirline..', Manufacturer: '..foundAircraftManufacturer..', Type: '..foundAircraftType) + else + -- no, lookup returned wrong registration + LrLogger:warn(photoFilename..' - WRONG REG: lookup returned wrong registration: '..foundRegistration..' instead of '..searchRegistration) + countNoReg = countNoReg + 1 + flagRegFound = false + -- mark photo with keyword wrong_reg + catalog:withWriteAccessDo('set keyword', + function() + photo:addKeyword(keywordWrongReg) + end) + end end + else + -- yes, use cached metadata + LrLogger:info(photoFilename..' - using cached metadata for: '..metadataCache[searchRegistration].foundRegistration) + countCacheHit = countCacheHit + 1 end else - -- yes, use cached metadata - LrLogger:info(photoFilename..' - using cached metadata for: '..metadataCache[searchRegistration].foundRegistration) - countCacheHit = countCacheHit + 1 + -- yes, a previous lookup returned nothing useful + countRegNotFound = countRegNotFound + 1 + flagRegFound = false + LrLogger:warn(photoFilename..' - REG NOT FOUND: lookup skipped for registration '..searchRegistration..' (a previous lookup returned noting useful)') + -- mark photo with keyword reg_not_found + catalog:withWriteAccessDo('set keyword', + function() + photo:addKeyword(keywordRegNotFound) + end) end -- check if we have a reg and user did not hit cancel if flagRegFound and not progressScope:isCanceled()then