Class: Nicovideo::MyList

Inherits:
Page
  • Object
show all
Defined in:
lib/nicovideo/mylist.rb

Constant Summary collapse

NICO_MYLIST =
'マイリスト'

Constants inherited from Page

Page::BASE_TITLE1, Page::BASE_TITLE2, Page::BASE_URL, Page::NV_DEBUG_LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Page

#exists?, #html, #title=

Constructor Details

#initialize(agent, mylist_id) ⇒ MyList

Returns a new instance of MyList.



12
13
14
15
16
17
18
19
20
# File 'lib/nicovideo/mylist.rb', line 12

def initialize agent, mylist_id
  super(agent)
  @mylist_id = mylist_id
  @raw_url = BASE_URL + '/mylist/' + @mylist_id
  @url     = BASE_URL + '/mylist/' + @mylist_id + '?rss=2.0'

  params = ["title", "user", "description", "videos", "rss"]
  self.register_getter params
end

Instance Attribute Details

#myliset_idObject (readonly)

Returns the value of attribute myliset_id.



22
23
24
# File 'lib/nicovideo/mylist.rb', line 22

def myliset_id
  @myliset_id
end

Instance Method Details

#add(video_id) ⇒ Object



27
28
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
56
57
58
59
60
# File 'lib/nicovideo/mylist.rb', line 27

def add(video_id)
  video_page = VideoPage.new @agent, video_id

  begin
    add_result = @agent.post(video_page.url, {
        :mylist => "add",
        :mylistgroup_name => "",
        :csrf_token => video_page.csrf_token,
        :group_id => @mylist_id,
        :ajax => "1"})

    result_code = JSON.parse(add_result.body.sub(/^\(?(.*?)\)?$/, '\1'))

    if result_code["result"] == "success" then
      # added video isn't applied to rss immediately, so add video into list by hand.
      page = @page || get_page(@url)
      @videos << video_page
      return self
    end
    raise ArgError if result_code["result"] == "duperror"
    raise StandardError
  rescue WWW::Mechanize::ResponseCodeError => e
    rc = e.response_code
    puts_info rc
    if rc == "404" || rc == "410"
      @not_found = true
      raise NotFound
    elsif rc == "403"
      raise Forbidden
    else
      raise e
    end
  end
end

#idObject



24
# File 'lib/nicovideo/mylist.rb', line 24

def id()  @mylist_id end

#urlObject



25
# File 'lib/nicovideo/mylist.rb', line 25

def url() @raw_url   end