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 +4 -4
- data/lib/pulse/downloader/client.rb +14 -1
- data/lib/pulse/downloader/version.rb +1 -1
- data/lib/pulse/downloader/web_page_parser.rb +17 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a2d2732c3a0307e7dffaf1ec3b60691e7b54ca3de4c4084325908f6fdf1b801
|
4
|
+
data.tar.gz: 06b3a802a55f186f8fccceec0e29d6b6e3dbade7be776699a6a327ccacf68060
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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
|
-
|
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
|
-
.
|
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
|