aboutsummaryrefslogtreecommitdiffstats
path: root/nicolist.js
diff options
context:
space:
mode:
authorebith2014-02-19 08:40:54 +0900
committerebith2014-02-19 08:40:54 +0900
commit03d7f9a83da6f95add45486cea104c2c1a8898fa (patch)
tree5e71cbd4995cdcb03879d0822d27dbdfbac2380e /nicolist.js
parent3b290246be03aedb80f365f3397539417ce2d2fa (diff)
downloadvimperator-plugins-03d7f9a83da6f95add45486cea104c2c1a8898fa.tar.bz2
動画を再生するコマンド付けた
Diffstat (limited to 'nicolist.js')
-rw-r--r--nicolist.js92
1 files changed, 91 insertions, 1 deletions
diff --git a/nicolist.js b/nicolist.js
index 3c19fcc..0ebb7a4 100644
--- a/nicolist.js
+++ b/nicolist.js
@@ -33,6 +33,7 @@ var INFO = xml`
</item>
</plugin>`;
+let video = {};
commands.addUserCommand(
['nicolist'],
'ニコニコ動画のマイリストを操作する',
@@ -61,6 +62,84 @@ commands.addUserCommand(
}
),
new Command(
+ ['p[lay]'],
+ '動画を再生する',
+ function (args) {
+ let [mylist_id, video_id] = args;
+ let video_ids = []
+ if (video_id) {
+ video_ids = [video_id];
+ } else if (mylist_id) {
+ let list = JSON.parse(util.httpGet('http://www.nicovideo.jp/api/mylist/list?group_id=' + mylist_id).responseText).mylistitem;
+ list.forEach(function(v){
+ video_ids.push(v.item_data.video_id);
+ });
+ } else { return; }
+ video_ids = video_ids.shuffle();
+ let i = 0;
+
+ video.container = document.createElementNS('http://www.w3.org/1999/xhtml', 'video');
+ video.container.volume = 0.7; // 効いてない
+ video.container.autoplay = true;
+ ['error', 'ended'].forEach(function(event) {
+ video.container.addEventListener(event, function() {
+ if (video.container.src === 'chrome://browser/content/browser.xul') { return; }
+ if (!video_ids[i]) { return; }
+ i++;
+ setupVideo();
+ });
+ });
+
+ setupVideo();
+
+ function setupVideo() {
+ video.flv = {}
+ util.httpGet('http://flapi.nicovideo.jp/api/getflv/' + video_ids[i]).responseText.split('&').forEach(function(param){
+ let tmp = param.split('=');
+ video.flv[tmp[0]] = decodeURIComponent(tmp[1]);
+ });
+
+ video.thumbinfo = util.httpGet('http://ext.nicovideo.jp/api/getthumbinfo/' + video_ids[i]).responseXML;
+ video.video_id = video.thumbinfo.getElementsByTagName('video_id')[0].firstChild.nodeValue;
+ video.title = video.thumbinfo.getElementsByTagName('title')[0].firstChild.nodeValue;
+ video.description = video.thumbinfo.getElementsByTagName('description')[0].firstChild.nodeValue;
+
+ util.httpGet('http://www.nicovideo.jp/watch/' + video_ids[i]); // watchページにアクセスしておかないと読み込み時403
+ video.container.src = video.flv.url;
+ }
+ },
+ {
+ literal: 1,
+ completer: mylistCompleter,
+ }
+ ),
+ new Command(
+ ['s[top]'],
+ '動画の再生を止める',
+ function (args) {
+ video.container.pause();
+ video.container.src = ''; // chrome://browser/content/browser.xul になる
+ }
+ ),
+ new Command(
+ ['now[Playing]'],
+ '再生中の動画情報',
+ function (arg) {
+ if (arg) {
+ let url = 'http://www.nicovideo.jp/watch/' + arg;
+ liberator.open(url, liberator.NEW_TAB);
+ }
+ },
+ {
+ literal: 0,
+ completer: function(context, args) {
+ context.filters = [CompletionContext.Filter.textDescription];
+ context.title = ['id', 'title']
+ context.completions = [[video.video_id, video.title]]
+ }
+ }
+ ),
+ new Command(
['o[pen]'],
'マイリストか動画を開く',
function (args) {
@@ -141,7 +220,7 @@ function mylistCompleter (context, args) {
util.httpGet(url, function (xhr) {
context.incomplete = false;
- if (/open/.test(context.name)) {
+ if (/open|play/.test(context.name)) {
context.completions = [
[v.item_data.video_id, v.item_data.title]
for ([k, v] in Iterator(JSON.parse(xhr.responseText).mylistitem.sort(sorter)))
@@ -169,3 +248,14 @@ function getToken (isWatchPage) {
return util.httpGet(url).responseText.match(/NicoAPI\.token.+/)[0].match(/\d{5}-\d{10}-[\d\w]{40}/)[0];
}
}
+
+Array.prototype.shuffle = function() {
+ var i = this.length;
+ while(i){
+ var j = Math.floor(Math.random()*i);
+ var t = this[--i];
+ this[i] = this[j];
+ this[j] = t;
+ }
+ return this;
+}