Class: Niconico::Live::Mypage

Inherits:
Object
  • Object
show all
Defined in:
lib/niconico/live/mypage.rb

Defined Under Namespace

Classes: UnknownStatus

Constant Summary collapse

URL =
'http://live.nicovideo.jp/my'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Mypage

Returns a new instance of Mypage.



15
16
17
# File 'lib/niconico/live/mypage.rb', line 15

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



19
20
21
# File 'lib/niconico/live/mypage.rb', line 19

def client
  @client
end

Instance Method Details

#agentObject



21
22
23
# File 'lib/niconico/live/mypage.rb', line 21

def agent
  client.agent
end

#available_reservationsObject



58
59
60
# File 'lib/niconico/live/mypage.rb', line 58

def available_reservations
  reservations.select { |_| _.reservation_available? }
end

#pageObject



25
26
27
# File 'lib/niconico/live/mypage.rb', line 25

def page
  @page ||= agent.get(URL)
end

#reservationsObject Also known as: timeshift_list



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/niconico/live/mypage.rb', line 29

def reservations
  return @reservations if @reservations
  lists = page.search("form[name=timeshift_list] .liveItems")
  @reservations = lists.flat_map do |list|
    list.search('.column').map do |column|
      link = column.at('.name a')
      id = link[:href].sub(/\A.*\//,'').sub(/\?.*\z/,'')
      status = column.at('.status').inner_text 
      watch_button = column.at('.timeshift_watch a')

      preload = {}

      preload[:title] = link[:title]

      preload[:reservation] = Live::API.parse_reservation_message(status)
      raise UnknownStatus, "BUG, there's unknown message for reservation status: #{status.inspect}" unless preload[:reservation]

      # (試聴する) [試聴期限未定]
      if watch_button && watch_button[:onclick] && watch_button[:onclick].include?('confirm_watch_my')
        preload[:reservation][:status] = :reserved
        preload[:reservation][:available] = true
      end

      Niconico::Live.new(client, id, preload)
    end
  end
end

#unaccepted_reservationsObject



62
63
64
# File 'lib/niconico/live/mypage.rb', line 62

def unaccepted_reservations
  reservations.select { |_| _.reservation_unaccepted? }
end