Created
March 13, 2018 01:42
-
-
Save jboxman/7e4e31e1cc4fa542076521a1076792c4 to your computer and use it in GitHub Desktop.
Set XMP-digiKam:Color label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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