Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
TumblrでhighRes画像を取得するTombfixパッチ
Browse files Browse the repository at this point in the history
 - Tumblr Photosetパッチに対応
  • Loading branch information
polygonplanet committed Sep 18, 2013
1 parent 6f5c437 commit 1222e5b
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions tombloo.extractor.tumblr.highres.js
@@ -1,47 +1,62 @@
/**
* Extractor Tumblr HighRes - Tombloo patch
* Extractor Tumblr HighRes - Tombfix patch
*
* TumblrでhighRes画像を取得するTomblooパッチ
* TumblrでhighRes画像を取得するTombfixパッチ
*
* @version 1.01
* @date 2013-06-15
* @date 2013-09-19
* @author polygon planet <polygon.planet.aqua@gmail.com>
* - Twitter: http://twitter.com/polygon_planet
* @license Same as Tombloo
* @link http://twitter.com/polygon_planet
* @license Public Domain
* @updateURL https://github.com/polygonplanet/tombloo/raw/master/tombloo.extractor.tumblr.highres.js
*
* Tombloo: https://github.com/to/tombloo/wiki
*/
(function() {

addAround(Tombloo.Service.extractors['ReBlog'], 'extractByEndpoint', function(proceed, args) {
return proceed(args).addCallback(function(ps) {

function getHighRes(ps) {
var itemUrl = ps.itemUrl;

if (ps.type !== 'photo' || !/tumblr.*_\d+\.\w+$/.test(itemUrl)) {
return ps;
return succeed(ps);
}

var highRes = itemUrl.replace(/^(.*)_\d+\.(\w+)$/, '$1_1280.$2');

if (highRes === itemUrl) {
return ps;
return succeed(ps);
}

return request(highRes).addErrback(function(err) {
return ps;
}).addCallback(function(res) {
if (res.status == 200) {
itemUrl = highRes;
update(ps, {
itemUrl : itemUrl,
itemUrl : highRes,
form : {
image : itemUrl
image : highRes
}
});
}
return ps;
});
}

return proceed(args).addCallback(function(ps) {
if (ps.favorite && ps.favorite.form &&
Array.isArray(ps.favorite.form.images) && ps.favorite.form.images.length
) {
// 画像が複数 (Photoset)
return deferredForEach(ps.favorite.form.images, function(image, i) {
return wait(0).addCallback(function() {
return getHighRes(update({}, ps, { itemUrl : image })).addCallback(function(nps) {
ps.favorite.form.images[i] = nps.itemUrl;
return ps;
});
});
});
}
return getHighRes(ps);
});
});

Expand Down

0 comments on commit 1222e5b

Please sign in to comment.