cherrypicker 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -9,12 +9,13 @@ require 'progressbar'
|
|
9
9
|
require 'open-uri'
|
10
10
|
|
11
11
|
class Download
|
12
|
-
attr_accessor :link, :size, :location, :progress
|
12
|
+
attr_accessor :link, :size, :location, :progress, :filename
|
13
13
|
|
14
|
-
def initialize(link, location = nil, size = nil)
|
14
|
+
def initialize(link, location = nil, size = nil, filename = nil)
|
15
15
|
@link = link
|
16
16
|
@size = size
|
17
17
|
@location = location
|
18
|
+
@filename = filename
|
18
19
|
@progress = 0
|
19
20
|
|
20
21
|
download_file
|
@@ -28,8 +29,8 @@ class Download
|
|
28
29
|
request.initialize_http_header({"User-Agent" => random_agent})
|
29
30
|
@size = http.request_head(URI.escape(uri.path))['content-length'].to_i if @size.nil?
|
30
31
|
http.request(request) do |response|
|
31
|
-
bar = ProgressBar.new(File.basename(uri.path), @size.to_i)
|
32
|
-
File.open(@location + File.basename(uri.path), "wb") do |file|
|
32
|
+
bar = ProgressBar.new((@filename ||= File.basename(uri.path)), @size.to_i)
|
33
|
+
File.open(@location + (@filename ||= File.basename(uri.path)), "wb") do |file|
|
33
34
|
response.read_body do |segment|
|
34
35
|
@progress += segment.length
|
35
36
|
bar.set(@progress)
|
data/lib/cherrypicker/hotfile.rb
CHANGED
data/lib/cherrypicker/version.rb
CHANGED