Parent

Included Modules

Files

Nicovideo::OpenList

This class doesn't access NICONICO DOUGA when an instance created. At the first time you call this instance method, this accesses NICONICO

Attributes

pagenum[R]

Public Class Methods

new(agent, video_id, sort='c', order='d', pagenum=1) click to toggle source
# File lib/nicovideo/openlist.rb, line 10
def initialize agent, video_id, sort='c', order='d', pagenum=1
  super(agent)
  @video_id = video_id
  @pagenum  = pagenum
  @sort     = sort
  @order    = order
  @url      = url()

  params = ["mylists", "total_size", "has_next?", "has_prev?"]
  self.register_getter params
end

Public Instance Methods

each() click to toggle source
# File lib/nicovideo/openlist.rb, line 31
def each
  self.mylists.each {|ml|
    yield ml
  }
end
id() click to toggle source
# File lib/nicovideo/openlist.rb, line 24
def id() @video_id end
next() click to toggle source
# File lib/nicovideo/openlist.rb, line 52
def next
  self.pagenum = @pagenum + 1
  self
end
page=(pagenum) click to toggle source
# File lib/nicovideo/openlist.rb, line 47
def page=(pagenum)
  self.pagenum = pagenum
  self
end
pagenum=(pagenum) click to toggle source
# File lib/nicovideo/openlist.rb, line 39
def pagenum=(pagenum)
  if @pagenum != pagenum
    @pagenum = pagenum
    get_page(self.url, true)
  end
  @pagenum
end
prev() click to toggle source
# File lib/nicovideo/openlist.rb, line 57
def prev
  self.pagenum = @pagenum - 1
  self
end
to_a() click to toggle source
# File lib/nicovideo/openlist.rb, line 37
def to_a() self.mylists end
url() click to toggle source

call whenever pagenum changed

# File lib/nicovideo/openlist.rb, line 27
def url
  @url = BASE_URL + '/openlist/' + @video_id + "?page=#{@pagenum}&sort=#{@sort}&order=#{@order}"
end

Protected Instance Methods

parse(page) click to toggle source
# File lib/nicovideo/openlist.rb, line 63
def parse(page)
  if page.body =~ /<strong.*?>#{@video_id}<\/strong> を登録している公開マイリストはありません。/
    @not_found = true
    raise NotFound
  end

  @total_size = page.search('//div[@class="mb8p4"]//p[@class="TXT12"]//strong').first.inner_html.sub(/,/,'').to_i

  @has_next = false
  @has_prev = false
  respages = page/'//div[@class="pagelink"]'
  puts_info respages.size
  respages.each {|r| puts_info r.inner_html }
  if respages.size > 0
    respages.each {|text|
      if text.inner_html =~ /<a class="prevpage".*?>.*?戻る.*?<\/a>/
        @has_prev = true
      end
      if text.inner_html =~ /<a class="nextpage".*?>.*?進む.*?<\/a>/
        @has_next = true
      end
    }
  end

  scanpattern = /<a href=\"#{BASE_URL}\/mylist\/(\d+)\">(.+?)<\/a>/u
  listrefs = page.parser.to_html.scan(scanpattern)
  @mylists = listrefs.inject([]) {|arr, v| # v[0]: mylist id, v[1]: mylist title
    ml = MyList.new(@agent, v[0])
    ml.title = v[1]
    arr << ml
  }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.