Skip to content

Instantly share code, notes, and snippets.

@rankun203
Last active September 20, 2020 04:27
Show Gist options
  • Save rankun203/d8b94f9761568ee7d5bbe57863e31ec7 to your computer and use it in GitHub Desktop.
Save rankun203/d8b94f9761568ee7d5bbe57863e31ec7 to your computer and use it in GitHub Desktop.
Exif Editing
const sh = require("shelljs");
const exiftool = require("exiftool-vendored").exiftool;
const folder =
"/Users/rankun203/Downloads/670 Claude Monet Paintings/670 Amazing Claude Monet Paintings [Up to 4500 Px]-1";
let files = [];
sh.ls(`${folder}/Pics/Monet Paintings/`).forEach((f) => files.push(f));
files = files.sort((a, b) => {
const aNum = a.match(/(\d+)\s/)[1];
const bNum = b.match(/(\d+)\s/)[1];
return Number(aNum) > Number(bNum) ? 1 : -1;
});
(async () => {
for (let f of files) {
const parts = f.match(/(\d+).*/);
const num = parts[1];
const title = f.match(/(.*)\.[^\.]+/)[1];
const newDate = new Date(315532800000 + Number(num) * 10000)
.toISOString()
.replace("T", " ")
.replace(/-/g, ":")
.replace(/\.\d{3}\w/, "");
const filename = `${folder}/Pics/Monet Paintings/${f}`;
const tags = {
artist: "Claude Monet",
Title: title,
AllDates: newDate,
};
// console.log("\non file", filename, newDate);
const rtags = await exiftool.read(filename);
if (!rtags["Caption-Abstract"]) {
tags["Caption-Abstract"] = title;
} else {
console.log("file has original caption", f);
tags["Caption-Abstract"] = `${title}\n\n${rtags["Caption-Abstract"]}`;
}
// console.log(Object.keys(rtags));
// console.log("Caption-Abstract", rtags["Caption-Abstract"]);
// console.log("CaptionWriter", rtags["CaptionWriter"]);
console.log(tags);
// if (rtags["Caption-Abstract"]) {
// console.log("rtags.Caption", rtags.Caption);
// }
try {
await exiftool.write(filename, tags);
} catch (e) {
console.log("WARNING", f);
console.log(e);
}
}
process.exit(0);
})();
const sh = require("shelljs");
const folder =
"/Users/rankun203/Downloads/670 Claude Monet Paintings/670 Amazing Claude Monet Paintings [Up to 4500 Px]-1";
const files = sh
.cat(`${folder}/List.txt`)
.trim()
.split(/\r/)
.reduce((accu, cur) => {
const name = cur.split(") ");
accu[name[0].trim()] = name[1].trim();
return accu;
}, {});
sh.ls(`${folder}/Pics/`).forEach((f) => {
const parts = f.match(/(\d+)\..*/);
const name = files[parts[1]];
const newName = `${parts[1]} - ${name}`;
console.log(f, "-->", newName);
sh.mv(`${folder}/Pics/${f}`, `${folder}/Pics/renamed/${newName}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment