Class: Nicovideo::VideoPage

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

Constant Summary

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

Constructor Details

#initialize(agent, video_id) ⇒ VideoPage

Returns a new instance of VideoPage.



6
7
8
9
10
11
12
# File 'lib/nicovideo/videopage.rb', line 6

def initialize agent, video_id
  super(agent)
  @video_id = video_id
  @params   = nil
  @url      = BASE_URL + '/watch/' + @video_id
  register_getter ["title", "tags", "published_at", "csrf_token"]
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



14
15
16
# File 'lib/nicovideo/videopage.rb', line 14

def url
  @url
end

#video_idObject (readonly)

Returns the value of attribute video_id.



14
15
16
# File 'lib/nicovideo/videopage.rb', line 14

def video_id
  @video_id
end

Instance Method Details

#comments(num = 500) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nicovideo/videopage.rb', line 32

def comments(num=500)
  puts_info 'getting comment xml : id = ' + @video_id
  begin
    @params = get_params unless @params
    ms = @params['ms']
    raise ArgError unless ms
    
    thread_id = @params['thread_id']
    body = %!<thread res_from="-#{num}" version="20061206" thread="#{thread_id}" />!
    post_url = CGI.unescape(ms)
    comment_xml = @agent.post_data(post_url, body).body
    puts_debug comment_xml
    Comments.new(@video_id, comment_xml)
  end
end

#flvObject



48
# File 'lib/nicovideo/videopage.rb', line 48

def flv() return video() end

#idObject



16
# File 'lib/nicovideo/videopage.rb', line 16

def id()   @video_id end

#low?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/nicovideo/videopage.rb', line 67

def low?
  @params ||= get_params
  return true if CGI.unescape(@params['url']) =~ /low$/
  return false
end

#openlist(page = 1) ⇒ Object



63
64
65
# File 'lib/nicovideo/videopage.rb', line 63

def openlist(page=1)
  OpenList.new(@agent, @video_id)
end

#title=(title) ⇒ Object



59
60
61
# File 'lib/nicovideo/videopage.rb', line 59

def title=(title)
  @title = title
end

#typeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nicovideo/videopage.rb', line 18

def type
  @params ||= get_params
  pattern = %r!^http://.*\.nicovideo\.jp/smile\?(.*?)=.*$!
  CGI.unescape(@params['url']) =~ pattern
  case $1
  when 'm'
    return 'mp4'
  when 's'
    return 'swf'
  else
    return 'flv'
  end
end

#videoObject



50
51
52
53
54
55
56
57
# File 'lib/nicovideo/videopage.rb', line 50

def video()
  begin
    @params ||= get_params
    video_url = CGI.unescape(@params['url'])
    video_flv = @agent.get_file(video_url)
    video_flv
  end
end