Module: CommentMove

Included in:
NicovideoAccount
Defined in:
lib/comment_move/login.rb,
lib/comment_move/version.rb,
lib/comment_move/get_waybackkey.rb,
lib/comment_move/get_playerstatus.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#get_playerstatus(lv, user_session) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/comment_move/get_playerstatus.rb', line 5

def get_playerstatus(lv, user_session)
  url = Net::HTTP.new('watch.live.nicovideo.jp')
  res = url.get("/api/getplayerstatus?v=#{lv}", {'Cookie' => "user_session=#{user_session}"})
  xml = Nokogiri::XML(res.body)

  {
    user: xml.xpath('//user/user_id').text,
    addr: xml.xpath('//ms//addr').text,
    port: xml.xpath('//ms//port').text.to_i,
    thread: xml.xpath('//ms//thread').text
  }
end

#get_waybackkey(thread, user_session) ⇒ Object



5
6
7
8
9
# File 'lib/comment_move/get_waybackkey.rb', line 5

def get_waybackkey(thread, user_session)
  url = Net::HTTP.new('watch.live.nicovideo.jp')
  res = url.get("/api/getwaybackkey?thread=#{thread}", {'Cookie' => "user_session=#{user_session}"})
  res.body[/waybackkey=(.+)/, 1]
end

#login(mail, password) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/comment_move/login.rb', line 4

def (mail, password)
  https = Net::HTTP.new('secure.nicovideo.jp', 443)
  https.use_ssl = true
  https.verify_mode = OpenSSL::SSL::VERIFY_NONE
  response = https.start do |https|
    https.post('/secure/login?site=niconico', "mail=#{mail}&password=#{password}")
  end

  user_session = nil
  response.get_fields('set-cookie').each do |cookie|
    cookie.split('; ').each do |param|
      pair = param.split('=')
      if pair[0] == 'user_session'
        user_session = pair[1] unless pair[1] == 'deleted'
        break
      end
    end
    break unless user_session.nil?
  end
  user_session
end