Skip to content

Instantly share code, notes, and snippets.

@jboxman
Created March 13, 2018 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jboxman/7e4e31e1cc4fa542076521a1076792c4 to your computer and use it in GitHub Desktop.
Save jboxman/7e4e31e1cc4fa542076521a1076792c4 to your computer and use it in GitHub Desktop.
Set XMP-digiKam:Color label
const fs = require('fs');
const readline = require('readline');
const path = require('path');
const { spawnSync } = require('child_process');
// Ran 20180206 successfully
process.exit(0);
// exiftool -r -m -n -if '$Orientation != 1' -p '$Directory/$FileName' . -ext xmp -ext jpg > /tmp/imagefiles.txt
const stream = readline.createInterface({
input: fs.createReadStream('/tmp/imagefiles.txt'),
crlfDelay: Infinity
});
let data = {};
stream.on('line', line => {
let {name, dir} = path.parse(line);
if(name.match(/\./)) {
name = path.basename(name, `.${name.split(/\./)[1]}`);
}
data[name] = Object.assign({count: 0, filePath: path.join(dir, name)}, data[name]);
data[name].count++;
});
/* -XMP-digiKam:ColorLabel= (fixed values)
1 - red
2 - orange
3 - yellow
4 - green
5 - blue
6 - magenta
7 - gray
8 - black
9 - white
*/
stream.on('close', () => {
// If there is only a sidecar, ignore for now
Object.keys(data).filter(v => data[v].count == 2).forEach(key => {
let {filePath} = data[key];
// Run exiftool to update files.
['jpg.xmp'].forEach(ext => {
let {stdout, stderr, error} = spawnSync(
`exiftool`,
[
'-n', '-XMP-digiKam:ColorLabel=1', `photographers/jboxman/${filePath}.${ext}`
]);
console.log(`${filePath}: ${stdout} - ${stderr}`);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment