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*/
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#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.
-
#name ⇒ Object
Returns the value of attribute name.
-
#percent ⇒ Object
Returns the value of attribute percent.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
-
#download_video ⇒ Object
method dowload video from selected folder.
-
#initialize(href, path = nil) ⇒ Downloader
constructor
A new instance of Downloader.
Constructor Details
#initialize(href, path = nil) ⇒ Downloader
Returns a new instance of Downloader.
8 9 10 11 12 13 14 |
# File 'lib/youtube_tools/downloader.rb', line 8 def initialize(href, path=nil) @href = href @music_folder = path.nil? ? FOLDER_PATH : path create_folder init_information end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def content @content end |
#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 |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def name @name end |
#percent ⇒ Object
Returns the value of attribute percent.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def percent @percent end |
#total ⇒ Object
Returns the value of attribute total.
3 4 5 |
# File 'lib/youtube_tools/downloader.rb', line 3 def total @total end |
Instance Method Details
#download_video ⇒ Object
method dowload video from selected folder
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/youtube_tools/downloader.rb', line 29 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 end |