Last active
December 24, 2015 13:09
-
-
Save iyoupapa/6803380 to your computer and use it in GitHub Desktop.
このコードは tombloo/tombfix 用の Creative Commons License の記述を追加するパッチです。このコードのライセンスは tombloo/tombfix と同様にパブリックドメイン(CC0)です。Patche for tombloo/tombfix to add creative commons license description.This code license is public domain(CC0), same as tombloo/tombfix.
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
(function() { | |
Tombloo.Service.extractors.register({ | |
name : 'Photo - DeviantArt', | |
ICON : 'http://st.deviantart.net/icons/favicon.ico', | |
URL : 'http://www.deviantart.com/', | |
check : function(ctx){ | |
var logs = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService); | |
if (ctx.onImage) { | |
logs.logStringMessage("!0 " + (ctx.target.src.match('^http://.+\.500px\.org/.+/.+/.+\.jpg$'))?"true":"false" + "!"); | |
} else { | |
logs.logStringMessage("!0 !"); | |
} | |
return ctx.onImage && | |
ctx.target.src.match('^http://....\.deviantart\.(net|com)/(....?|images..?)/'); | |
}, | |
extract : function(ctx){ | |
var authorElement = $x('//div[@class="dev-title-container"]//a[contains(concat(" ",normalize-space(@class)," "), " username ")]'); | |
var cc = $x('//div[@class="cc_license_text"]'); | |
if (cc) { | |
cc = cc.innerHTML | |
.replace(/<\/?em>/g, '') | |
.replace(/<br>/g, '') | |
.replace(/rel="license"/g, '') | |
.replace(/target="_blank"/g, '') | |
.replace(/ +/g, ' '); | |
} | |
var url; | |
url = ctx.target.src; | |
return { | |
type : 'photo', | |
item : ctx.title.extract(/(.*) by .+ on deviantART/i), | |
itemUrl : url, | |
author : authorElement.textContent.trim(), | |
authorUrl : authorElement.href, | |
license : cc, | |
}; | |
}, | |
}, 'Photo', false); | |
Tombloo.Service.extractors.register({ | |
name : 'Photo - 500px', | |
ICON : 'http://500px.com/favicon.ico', | |
URL : 'http://500px.com/', | |
check : function (ctx) { | |
var logs = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService); | |
if (ctx.onImage) { | |
logs.logStringMessage("!0 " + (ctx.target.src.match('^http://.+\.500px\.org/.+/.+/.+\.jpg$'))?"true":"false" + "!"); | |
} else { | |
logs.logStringMessage("!0 !"); | |
} | |
return ctx.onImage && | |
ctx.target.src.match('^http://.+\.500px\.org/.+/.+/.+\.jpg$'); | |
}, | |
extract : function (ctx) { | |
var authorElement = $x('//a[contains(concat(" ",normalize-space(@class)," "), " user_profile_link ")]'); | |
var ccTypeElement = $x('//a[contains(concat(" ",normalize-space(@class)," "), " license ")]'); | |
var cc = ''; | |
if (ccTypeElement && ccTypeElement.href && ccTypeElement.href.match('^http://creativecommons.org/.*$')) { | |
var ccText = ccTypeElement.attributes['data-tooltip'].value; | |
cc = 'Some rights reserved. This work is licensed under a <a href="' | |
+ ccTypeElement.href | |
+ '">' | |
+ ccText.trim() | |
+ '</a> license.'; | |
} | |
var url = ctx.target.src; | |
return { | |
type : 'photo', | |
item : ctx.title.extract(/500px \/ (.*) by .*$/i), | |
itemUrl : url, | |
author : authorElement.textContent.trim(), | |
authorUrl : authorElement.href, | |
license : cc, | |
}; | |
}, | |
}, 'Photo', false); | |
Tombloo.Service.extractors['Photo - Flickr']['extract'] = function(ctx){ | |
var id = this.getImageId(ctx); | |
return new DeferredHash({ | |
'info' : Flickr.getInfo(id), | |
'sizes' : Flickr.getSizes(id), | |
}).addCallback(function(r){ | |
if(!r.info[0]) | |
throw new Error(r.info[1].message); | |
var info = r.info[1]; | |
var sizes = r.sizes[1]; | |
var title = info.title._content; | |
ctx.title = title + ' on Flickr' | |
ctx.href = info.urls.url[0]._content; | |
var largestSize; | |
if (info.rotation == 0) { | |
largestSize = sizes.pop(); | |
} else { | |
sizes.pop(); | |
largestSize = sizes.pop(); | |
} | |
return { | |
type : 'photo', | |
item : title, | |
itemUrl : largestSize.source, | |
author : info.owner.username, | |
authorUrl : ctx.href.extract('^(https?://.*?flickr.com/photos/.+?/)'), | |
favorite : { | |
name : 'Flickr', | |
id : id, | |
}, | |
license : info.license, | |
date : info.dates.taken, | |
} | |
}).addErrback(function(err){ | |
return Tombloo.Service.extractors['Photo'].extract(ctx); | |
}); | |
}; | |
addAround( | |
Tombloo.Service.extractors, | |
'extract', | |
function(proceed, args, target, methodName) { | |
return proceed(args).addCallback(function(ps){ | |
switch (ps.license) { | |
case '1': | |
var dd = ps.date.split('-'); | |
ps.description = '(c) ' + dd[0] + ' <a href="' + ps.authorUrl + '">' + ps.author + '</a>' | |
+ ' under <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">CC-BY-NC-SA</a> license.' | |
ps.private = false; | |
break; | |
case '2': | |
var dd = ps.date.split('-'); | |
ps.description = '(c) ' + dd[0] + ' <a href="' + ps.authorUrl + '">' + ps.author + '</a>' | |
+ ' under <a href="http://creativecommons.org/licenses/by-nc/2.0/">CC-BY-NC</a> license.' | |
ps.private = false; | |
break; | |
case '3': | |
var dd = ps.date.split('-'); | |
ps.description = '(c) ' + dd[0] + ' <a href="' + ps.authorUrl + '">' + ps.author + '</a>' | |
+ ' under <a href="http://creativecommons.org/licenses/by-nc-nd/2.0/">CC-BY-NC-ND</a> license.' | |
ps.private = false; | |
break; | |
case '4': | |
var dd = ps.date.split('-'); | |
ps.description = '(c) ' + dd[0] + ' <a href="' + ps.authorUrl + '">' + ps.author + '</a>' | |
+ ' under <a href="http://creativecommons.org/licenses/by/2.0/">CC-BY</a> license.' | |
ps.private = false; | |
break; | |
case '5': | |
var dd = ps.date.split('-'); | |
ps.description = '(c) ' + dd[0] + ' <a href="' + ps.authorUrl + '">' + ps.author + '</a>' | |
+ ' under <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> license.' | |
ps.private = false; | |
break; | |
case '6': | |
var dd = ps.date.split('-'); | |
ps.description = '(c) ' + dd[0] + ' <a href="' + ps.authorUrl + '">' + ps.author + '</a>' | |
+ ' under <a href="http://creativecommons.org/licenses/by-nd/2.0/">CC-BY-ND</a> license.' | |
ps.private = false; | |
break; | |
default: | |
if (ps.license) { | |
ps.description = '(c) <a href="' + ps.authorUrl + '">' + ps.author | |
+ '</a> ' + ps.license; | |
ps.private = false; | |
} else if (ps.type == 'photo') { | |
ps.private = true; | |
} | |
break; | |
} | |
return ps; | |
}); | |
} | |
); | |
})(); |
Revision 4
Flickr, DeviantArt の他に 500px に対応。
DeviantArt と 500px は写真の撮影日がないので Copyright の年が表示できないのが残念です。アップロード日の年を使うのは違う気がします。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revision 3
FlickrのHTTPS対応。