Top Level Namespace

Defined Under Namespace

Classes: Integer, ProgressRunner, SaveTube, YoutubeShort

Instance Method Summary collapse

Instance Method Details

#download_stream(url, name, path) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/downloader_file.rb', line 55

def download_stream(url, name, path)
	if File.directory?(path)
		name = name.gsub(/(?:\?|\/|\|)/,'_')
		length = HTTParty.head(url)["content-length"].to_i
		progress_runner = ProgressRunner.new(length)
		File.open("#{path}#{name}",'wb') do | file |
			HTTParty.get(url, stream_body: true) do | segment |
				progress_runner.download(segment.length) do
					file.write(segment)
				end
			end
		end
	else
		raise Errno, "Path #{path} not found!"
	end
end

#getPage(url = nil, headers = nil, params = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/function.rb', line 12

def getPage(url=nil, headers=nil, params=nil)
	default_headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36'}
	begin
		return HTTParty.get(url, 
			:headers => !headers.nil? ? headers : default_headers,
			:query => params).body
	rescue SocketError
		abort("no internet connection!")
	end
end

#loadJson(raw) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/function.rb', line 23

def loadJson(raw)
	if (raw.instance_of?(String))
		begin
			return JSON.parse(raw)
		rescue JSON::ParserError => e
			abort(" (!) Json not valid: #{e}")
		end
	elsif (raw.instance_of?(Hash))
		return raw
	else
		abort(" (!) can't load json if type is: #{raw.class}")
	end
end

#prompt(*args) ⇒ Object



7
8
9
10
# File 'lib/function.rb', line 7

def prompt(*args)
	print(*args)
   	gets
end