Skip to content

Instantly share code, notes, and snippets.

@YungSang
Last active December 16, 2015 18:09
Show Gist options
  • Save YungSang/5476071 to your computer and use it in GitHub Desktop.
Save YungSang/5476071 to your computer and use it in GitHub Desktop.
[Deprecated] Taberareloo 用のニコニコ動画 Extractor この実装は推奨されません。こちらで対応されています。https://github.com/Constellation/taberareloo/pull/194
(function() {
update(Extractors['Video - Nico Nico Douga'], {
extract : function(ctx) {
var externalPlayerURL = 'http://ext.nicovideo.jp/thumb_' + ctx.pathname.slice(1) + '?thumb_mode=swf&ap=1&c=1';
var video_id = ctx.pathname.extract(/watch\/(sm\d+)/);
return request('http://ext.nicovideo.jp/api/getthumbinfo/' + video_id).addCallback(function(res) {
var xml = res.responseXML;
var status = xml.getElementsByTagName('nicovideo_thumb_response')[0].getAttribute('status');
if (status !== 'ok') {
var description = xml.getElementsByTagName('description')[0].textContent;
console.error('This video can\'t be shared. (' + description + ')');
throw new Error(description);
}
ctx.title = xml.getElementsByTagName('title')[0].textContent;
ctx.href = xml.getElementsByTagName('watch_url')[0].textContent;
var embeddable = xml.getElementsByTagName('embeddable')[0].textContent;
var thumbnail = xml.getElementsByTagName('thumbnail_url')[0].textContent;
var description = xml.getElementsByTagName('description')[0].textContent;
if (embeddable) {
return {
type : 'video',
item : ctx.title,
itemUrl : ctx.href,
body : '<embed type="application/x-shockwave-flash" width="485" height="385" src="' + externalPlayerURL + '"/>',
data : {
thumbnail : thumbnail,
description : description
}
};
}
else {
return {
type : 'photo',
item : ctx.title,
itemUrl : thumbnail,
body : description
};
}
});
}
});
})();
@YungSang
Copy link
Author

ちょっと強引すぎるかもなぁ

@syoichi
Copy link

syoichi commented Apr 28, 2013

Extractorの段階でCookieの操作を行うのは何らかの副作用があるかもしれませんね。
より正確に情報を取得するならば、http://ext.nicovideo.jp/api/getthumbinfo/sm9 のようなAPIを利用した方が良いかもしれません。

@YungSang
Copy link
Author

おお!そんなのもあるんですね!

@YungSang
Copy link
Author

http://ext.nicovideo.jp/api/getthumbinfo/ を使うバージョンも試してみました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment