Class: YoutubeTools::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/youtube_tools/downloader.rb

Constant Summary collapse

/"fmt_stream_map": ("[\w |:\/\\.?=&\,%-]+")/
NAME_PATTERN =
/-\s+(.*)\s*/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/youtube_tools/downloader.rb', line 3

def content
  @content
end

#full_pathObject

Returns the value of attribute full_path.



3
4
5
# File 'lib/youtube_tools/downloader.rb', line 3

def full_path
  @full_path
end

#hrefObject

Returns the value of attribute href.



3
4
5
# File 'lib/youtube_tools/downloader.rb', line 3

def href
  @href
end

Returns the value of attribute link_dw.



3
4
5
# File 'lib/youtube_tools/downloader.rb', line 3

def link_dw
  @link_dw
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/youtube_tools/downloader.rb', line 3

def name
  @name
end

#percentObject

Returns the value of attribute percent.



3
4
5
# File 'lib/youtube_tools/downloader.rb', line 3

def percent
  @percent
end

#totalObject

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_videoObject

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