forked from devbab/plex-ttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exif.js
executable file
·79 lines (64 loc) · 2.27 KB
/
exif.js
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
//const exiftool = require("exiftool-vendored").exiftool;
const ExifTool = require("exiftool-vendored").ExifTool;
let numCPUs = require("os").cpus().length;
const exiftool = new ExifTool({
maxProcs: numCPUs
});
// maxProcs: DefaultMaxProcs,
/**
* look for XMP tag and return an array of it
* @param {} filename
* @returns {modif,tags}
*/
function getFromImage(filename) {
// console.log(`getting exif for ${filename}`);
return new Promise(function (resolve, reject) {
exiftool
.read(filename)
.then(tags => {
//console.log("exif tags ",tags);
const d = tags.FileModifyDate;
const modif = new Date(d.year, d.month - 1, d.day, d.hour, d.minute, d.second, 0);
//console.log("fileModifyDate: ",d );
const lat = tags.GPSLatitude;
const lng = tags.GPSLongitude;
let pos = null;
if (lat && lng)
pos = {
lat: lat,
lng: lng
};
let faces = [];
if (Object.prototype.hasOwnProperty.call(tags, "PersonInImage")){
faces = tags.PersonInImage;
console.log("Found Person in Image Names: ", faces);
}
// support for Picasa face regions
else if (Object.prototype.hasOwnProperty.call(tags, "RegionInfo")) {
out = [];
for (i=0; i < tags.RegionInfo.RegionList.length; i++) {
if (tags.RegionInfo.RegionList[i].Name)
out[i] = tags.RegionInfo.RegionList[i].Name;
}
console.log("Found Region Names: ", out);
faces = out;
}
resolve({
modif: modif,
faces: faces,
pos: pos,
tags: tags
});
})
.catch(err => {
reject(err);
});
});
}
function end() {
exiftool.end();
}
module.exports = {
getFromImage: getFromImage,
end: end
};