-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
44 lines (36 loc) · 822 Bytes
/
index.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
/**
* Module dependencies.
*/
var exec = require('child_process').exec
, command = require('shelly');
/**
* Fetch EXIF data from `file` and invoke `fn(err, data)`.
*
* @param {String} file
* @param {Function} fn
* @api public
*/
module.exports = function(file, fn){
var cmd = command('exiftool ?', file);
exec(cmd, function(err, str){
if (err) return fn(err);
var obj = str.split('\n').reduce(function(obj, line){
var i = line.indexOf(':');
var key = slug(line.slice(0, i));
var val = line.slice(i + 1, line.length).trim();
if ('' == key || '' == val) return obj;
obj[key] = val;
return obj;
}, {});
fn(null, obj);
});
};
/**
* Slug `str`.
*/
function slug(str) {
return str
.trim()
.replace(/[^\w]+/g, ' ')
.toLowerCase();
}