pulse-downloader 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1d8d3d5f2814c1744f58c8a09b118a478b2d1d3f1e92a66df86fd4352284fe4
4
- data.tar.gz: 3384a0e37e73e237edf8cd9a2fbdac640473408b7c8e523b8a43ea80529a0680
3
+ metadata.gz: 143241844753713ded3ebdb7fccf727a20ab2055ad9c40e9936b88f9ecd4a0a5
4
+ data.tar.gz: 471f4432385de2dc96223ed014e5d3c88adccfda7c98a591b1cd2c915dbe3256
5
5
  SHA512:
6
- metadata.gz: ee7a13ba93ca48c4306d6cede31c17753610c3496277830a8a5e4bb37b17e141ac231c37ce0bb5166d66db6f7fe6c969e20d8c85d758c3225b5d2b021035ce30
7
- data.tar.gz: 6e2999c3df8cbbe876743c10396d59cd8d6c0b1f9723090b910f6594fdd11d0290e30a903b6238e49c36b51fd6f40f04542748c85fcfb34835cdb5f42fb7ab5f
6
+ metadata.gz: f26e86e5e59e24be532fc542e2de26c33d69dd2e4bb264ef6fe1f28f46d68782d5d0838a80db769912fc202598dff4e40aad10a856e4659e01105c73997b7ed3
7
+ data.tar.gz: a29a979395ce6b6d7311e7150e22f1ed11a62cd317e19aa42a16241674e7abe33397e8d210882aeb4fa6f7835e3a32e321ccdadf13ecc20219c7a9065a38f9f5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pulse-downloader (0.1.2)
4
+ pulse-downloader (0.1.3)
5
5
  active_attr (~> 0.15)
6
6
  httparty (~> 0.18)
7
7
  nokogiri (~> 1.10.9)
data/README.md CHANGED
@@ -30,6 +30,8 @@ client = Pulse::Downloader::Client.new(
30
30
  save_path: '',
31
31
  read_from_save_path: false,
32
32
  verify_ssl: true,
33
+ drop_exitsing_files_in_path: false,
34
+ save_and_dont_return: true
33
35
  report_time: false
34
36
  )
35
37
  ```
@@ -3,6 +3,7 @@ require 'nokogiri'
3
3
 
4
4
  require "pulse/downloader/version"
5
5
  require 'pulse/downloader/web_page_parser'
6
+ require 'pulse/downloader/file_checker'
6
7
  require 'pulse/downloader/file_downloader'
7
8
  require 'pulse/downloader/client'
8
9
 
@@ -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:, file_type:, save_data: false, save_path: '', read_from_save_path: false, verify_ssl: true, report_time: false)
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'
@@ -1,5 +1,5 @@
1
1
  module Pulse
2
2
  module Downloader
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
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.2
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-15 00:00:00.000000000 Z
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