Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to get EXIF data from Flickr #353

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/jquery.nanogallery2.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@
RTL : false,
flickrSkipOriginal : true,
flickrAPIKey: '',
flickrExif: false,
breadcrumbAutoHideTopLevel : true,
displayBreadcrumb : true,
breadcrumbOnlyCurrentLevel : true,
Expand Down
55 changes: 55 additions & 0 deletions src/jquery.nanogallery2.data_flickr.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,56 @@
}


// -----------
// Retrieve flickr EXIF data
function FlickrGetExif ( itemID, newItem ) {
jQuery.ajaxSetup({ cache: false });
jQuery.support.cors = true;

var sourceData=[];

var tId = setTimeout( function() {
// workaround to handle JSONP (cross-domain) errors
NanoAlert('Could not retrieve AJAX data...');
}, 60000 );

url = Flickr.url() + "?&method=flickr.photos.getExif&api_key=" + G.O.flickrAPIKey + "&photo_id="+itemID+"&format=json";

jQuery.getJSON( url + '&jsoncallback=?' , function(data, status, xhr) {
// Exif - model
if( data.photo.camera !== undefined ) { newItem.exif.model = data.photo.camera; }
// Exif - flash
var flash = data.photo.exif.filter(function(exif) {return exif.tag == "Flash"})
if( flash.length >= 1 ) { newItem.exif.flash = flash[0].raw._content; }
// Exif - focallength
var fl = data.photo.exif.filter(function(exif) {return exif.tag == "FocalLength"});
if( fl.length >= 1 ) { newItem.exif.focallength = fl[0].raw._content; }
// Exif - fstop
var fstop = data.photo.exif.filter(function(exif) {return exif.tag == "FNumber"});
if( fstop.length >= 1 ) { newItem.exif.fstop = fstop[0].raw._content; }
// Exif - exposure
var exposure = data.photo.exif.filter(function(exif) {return exif.tag == "ExposureTime"});
if( exposure.length >= 1 ) { newItem.exif.exposure = exposure[0].raw._content; }
// Exif - iso
var iso = data.photo.exif.filter(function(exif) {return exif.tag == "ISO"});
if( iso.length >= 1 ) { newItem.exif.iso = iso[0].raw._content; }
// Exif - time
var time = data.photo.exif.filter(function(exif) {return exif.tag == "DateTimeOriginal"});
if( time.length >= 1 ) { newItem.exif.time = time[0].raw._content; }
// Exif - location
var location = data.photo.exif.filter(function(exif) {return exif.tag == "LOLcation"});
if( location.length >= 1 ) { newItem.exif.location = location[0].raw._content; }

// author
var author = data.photo.exif.filter(function(exif) {return exif.tag == "OwnerName"});
if( author.length >= 1 ) { newItem.author = author[0].raw._content; }

clearTimeout(tId);
}).fail(function(jqXHR, textStatus, errorThrown) {
console.log("Unable to get EXIF data from Flickr");
})
}


// -----------
// Retrieve items for one Flickr photoset
Expand Down Expand Up @@ -212,6 +262,11 @@
// create item
var newItem = NGY2Item.New( G, itemTitle, itemDescription, itemID, albumID, 'image', tags );

// grab EXIF data
if ( G.O.flickrExif ) {
FlickrGetExif(itemID, newItem);
}

// add image
newItem.setMediaURL( imgUrl, 'img');
newItem.imageWidth = imgW;
Expand Down