pulse-downloader 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/pulse/downloader.rb +1 -0
- data/lib/pulse/downloader/client.rb +17 -1
- data/lib/pulse/downloader/file_checker.rb +27 -0
- data/lib/pulse/downloader/file_downloader.rb +3 -8
- data/lib/pulse/downloader/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 143241844753713ded3ebdb7fccf727a20ab2055ad9c40e9936b88f9ecd4a0a5
|
4
|
+
data.tar.gz: 471f4432385de2dc96223ed014e5d3c88adccfda7c98a591b1cd2c915dbe3256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26e86e5e59e24be532fc542e2de26c33d69dd2e4bb264ef6fe1f28f46d68782d5d0838a80db769912fc202598dff4e40aad10a856e4659e01105c73997b7ed3
|
7
|
+
data.tar.gz: a29a979395ce6b6d7311e7150e22f1ed11a62cd317e19aa42a16241674e7abe33397e8d210882aeb4fa6f7835e3a32e321ccdadf13ecc20219c7a9065a38f9f5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/pulse/downloader.rb
CHANGED
@@ -2,6 +2,7 @@ module Pulse
|
|
2
2
|
module Downloader
|
3
3
|
class Client
|
4
4
|
include ::Pulse::Downloader::WebPageParser
|
5
|
+
include ::Pulse::Downloader::FileChecker
|
5
6
|
include ::Pulse::Downloader::FileDownloader
|
6
7
|
|
7
8
|
attr_reader :url,
|
@@ -10,20 +11,35 @@ module Pulse
|
|
10
11
|
:save_path,
|
11
12
|
:read_from_save_path,
|
12
13
|
:verify_ssl,
|
14
|
+
:drop_exitsing_files_in_path,
|
13
15
|
:report_time,
|
14
16
|
:start_time,
|
15
17
|
:end_time
|
16
18
|
|
19
|
+
# Does not continue downloads-
|
20
|
+
# Will only save once the file has been downloaded in memory
|
21
|
+
|
22
|
+
# TODO: Add in progress bar
|
17
23
|
# TODO: Validation
|
18
24
|
# TODO: Retry
|
19
25
|
# TODO: DNS
|
20
|
-
def initialize(url:,
|
26
|
+
def initialize(url:,
|
27
|
+
file_type:,
|
28
|
+
save_data: false,
|
29
|
+
save_path: '',
|
30
|
+
read_from_save_path: false,
|
31
|
+
verify_ssl: true,
|
32
|
+
drop_exitsing_files_in_path: false,
|
33
|
+
save_and_dont_return: true,
|
34
|
+
report_time: false)
|
35
|
+
|
21
36
|
@url = url
|
22
37
|
@file_type = file_type
|
23
38
|
@save_data = save_data
|
24
39
|
@save_path = save_path
|
25
40
|
@read_from_save_path = read_from_save_path
|
26
41
|
@verify_ssl = verify_ssl
|
42
|
+
@drop_exitsing_files_in_path = drop_exitsing_files_in_path
|
27
43
|
@report_time = report_time
|
28
44
|
end
|
29
45
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Pulse
|
2
|
+
module Downloader
|
3
|
+
module FileChecker
|
4
|
+
def file_path_in_file_list?(file_path)
|
5
|
+
return false unless drop_exitsing_files_in_path && save_data
|
6
|
+
|
7
|
+
list_files_in(save_path).include?(compute_save_path(file_path))
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def compute_save_path(url)
|
13
|
+
"#{save_path}/#{compute_filename(url)}".gsub('//', '/')
|
14
|
+
end
|
15
|
+
|
16
|
+
def compute_filename(file_path)
|
17
|
+
file_path.scan(/[\/]\S+/).last
|
18
|
+
end
|
19
|
+
|
20
|
+
def list_files_in(path)
|
21
|
+
`ls #{path}`.split("\n").map do |filename|
|
22
|
+
"#{path}/#{filename}".gsub('//', '/')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -4,6 +4,7 @@ module Pulse
|
|
4
4
|
# save_path and verify_ssl are defined in client.rb
|
5
5
|
def download(file_path)
|
6
6
|
raise "save_path is undefined" if save_data && save_path == ''
|
7
|
+
return if file_path_in_file_list?(file_path) # skip downloading the file
|
7
8
|
|
8
9
|
@start_time = get_micro_second_time
|
9
10
|
|
@@ -19,6 +20,8 @@ module Pulse
|
|
19
20
|
File.open(compute_save_path(file_path), 'wb') do |file|
|
20
21
|
file.write(file_data.body)
|
21
22
|
end
|
23
|
+
|
24
|
+
return true if save_and_dont_return
|
22
25
|
end
|
23
26
|
|
24
27
|
file_data
|
@@ -36,14 +39,6 @@ module Pulse
|
|
36
39
|
|
37
40
|
private
|
38
41
|
|
39
|
-
def compute_save_path(url)
|
40
|
-
"#{save_path}/#{compute_filename(url)}"
|
41
|
-
end
|
42
|
-
|
43
|
-
def compute_filename(file_path)
|
44
|
-
file_path.scan(/[\/]\S+/).last
|
45
|
-
end
|
46
|
-
|
47
42
|
def compute_file_link(file_path)
|
48
43
|
if section?(file_path)
|
49
44
|
raise 'invalid download path'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pulse-downloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- trex22
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- bin/setup
|
198
198
|
- lib/pulse/downloader.rb
|
199
199
|
- lib/pulse/downloader/client.rb
|
200
|
+
- lib/pulse/downloader/file_checker.rb
|
200
201
|
- lib/pulse/downloader/file_downloader.rb
|
201
202
|
- lib/pulse/downloader/version.rb
|
202
203
|
- lib/pulse/downloader/web_page_parser.rb
|