node-nicovideo-api
Version:
nicovideo api (video, live, etc..) wrapper package for node.js
208 lines (164 loc) • 5.46 kB
JavaScript
// Generated by CoffeeScript 1.10.0
/**
* マイリストの項目モデルです。
*
* Properties
* getメソッドを通じて第1階層まで取得できます。
* Example. mylistItem.get("movie").title
*
* - id : number -- マイリスト項目ID
* - type : number -- 項目の種類(動画、静画など)
* - description : string -- マイリストコメント
* - createTime : Date -- 追加日
* - updateTime : Date -- 更新日(?)
* - watch : number -- 不明
* - movie : Object -- 動画情報
* - id : string -- 動画ID
* - title : string -- 動画タイトル
* - length : number -- 動画の長さ(秒)
* - thumbnail : string -- サムネイル画像のURL
*
* - groupType : string -- 不明
* - lastResponse : string -- 最近投稿されたコメントの一部
* - isDeleted : boolean -- 削除されているか
*
* - updateTime : Date -- この情報の最終更新日時(?)
* - firtsRetrieve : Date -- 動画投稿日
*
* - count -- カウンタ系の情報が詰められたオブジェクト
* - view : number -- 再生数
* - comments : number -- コメント数
* - mylist : number -- マイリスト数
*
* @class MyListItem
*/
(function() {
var Emitter, Ent, MyListItem, _, __, deepFreeze, sprintf,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
_ = require("lodash");
__ = require("lodash-deep");
Ent = require("ent");
Emitter = require("../Emitter");
sprintf = require("sprintf").sprintf;
deepFreeze = require("deep-freeze");
module.exports = MyListItem = (function(superClass) {
extend(MyListItem, superClass);
function MyListItem() {
return MyListItem.__super__.constructor.apply(this, arguments);
}
/**
* @static
* @property {Object} ItemTypes アイテムの種類のリスト
* @property {Number} ItemTypes.movie 動画
* @property {Number} ItemTypes.seiga 静画
*/
MyListItem.ItemTypes = deepFreeze({
MOVIE: 0,
SEIGA: 5,
BOOK: 6,
BLOMAGA: 13
});
MyListItem.defaults = {
id: -1,
type: -1,
description: null,
createTime: null,
updateTime: null,
watch: 0,
movie: null
};
/**
* MylistAPIの取得結果の一部からMyListItemのオブジェクトを生成します。
* @static
* @method fronApiResponse
* @param {Object} itemInfo
* @param {MyList} mylist
*/
MyListItem.fromApiResponse = function(itemInfo, mylist) {
var item;
item = new MyListItem;
item._attr = deepFreeze(MyListItem.parse(itemInfo));
item.list = mylist;
return Object.defineProperties(item, {
id: {
value: item.get("id") | 0
}
});
};
MyListItem.parse = function(itemInfo) {
var attr, item;
item = itemInfo.item_data;
attr = {
id: itemInfo.item_id | 0,
type: itemInfo.item_type | 0,
description: itemInfo.description,
watch: itemInfo.watch,
createTime: new Date(itemInfo.create_time * 1000),
updateTime: new Date(itemInfo.update_time),
movie: {
id: item.video_id,
title: Ent.decode(item.title),
length: item.length_seconds | 0,
thumbnail: item.thumbnail_url,
groupType: item.group_type,
lastResponse: item.last_res_body,
isDeleted: item.deleted !== "0",
updateTime: new Date(item.update_time * 1000),
firtsRetrieve: new Date(item.first_retrieve * 1000),
count: {
view: item.view_counter | 0,
comments: item.num_res | 0,
mylist: item.mylist_counter | 0
}
}
};
return attr;
};
/**
* @private
* @property {Object} _attr
*/
/**
* @property {Number} id
*/
/**
* @param {String} path
* @return
*/
MyListItem.prototype.get = function(path) {
return __.deepGet(this._attr, path);
};
/**
* @return {Promise}
*/
MyListItem.prototype["delete"] = function() {
return this.list.deleteItem(this);
};
/**
* @return {Boolean}
*/
MyListItem.prototype.isMovie = function() {
return this.get("type") === MyListItem.ItemTypes.MOVIE;
};
/**
* @return {Boolean}
*/
MyListItem.prototype.isSeiga = function() {
return this.get("type") === MyListItem.ItemTypes.SEIGA;
};
/**
* @return {Boolean}
*/
MyListItem.prototype.isBook = function() {
return this.get("type") === MyListItem.ItemTypes.BOOK;
};
/**
* @return {Boolean}
*/
MyListItem.prototype.isBlomaga = function() {
return this.get("type") === MyListItem.ItemTypes.BLOMAGA;
};
return MyListItem;
})(Emitter);
}).call(this);