Skip to content

Instantly share code, notes, and snippets.

@Adidea
Last active August 11, 2016 00:34
Show Gist options
  • Save Adidea/e095391c49a0c168c7616abe46ab52ab to your computer and use it in GitHub Desktop.
Save Adidea/e095391c49a0c168c7616abe46ab52ab to your computer and use it in GitHub Desktop.
converts JSON generated from my gallery scraper to a structure compatible with ExifTool
function toExifJSON(json) {
console.log(json);
var data = JSON.parse(json);
var exif = [];
for (var file in data) {
if (data.hasOwnProperty(file)) {
exif.push({
"SourceFile": file,
//I just noticed title is missing from the last version of my scraper, where'd it go?
"Creator": data[file].artist,
"CreatorWorkUrl": data[file].submission,
"Description": data[file].description,
"Subject": data[file].tags,
"Keywords": data[file].tags,
//TODO: setup category and common tag heiarchies EX: "HierarchicalSubject": ["Gender|Male", "Medium|Artwork (Traditional)"]
});
}
}
return JSON.stringify(exif, null, 4);
}
function initialize() {
var fileInput = document.createElement("input");
fileInput.setAttribute("type", "file");
document.body.insertBefore(fileInput, document.body.firstChild);
fileInput.addEventListener("change", function() {
var file = this.files[0];
var read = new FileReader();
read.onload = function(e) {
var text = e.target.result;
document.body.innerHTML = toExifJSON(text);
document.body.insertBefore(fileInput, document.body.firstChild);
}
read.readAsText(file);
});
}
initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment