Class: Nicovideo
Instance Method Summary collapse
- #download(name) ⇒ Object
-
#initialize(url, options) ⇒ Nicovideo
constructor
A new instance of Nicovideo.
Methods inherited from WebRadio
Constructor Details
#initialize(url, options) ⇒ Nicovideo
Returns a new instance of Nicovideo.
9 10 11 12 13 14 15 16 17 |
# File 'lib/nicovideo.rb', line 9 def initialize(url, ) account = Pit::get('nicovideo', :require => { :id => 'your nicovideo id', :pass => 'your nicovideo password' }) @nico = Niconico.new(account[:id], account[:pass]) @nico.login super end |
Instance Method Details
#download(name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nicovideo.rb', line 19 def download(name) player_url = get_player_url(@url) video = @nico.video(Pathname(URI(player_url).path).basename.to_s) serial = video.title.scan(/(?:[#第]|[ ]EP|track-)(\d+)|/).flatten.compact[0].to_i @file = "#{name}##{'%02d' % serial}.#{video.type}" @mp3_file = @file.sub(/\....$/, '.mp3') mp3nize(@file, @mp3_file) do open(@file, 'wb:ASCII-8BIT') do |o| begin video.get_video do |body| print '.' o.write(body) end rescue Niconico::Video::VideoUnavailableError => e raise DownloadError.new(e.) end end end end |