pulse-downloader 0.1.15 → 0.1.20

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: 4d2a34a08bede3b49a3d3629fc2d785d6337dc62702dbeb86742323b4baa11aa
4
- data.tar.gz: 29e276ed758b83ff22453f7774afd4e28aec0b6eac3436302287e239e73e0d73
3
+ metadata.gz: 8a2d2732c3a0307e7dffaf1ec3b60691e7b54ca3de4c4084325908f6fdf1b801
4
+ data.tar.gz: 06b3a802a55f186f8fccceec0e29d6b6e3dbade7be776699a6a327ccacf68060
5
5
  SHA512:
6
- metadata.gz: ddd1e433cc5be43243d83867107089945aa756328fa3e3fb4d239b682bfa88c29563e8401a3dccadd266d87169129ae994132a178179740c91520b790a7209c8
7
- data.tar.gz: cb3c310e893e3bb8c095d1e42b299f5bb3c9f95128b1657f65e066e7c60d154b22947f5d70d8e675f71438e7b0fe5c83cecef5a8806ba8b1a08e29f4a8f4bfb9
6
+ metadata.gz: 27c5f745685fbb5b2c207113b4fe28eb97b8638551afb931e3be1e4d9f073c5959ba0cc1ed59db44fbdfaae26218840ca8663da95fba37ef7c0cf18a37f2aefc
7
+ data.tar.gz: 3a06bbe0fafe7329eec9ba1d90e483da181f309915b06bfb67d49c3de9f1c96402047d775f672ed172979ca210d988e7063acd5c53860dc61bfcf508a6f64457
@@ -18,7 +18,8 @@ module Pulse
18
18
  :report_time,
19
19
  :start_time,
20
20
  :end_time,
21
- :progress_bar
21
+ :progress_bar,
22
+ :base_url
22
23
 
23
24
  # Does not continue downloads-
24
25
  # Will only save once the file has been downloaded in memory
@@ -51,6 +52,8 @@ module Pulse
51
52
  @save_and_dont_return = save_and_dont_return
52
53
  @report_time = report_time
53
54
  @progress_bar = progress_bar
55
+
56
+ @base_url = get_base_url
54
57
  end
55
58
 
56
59
  def call!
@@ -76,6 +79,16 @@ module Pulse
76
79
 
77
80
  private
78
81
 
82
+ def get_base_url
83
+ url_breakdown = url.split('/')
84
+
85
+ if url_breakdown.first.include?('https')
86
+ url_breakdown[2]
87
+ else
88
+ url_breakdown.first
89
+ end
90
+ end
91
+
79
92
  def get_micro_second_time
80
93
  (Time.now.to_f * 1000).to_i
81
94
  end
@@ -1,5 +1,5 @@
1
1
  module Pulse
2
2
  module Downloader
3
- VERSION = "0.1.15"
3
+ VERSION = "0.1.20"
4
4
  end
5
5
  end
@@ -19,7 +19,9 @@ module Pulse
19
19
 
20
20
  def extract_file_urls(response)
21
21
  return [] if response.body.nil? || response.body.empty?
22
- extract_download_links(response) + extract_embedded_images(response)
22
+ (
23
+ extract_download_links(response) + extract_embedded_images(response)
24
+ ).uniq
23
25
  end
24
26
 
25
27
  def extract_download_links(response)
@@ -29,21 +31,34 @@ module Pulse
29
31
  .map { |link| link['href'] }
30
32
  .compact
31
33
  .select { |link| link.include? file_type }
34
+ .map { |link| add_base_url(link) }
32
35
  end
33
36
 
34
37
  def extract_embedded_images(response)
38
+ return [] unless scrape_images
39
+
35
40
  parse_html(response.body)
36
41
  .css('img')
37
42
  .to_a
38
43
  .map { |e| e["src"] }
39
44
  .compact
40
45
  .select { |link| link.include? file_type }
41
- .select { |link| link.include? "https://" }
46
+ .map { |link| add_base_url(link) }
42
47
  end
43
48
 
44
49
  def parse_html(raw_html)
45
50
  Nokogiri::HTML(raw_html)
46
51
  end
52
+
53
+ def add_base_url(str)
54
+ unless str.include?('https://')
55
+ str
56
+ unless str.include?(base_url)
57
+ "https://#{base_url}#{str}"
58
+ else
59
+ str
60
+ end
61
+ end
47
62
  end
48
63
  end
49
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pulse-downloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - trex22