I am trying to extract EXIF data from several jpeg files located in one of my Google Drive folders, using a Google Script.
More accurately, I would like to extract the date at which the photo was taken, together with associated keywords / description of the image, previously created with Adobe Lightroom.
I know that several scripts allowing to extract EXIF data from a file exist on internet, but I didn't manage to link them, or to use them with my own Google script.
How can I do that easily ?
(I am a beginner on Google Script, please be as precise as possible)
Thank you in advance
The DriveApp service of Google Apps Script doesn't provide access to the details you're looking for, but the Advance Drive Service does.
Code.gs
You will need to enable the Advanced Drive service, following instructions here.
// Demo use of getPhotoExif()
// Logs all files in a folder named "Photos".
function listPhotos() {
var files = DriveApp.getFoldersByName("Photos").next().getFiles();
var fileInfo = [];
while (files.hasNext()) {
var file = files.next();
Logger.log("File: %s, Date taken: %s",
file.getName(),
getPhotoExif(file.getId()).date || 'unknown');
}
}
/**
* Retrieve imageMediaMetadata for given file. See Files resource
* representation for details.
* (https://developers.google.com/drive/v2/reference/files)
*
* @param {String} fileId File ID to look up
*
* @returns {object} imageMediaMetadata object
*/
function getPhotoExif( fileId ) {
var file = Drive.Files.get(fileId);
var metaData = file.imageMediaMetadata;
// If metaData is 'undefined', return an empty object
return metaData ? metaData : {};
}
In the Google Drive API, the resource representation for a File includes properties for the EXIF data:
"imageMediaMetadata": {
"width": integer,
"height": integer,
"rotation": integer,
"location": {
"latitude": double,
"longitude": double,
"altitude": double
},
"date": string,
"cameraMake": string,
"cameraModel": string,
"exposureTime": float,
"aperture": float,
"flashUsed": boolean,
"focalLength": float,
"isoSpeed": integer,
"meteringMode": string,
"sensor": string,
"exposureMode": string,
"colorSpace": string,
"whiteBalance": string,
"exposureBias": float,
"maxApertureValue": float,
"subjectDistance": integer,
"lens": string
},