-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportPhotoMetadata.lua
More file actions
104 lines (87 loc) · 3.36 KB
/
ReportPhotoMetadata.lua
File metadata and controls
104 lines (87 loc) · 3.36 KB
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
96
97
98
99
100
101
102
103
104
local LrDialogs = import 'LrDialogs'
local LrDate = import 'LrDate'
local LrLogger = import 'LrLogger'
local LrPathUtils = import 'LrPathUtils'
local LrFileUtils = import 'LrFileUtils'
local LrErrors = import 'LrErrors'
local LrApplication = import "LrApplication"
local LrProgressScope = import "LrProgressScope"
local myLogger = LrLogger( 'libraryLogger' )
local LrTasks = import 'LrTasks'
local LrFunctionContext = import 'LrFunctionContext'
myLogger:enable( "print" ) -- or "logfile"
MyHWExportItem = {}
-- function groupMessages(array)
-- local result = {};
-- for k, v in ipairs(array) do
-- if not result[v.sender] then
-- result[v.sender] = {};
-- end
-- table.insert(result[v.sender], v);
-- end
-- return result;
-- end
function concat ( a, b )
local result = {}
for k,v in pairs ( a ) do
table.insert( result, v )
end
for k,v in pairs ( b ) do
table.insert( result, v )
end
return result
end
function Split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
function table_print (tt, indent, done)
done = done or {}
indent = indent or 0
if type(tt) == "table" then
local sb = {}
for key, value in pairs (tt) do
table.insert(sb, string.rep (" ", indent)) -- indent it
if type (value) == "table" and not done [value] then
done [value] = true
table.insert(sb, "{\n");
table.insert(sb, table_print (value, indent + 2, done))
table.insert(sb, string.rep (" ", indent)) -- indent it
table.insert(sb, "}\n");
elseif "number" == type(key) then
table.insert(sb, string.format("\"%s\"\n", tostring(value)))
else
table.insert(sb, string.format(
"%s = \"%s\"\n", tostring (key), tostring(value)))
end
end
return table.concat(sb)
else
return tt .. "\n"
end
end
function MyHWExportItem.report_photo_metadata()
local catalog = LrApplication.activeCatalog()
local photo = catalog:getTargetPhoto()
local common_fields = {'dateTimeOriginal', 'dateTimeDigitized', 'dateTime'}
local raw_meta = catalog:batchGetRawMetadata({photo}, concat(common_fields, {'dateTimeOriginalISO8601', 'dateTimeDigitizedISO8601', 'dateTimeISO8601', 'gps', 'path', 'fileFormat'}))[photo]
local formatted_meta = catalog:batchGetFormattedMetadata({photo}, concat(common_fields, {'dateCreated', 'preservedFileName', 'folderName', 'fileType'}))[photo]
-- process raw common just to make readable
for i, v in ipairs(common_fields) do
raw = raw_meta[v]
if raw ~= nil then
raw_meta[v] = '(parsed) ' .. LrDate.timeToW3CDate(raw)
else
raw_meta[v] = 'missing'
end
end
raw_meta['parent_folder_name'] = LrPathUtils.leafName(LrPathUtils.parent(raw_meta['path']))
local filenamePresets = LrApplication.filenamePresets()
formatted_meta['preset_scotty'] = photo:getNameViaPreset( filenamePresets['ScottyG'], '', 0 )
formatted_meta['preset_iso'] = photo:getNameViaPreset( filenamePresets['ISO8601'], '', 0 )
LrDialogs.message('Photo Metadata', table_print(raw_meta) .. '\n\n' .. table_print(formatted_meta), 'info')
end
LrTasks.startAsyncTask(MyHWExportItem.report_photo_metadata)