-
Notifications
You must be signed in to change notification settings - Fork 0
/
EvalFocus.lua
77 lines (70 loc) · 2.44 KB
/
EvalFocus.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
--[[
EvalFocus.lrdevplugin
@file EvalFocus.lua
@author @remov_b4_flight
]]
-- Please specfy python in your local enviromnent.
local python = '/opt/homebrew/bin/python3.12'
local PluginTitle = 'EvalFocus'
local LrApplication = import 'LrApplication'
local LrTasks = import 'LrTasks'
local LrProgress = import 'LrProgressScope'
local LrSelection = import 'LrSelection'
local LrFileUtils = import 'LrFileUtils'
local prefs = import 'LrPrefs'.prefsForPlugin()
--local LrLogger = import 'LrLogger'
--local Logger = LrLogger(PluginTitle)
--Logger:enable('logfile')
--Constants
local SEP = ' '
local SCRIPT = '/evalfocus.py'
local SCRIPT_PATH = _PLUGIN.path .. SCRIPT
local MINRESULT = 5
local NOTFOUND = 2
--For python logfile
local REDIR = '>>'
local LOG_OPTION = '-vvvv'
local LOG_FILE = '/evalfocus.log'
local LOGPATH = _PLUGIN.path .. LOG_FILE
local LOG_CMDLINE = LOG_OPTION .. SEP .. REDIR .. SEP .. LOGPATH
if (prefs.AutoReject == nil) then
prefs.AutoReject = false
end
if (prefs.RejectRange == nil) then
prefs.RejectRange = 30
end
local CurrentCatalog = LrApplication.activeCatalog()
--Main part of this plugin.
LrTasks.startAsyncTask( function ()
local ProgressBar = LrProgress(
{title = PluginTitle .. ' is Running..'}
)
local TargetPhoto = CurrentCatalog:getTargetPhoto()
local SelectedPhotos = CurrentCatalog:getTargetPhotos()
local countPhotos = #SelectedPhotos
--loops photos in selected
for i,PhotoIt in ipairs(SelectedPhotos) do
if (PhotoIt:getRawMetadata('fileFormat') == 'JPG' and PhotoIt:getRawMetadata('fileSize') ~= nil ) then
local FilePath = PhotoIt:getRawMetadata('path')
local CommandLine = python .. SEP .. SCRIPT_PATH .. SEP .. FilePath
-- Logger:info(CommandLine)
-- only MSB 8 bits are valid
local return_value = LrTasks.execute(CommandLine) / 256
-- Logger:info('value=' .. value)
if (return_value >= MINRESULT) then
CurrentCatalog:withWriteAccessDo('Evaluate Focus', function()
PhotoIt:setPropertyForPlugin(_PLUGIN, 'value', return_value)
if (prefs.AutoReject == true and (return_value < prefs.RejectRange or PhotoIt:getRawMetadata('shutterSpeed') > 1)) then
PhotoIt:setRawMetadata('pickStatus', -1)
end
end, { timeout = 0.33 } ) --end of withWriteAccessDo
end
else
-- Logger:info('skip non JPEG file.')
end --isVideo
ProgressBar:setPortionComplete(i, countPhotos)
end --end of for photos loop
ProgressBar:done()
LrSelection.selectNone()
end ) --end of startAsyncTask function()
return