Last active
December 16, 2015 18:09
-
-
Save YungSang/5476071 to your computer and use it in GitHub Desktop.
[Deprecated] Taberareloo 用のニコニコ動画 Extractor この実装は推奨されません。こちらで対応されています。https://github.com/Constellation/taberareloo/pull/194
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() { | |
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 | |
}; | |
} | |
}); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extractorの段階でCookieの操作を行うのは何らかの副作用があるかもしれませんね。
より正確に情報を取得するならば、http://ext.nicovideo.jp/api/getthumbinfo/sm9 のようなAPIを利用した方が良いかもしれません。