Tabs -> Spaces

This commit is contained in:
Bryan Ashby 2018-06-29 22:39:36 -06:00
parent fa100c2da1
commit a8e27b4cf5
1 changed files with 70 additions and 70 deletions

View File

@ -20,96 +20,96 @@ const FILETYPE_HANDLERS = {};
[ 'MP4', 'MOV', 'AVI', 'MKV', 'MPG', 'MPEG', 'M4V', 'WMV' ].forEach(ext => FILETYPE_HANDLERS[ext] = videoFile); [ 'MP4', 'MOV', 'AVI', 'MKV', 'MPG', 'MPEG', 'M4V', 'WMV' ].forEach(ext => FILETYPE_HANDLERS[ext] = videoFile);
function audioFile(metadata) { function audioFile(metadata) {
// nothing if we don't know at least the author or title // nothing if we don't know at least the author or title
if(!metadata.author && !metadata.title) { if(!metadata.author && !metadata.title) {
return; return;
} }
let desc = `${metadata.artist||'Unknown Artist'} - ${metadata.title||'Unknown'} (`; let desc = `${metadata.artist||'Unknown Artist'} - ${metadata.title||'Unknown'} (`;
if(metadata.year) { if(metadata.year) {
desc += `${metadata.year}, `; desc += `${metadata.year}, `;
} }
desc += `${metadata.audioBitrate})`; desc += `${metadata.audioBitrate})`;
return desc; return desc;
} }
function videoFile(metadata) { function videoFile(metadata) {
return `${metadata.fileType} video(${metadata.imageSize}px, ${metadata.duration}, ${metadata.audioBitsPerSample}/${metadata.audioSampleRate} audio)`; return `${metadata.fileType} video(${metadata.imageSize}px, ${metadata.duration}, ${metadata.audioBitsPerSample}/${metadata.audioSampleRate} audio)`;
} }
function documentFile(metadata) { function documentFile(metadata) {
// nothing if we don't know at least the author or title // nothing if we don't know at least the author or title
if(!metadata.author && !metadata.title) { if(!metadata.author && !metadata.title) {
return; return;
} }
let result = metadata.author || ''; let result = metadata.author || '';
if(result) { if(result) {
result += ' - '; result += ' - ';
} }
result += metadata.title || 'Unknown Title'; result += metadata.title || 'Unknown Title';
return result; return result;
} }
function imageFile(metadata) { function imageFile(metadata) {
let desc = `${metadata.fileType} image (`; let desc = `${metadata.fileType} image (`;
if(metadata.animationIterations) { if(metadata.animationIterations) {
desc += 'Animated, '; desc += 'Animated, ';
} }
desc += `${metadata.imageSize}px`; desc += `${metadata.imageSize}px`;
const created = moment(metadata.createdate); const created = moment(metadata.createdate);
if(created.isValid()) { if(created.isValid()) {
desc += `, ${created.format('YYYY')})`; desc += `, ${created.format('YYYY')})`;
} else { } else {
desc += ')'; desc += ')';
} }
return desc; return desc;
} }
function main() { function main() {
const argv = exports.argv = require('minimist')(process.argv.slice(2), { const argv = exports.argv = require('minimist')(process.argv.slice(2), {
alias : { alias : {
h : 'help', h : 'help',
v : 'version', v : 'version',
} }
}); });
if(argv.version) { if(argv.version) {
console.info(TOOL_VERSION); console.info(TOOL_VERSION);
return 0; return 0;
} }
if(0 === argv._.length || argv.help) { if(0 === argv._.length || argv.help) {
console.info('usage: exiftool2desc.js [--version] [--help] PATH'); console.info('usage: exiftool2desc.js [--version] [--help] PATH');
return 0; return 0;
} }
const path = argv._[0]; const path = argv._[0];
fs.readFile(path, (err, data) => { fs.readFile(path, (err, data) => {
if(err) { if(err) {
return -1; return -1;
} }
exiftool.metadata(data, (err, metadata) => { exiftool.metadata(data, (err, metadata) => {
if(err) { if(err) {
return -1; return -1;
} }
const handler = FILETYPE_HANDLERS[metadata.fileType]; const handler = FILETYPE_HANDLERS[metadata.fileType];
if(!handler) { if(!handler) {
return -1; return -1;
} }
const info = handler(metadata); const info = handler(metadata);
if(!info) { if(!info) {
return -1; return -1;
} }
console.info(info); console.info(info);
return 0; return 0;
}); });
}); });
} }
return main(); return main();