Skip to content

Instantly share code, notes, and snippets.

@Tosainu
Created August 14, 2014 04:27
Show Gist options
  • Save Tosainu/75bda82150eeebe2592c to your computer and use it in GitHub Desktop.
Save Tosainu/75bda82150eeebe2592c to your computer and use it in GitHub Desktop.
ニコ動にログインしてデフォルトのマイリスト(とりあえずマイリスト)を取得
var request = require('request').defaults({jar: true});
var options_login = {
url: 'https://secure.nicovideo.jp/secure/login?site=niconico',
form: {
mail_tel: 'YOUR MAIL ADDR',
password: 'YOUR PASSWORD'
}
};
// login niconico
request.post(options_login, function(error, response) {
if (error) {
console.log(error);
} else if (response.statusCode !== 302 || response.headers.location !== 'http://www.nicovideo.jp/') {
console.log('login failed.');
} else {
// get token
request({url: 'http://www.nicovideo.jp/my/mylist'}, function(error, response, body) {
if (error) {
console.log(error);
} else if (response.statusCode !== 200) {
console.log('failed to get the token.');
} else {
// parse token
body.match(/\s*NicoAPI\.token = "([\d\w-]+)";/);
var token = RegExp.$1;
// get deflist
request.post({url: 'http://www.nicovideo.jp/api/deflist/list', form: {token: token}}, function(error, response, body) {
if (error) {
console.log(error);
} else if (response.statusCode !== 200) {
console.log('failed to get the deflist.');
} else {
JSON.parse(body).mylistitem.forEach(function(item) {
console.log(item.item_data);
});
}
});
}
});
}
});
{
"name": "niconico",
"version": "0.0.0",
"description": "login niconico and get default mylist",
"main": "niconico.js",
"author": "Tosainu",
"license": "MIT",
"dependencies": {
"request": "^2.40.0",
"tough-cookie": "^0.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment