Class: YoutubeTools::Downloader
- Inherits:
-
Object
- Object
- YoutubeTools::Downloader
- Defined in:
- lib/youtube_tools/downloader.rb
Constant Summary collapse
- LINK_PATTERN =
/"fmt_stream_map": ("[\w |:\/\\.?=&\,%-]+")/
- NAME_PATTERN =
/-\s+(.*)\s*/
- QUALITY =
{ :low => 5, :mp4 => 18, :mid => 34, :hd => 22, :hight => 35 }
Instance Attribute Summary collapse
-
#full_path ⇒ Object
Returns the value of attribute full_path.
-
#href ⇒ Object
Returns the value of attribute href.
-
#link_dw ⇒ Object
Returns the value of attribute link_dw.
-
#links ⇒ Object
Returns the value of attribute links.
-
#name ⇒ Object
Returns the value of attribute name.
-
#quality ⇒ Object
Returns the value of attribute quality.
Instance Method Summary collapse
-
#download_video ⇒ Object
method dowload video from selected folder.
-
#initialize(href, options = {}) ⇒ Downloader
constructor
A new instance of Downloader.
- #set_quality(quality) ⇒ Object
Constructor Details
#initialize(href, options = {}) ⇒ Downloader
Returns a new instance of Downloader.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/youtube_tools/downloader.rb', line 9 def initialize(href, ={}) @href = href @video_folder = [:path].nil? ? FOLDER_PATH : [:path] @quality = [:quality].nil? ? set_quality(:low) : set_quality([:quality]) @error_quality = 0 @links = {} create_folder init_information end |
Instance Attribute Details
#full_path ⇒ Object
Returns the value of attribute full_path.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def full_path @full_path end |
#href ⇒ Object
Returns the value of attribute href.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def href @href end |
#link_dw ⇒ Object
Returns the value of attribute link_dw.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def link_dw @link_dw end |
#links ⇒ Object
Returns the value of attribute links.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def links @links end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def name @name end |
#quality ⇒ Object
Returns the value of attribute quality.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def quality @quality end |
Instance Method Details
#download_video ⇒ Object
method dowload video from selected folder
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/youtube_tools/downloader.rb', line 26 def download_video @percent = @total = 0 print "Downloading...0%" open(@full_path, 'wb') do |file| file.write(open(@link_dw, :content_length_proc => lambda {|t| if t && 0 < t @total = t end }, :progress_proc => lambda {|s| old_percent = @percent @percent = (s * 100)/@total print "..#{@percent}%" if @percent != old_percent }).read) end puts "Download complete!" end |