Class: Niconico::Video
- Includes:
- Helper
- Defined in:
- lib/nv/niconico/video.rb
Instance Attribute Summary
Attributes inherited from Fabric
Instance Method Summary collapse
- #download(output = ".") ⇒ Object
-
#initialize(ptr, agent = nil) ⇒ Video
constructor
A new instance of Video.
-
#method_missing(method, *args) ⇒ Object
Combined parameter fetcher.
Methods included from Helper
Methods inherited from Fabric
Constructor Details
#initialize(ptr, agent = nil) ⇒ Video
Returns a new instance of Video.
5 6 7 8 9 10 11 |
# File 'lib/nv/niconico/video.rb', line 5 def initialize(ptr, agent=nil) super(agent) @thumb = nil @flv = nil @id = normalize(ptr) # pvid | thumb_cached end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Combined parameter fetcher
43 44 45 |
# File 'lib/nv/niconico/video.rb', line 43 def method_missing(method, *args) thumb[method] || flv[method] || raise(NoMethodError, method) end |
Instance Method Details
#download(output = ".") ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nv/niconico/video.rb', line 13 def download(output=".") escapedTitle = thumb.title.gsub(/\//, "/") filename = "#{escapedTitle} - [#{thumb.video_id}].#{thumb.extension}" filepath = File.join(output, filename) Dir.mkdir(output) unless Dir.exist? output = nil File.open(filepath, 'wb') do |fp| open(flv.url, 'rb', 'Cookie' => flv., :content_length_proc => lambda{ |content_length| if content_length = ProgressBar.create(:total => content_length) end }, :progress_proc => lambda{ |transferred_bytes| if .progress = transferred_bytes else puts "#{transferred_bytes} / Total size is unknown" end } ) do |f| fp.print f.read end end end |