Skip to content

Commit

Permalink
Fixed #3
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed Apr 25, 2015
1 parent d61b316 commit 1428ef7
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
@@ -1,8 +1,16 @@
v0.0.3 / Apr 25 2015
=========================
* [`unknown`][3] :bug: Fix [#3][3A]
* [`unknown`][3] :lipstick: Change .getPlayerStatus callback arguments `error,playerStatus` -> `error,rawBody,playerStatus`

[3]: https://github.com/59naga/nicolive/commits/master
[3A]: https://github.com/59naga/nicolive/issues/3

v0.0.2 / Apr 25 2015
=========================
* [`unknown`][2] Fix [#2][2A]
* [`97fb93b`][2] :bug: Fix [#2][2A]

[2]: https://github.com/59naga/nicolive/commits/master
[2]: https://github.com/59naga/nicolive/commit/97fb93b61f2d5536139cdc796bb6147fbab89eb5
[2A]: https://github.com/59naga/nicolive/issues/2

v0.0.1 / Apr 24 2015
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -35,7 +35,7 @@ password: ******
# Authorized.

# Request to http://live.nicovideo.jp/api/getplayerstatus/nsen/hotaru
# Player status { port: '2805',addr: 'omsg103.live.nicovideo.jp',thread: '1431971701',version: '20061206',res_from: -5,user_id: '47972775',premium: '0',comment_count: '25',mail: '184' }
# Player status { port: '2805',addr: 'omsg103.live.nicovideo.jp',title: 'Nsen - 蛍の光チャンネル',description: 'Nsenからの去り際に...',thread: '1431971701',version: '20061206',res_from: -5,user_id: '47972775',premium: '0',comment_count: '25',mail: '184' }
# Connect to http://omsg103.live.nicovideo.jp:2805/api/thread?thread=1431971701&version=20061206&res_from=-5
# Or static http://omsg103.live.nicovideo.jp:80/api/thread?thread=1431971701&version=20061206&res_from=-5
# Received raw <thread resultcode="0" thread="1431971701" last_res="2257" ticket="0xc998880" revision="1" server_time="1429935582"/><chat ...
Expand Down Expand Up @@ -70,7 +70,7 @@ nicolive.login('your@email.address','********',function(error,cookie){
if(error) throw error;

viewer.on('handshaked',function(){
nicolive.comment('わこつ');
nicolive.comment('わこつ',{mail:'184'});
});
viewer.on('comment',function(comment){
console.log(comment.text);// わこつ
Expand Down
2 changes: 1 addition & 1 deletion lib/nicolive/cli.coffee
Expand Up @@ -44,6 +44,6 @@ module.exports= (argv)->
return console.error error if error?

viewer.on 'handshaked',=>
@comment cli.args[1] if cli.args[1]
@comment cli.args[1],cli if cli.args[1]
viewer.on 'comment',(comment)->
console.log h2('Received',(comment.attr.no ? '-')+':'),comment.text
2 changes: 1 addition & 1 deletion lib/nicolive/comment.coffee
Expand Up @@ -10,7 +10,7 @@ h1= chalk.underline.magenta
module.exports= (text,args...,callback)->
options= args[0] ? {}
callback= options if typeof options is 'function'
callback?= ((error)-> throw error if error)
callback= ((error)-> throw error if error) if typeof callback isnt 'function'
return callback new Error 'Disconnected' unless @viewer?

@getPostKey options,(error,postkey)=>
Expand Down
12 changes: 9 additions & 3 deletions lib/nicolive/get-player-status.coffee
Expand Up @@ -17,14 +17,17 @@ module.exports= (live_id,args...,callback)->
Cookie: @get()
,(error,res,body)=>
errorMessage= cheerio(body).find('error code').text()
return callback error if error?
return callback errorMessage if errorMessage.length
return callback error,body if error?
return callback errorMessage,body if errorMessage.length

playerStatus= cheerio body
ms= playerStatus.find('ms')
port= ms.find('port').eq(0).text()
addr= ms.find('addr').eq(0).text()

title= playerStatus.find('title').eq(0).text()
description= playerStatus.find('description').eq(0).text()

thread= ms.find('thread').eq(0).text()
version= '20061206'
res_from= -1*options.from if options.from?
Expand All @@ -38,6 +41,9 @@ module.exports= (live_id,args...,callback)->
port
addr

title
description

thread
version
res_from
Expand All @@ -47,4 +53,4 @@ module.exports= (live_id,args...,callback)->
mail
}
console.log h1('Player status'),statuses if options.verbose
callback null,statuses
callback null,body,statuses
2 changes: 1 addition & 1 deletion lib/nicolive/view.coffee
Expand Up @@ -11,7 +11,7 @@ h1= chalk.underline.magenta
module.exports= (live_id,args...,callback)->
options= args[0] ? {}

@getPlayerStatus live_id,options,(error,playerStatus)=>
@getPlayerStatus live_id,options,(error,body,playerStatus)=>
return callback error if error?
@playerStatus= playerStatus
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"main": "nicolive",
"bin" : "nicolive",
"description": "Command line comment viewer",
"version": "0.0.2",
"version": "0.0.3",

"scripts": {
"oldstart": "node nicolive",
Expand Down
8 changes: 4 additions & 4 deletions test/nicolive.spec.coffee
Expand Up @@ -21,7 +21,7 @@ describe 'nicolive',->
done()

it 'Logged in',(done)->
nicolive.ping (error,playerStatus)->
nicolive.ping (error,rawBody,playerStatus)->
expect(error).toBe null
expect(playerStatus.version).toEqual '20061206'

Expand Down Expand Up @@ -70,7 +70,7 @@ describe 'nicolive',->

describe '.ping',->
it 'Fetch playerStatus by nsen/vocaloid',(done)->
nicolive.ping (error,playerStatus)->
nicolive.ping (error,rawBody,playerStatus)->
expect(error).toBe null
expect(playerStatus.version).toBe '20061206'
expect(playerStatus.addr).toContain 'live.nicovideo.jp'
Expand All @@ -80,7 +80,7 @@ describe 'nicolive',->

describe '.getPlayerStatus',->
it 'Fetch playerStatus by live_id',(done)->
nicolive.getPlayerStatus 'nsen/hotaru',(error,playerStatus)->
nicolive.getPlayerStatus 'nsen/hotaru',(error,rawBody,playerStatus)->
expect(error).toBe null
expect(playerStatus.version).toBe '20061206'
expect(playerStatus.addr).toContain 'live.nicovideo.jp'
Expand Down Expand Up @@ -112,7 +112,7 @@ describe 'nicolive',->

describe '.logout',->
it 'Logged in',(done)->
nicolive.ping (error,playerStatus)->
nicolive.ping (error,rawBody,playerStatus)->
expect(error).toBe null
expect(playerStatus.version).toEqual '20061206'

Expand Down

0 comments on commit 1428ef7

Please sign in to comment.