Object
# File lib/nicovideo/base.rb, line 10 def initialize mail=nil, password=nil, auto_login=true @mail = mail @password = password @agent = WWW::Mechanize.new() agent_init(auto_login) @agent.set_account(@mail, @password) # for parameters current video @vp = nil self end
# File lib/nicovideo/base.rb, line 24 def agent_init auto_login=true @agent.instance_eval do alias raw_get get alias raw_post post def set_account(mail, password) @mail=mail; @password=password end def authenticated?(page) page.header['x-niconico-authflag'] != '0' end def login raise ArgError unless (@mail && @password) account = {'mail' => @mail, 'password' => @password } res = raw_post('https://secure.nicovideo.jp/secure/login?site=niconico', account) raise LoginError unless authenticated?(res) end end if auto_login @agent.instance_eval do @wait_time = 3 def get(*args) try(:raw_get, *args) end def post(*args) try(:raw_post, *args) end def try(name, *args) page = method(name).call(*args) unless authenticated?(page) self.login sleep @wait_time page = method(name).call(*args) raise LoginError unless authenticated?(page) end page end end end end
# File lib/nicovideo/base.rb, line 30 def authenticated?(page) page.header['x-niconico-authflag'] != '0' end
# File lib/nicovideo/base.rb, line 45 def get(*args) try(:raw_get, *args) end
# File lib/nicovideo/base.rb, line 96 def get_comments video_id, num=500 get_videopage(video_id).comments(num) end
# File lib/nicovideo/base.rb, line 92 def get_flv(video_id) get_videopage(video_id).flv end
# File lib/nicovideo/base.rb, line 84 def get_title(video_id) get_videopage(video_id).title end
# File lib/nicovideo/base.rb, line 88 def get_video(video_id) self.get_flv(video_id) end
# File lib/nicovideo/base.rb, line 34 def login raise ArgError unless (@mail && @password) account = {'mail' => @mail, 'password' => @password } res = raw_post('https://secure.nicovideo.jp/secure/login?site=niconico', account) raise LoginError unless authenticated?(res) end
# File lib/nicovideo/base.rb, line 100 def mylist(mylist_id) MyList.new(@agent, mylist_id) end
# File lib/nicovideo/base.rb, line 112 def newarrival(pagenum=1) Newarrival.new(@agent,pagenum) end
# File lib/nicovideo/base.rb, line 104 def openlist(video_id) OpenList.new(@agent, video_id) end
# File lib/nicovideo/base.rb, line 46 def post(*args) try(:raw_post, *args) end
# File lib/nicovideo/base.rb, line 108 def random() Random.new(@agent) end
type : 'mylist', 'view' or 'res' span : 'daily', 'newarrival', 'weekly', 'monthly', 'total' category : 'all', 'music' ... and more
# File lib/nicovideo/base.rb, line 119 def ranking(type='mylist', span='daily', category='all', pagenum=nil) Ranking.new(@agent, type, span, category, pagenum).to_a end
keyword : search keyword sort : nil -> published date
'v' -> playback times 'n' -> commented date 'r' -> comment number 'm' -> mylist number
# File lib/nicovideo/base.rb, line 129 def search(keyword, sort=nil, order=nil, pagenum=1) Search.new(@agent, keyword, sort, order, pagenum) end
# File lib/nicovideo/base.rb, line 29 def set_account(mail, password) @mail=mail; @password=password end
Generated with the Darkfish Rdoc Generator 2.