Last active
July 4, 2016 01:40
Star
You must be signed in to star a gist
This file contains 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
// ==Taberareloo== | |
// { | |
// "name" : "Patches for Flickr" | |
// , "description" : "Patches for Flickr" | |
// , "include" : ["content"] | |
// , "match" : ["*://www.flickr.com/*"] | |
// , "version" : "0.0.1" | |
// , "downloadURL" : "https://gist.githubusercontent.com/mono0x/06ef86dbc7618d0c4082c4f34561d272/raw/patch.extractor.flickr.tbrl.js" | |
// } | |
// ==/Taberareloo== | |
(function() { | |
update(Extractors['Photo - Flickr'], { | |
callMethod: function (ps) { | |
return request('https://flickr.com/services/rest/', { | |
queryString : update({ | |
api_key : this.API_KEY, | |
nojsoncallback : 1, | |
format : 'json', | |
responseType : 'json' | |
}, ps) | |
}).then(function (res) { | |
var json = JSON.parse(res.response); | |
if (json.stat !== 'ok') { | |
throw json.message; | |
} | |
return json; | |
}); | |
}, | |
extract: function(ctx) { | |
var id = this.getImageId(ctx); | |
return promiseAllHash({ | |
'info' : this.getInfo(id), | |
'sizes' : this.getSizes(id) | |
}).then(function (r) { | |
var info = r.info; | |
var sizes = r.sizes; | |
var title = info.title._content; | |
ctx.title = title + ' on Flickr'; | |
ctx.href = info.urls.url[0]._content; | |
var thumbnailSize; | |
if (sizes.length >= 6) { | |
thumbnailSize = sizes[6]; // may be 'Small' | |
} else { | |
thumbnailSize = sizes[sizes.length - 1]; | |
} | |
var uploadSize = sizes.find(function(size) { | |
return size.label === 'Large 2048'; | |
}); | |
if (!uploadSize) { | |
if ((info.rotation - 0) === 0) { | |
uploadSize = sizes.pop(); | |
} else { | |
sizes.pop(); | |
uploadSize = sizes.pop(); | |
} | |
} | |
return { | |
type : 'photo', | |
item : title, | |
itemUrl : uploadSize.source, | |
author : info.owner.username, | |
authorUrl : ctx.href.extract('^(https?://.*?flickr.com/photos/.+?/)'), | |
license : info.license, | |
date : info.dates.taken, | |
thumbnailUrl : thumbnailSize.source, | |
originalWidth : uploadSize.width, | |
originalHeight : uploadSize.height, | |
}; | |
}).catch(function () { | |
return Extractors.Photo.extract(ctx); | |
}); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment