miteru 0.14.1 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/miteru/feeds.rb +4 -2
- data/lib/miteru/http_client.rb +13 -0
- data/lib/miteru/version.rb +1 -1
- data/lib/miteru/website.rb +25 -1
- 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: acafc5c390603cb4e035ba592a47291eb5b93f20c1a6f4c12dbf22f40b15f3b4
|
4
|
+
data.tar.gz: bc8e05d8356ed633c45c1c241abb9972c79a85edab8f5d555cfce740d72f938f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e191d8815c1eda041a9c64e2ef5c62a16da248ff5a19cbcd419ccdfa956963e0ed1177e83193c45df71971f8717ecd558a8a0b0d69a0d0ac8c7a2a4c9463ba87
|
7
|
+
data.tar.gz: b098a5efaa9eb18a618a5c3a42a0ce7b584ad37d39c7f154cc5afed9a11f5c0c2750215efa83b7d8a4e0109e32399dc37978da2a1bcf4aa2ff9c21f7454d974f
|
data/lib/miteru/feeds.rb
CHANGED
@@ -52,13 +52,15 @@ module Miteru
|
|
52
52
|
urls = (0...segments.length).map do |idx|
|
53
53
|
breakdowned_url = "#{base}#{segments[0..idx].join('/')}"
|
54
54
|
breakdown = [breakdowned_url]
|
55
|
-
if idx > 0 && idx < segments.length
|
55
|
+
if idx > 0 && idx < segments.length
|
56
|
+
next if segments[idx].nil? || invalid_extension?(segments[idx])
|
57
|
+
|
56
58
|
VALID_EXTENSIONS.each do |ext|
|
57
59
|
breakdown << "#{base}#{segments[0..idx - 1].join('/')}/#{segments[idx]}#{ext}"
|
58
60
|
end
|
59
61
|
end
|
60
62
|
breakdown
|
61
|
-
end.flatten
|
63
|
+
end.flatten.compact
|
62
64
|
|
63
65
|
urls.reject do |breakdowned_url|
|
64
66
|
# Reject a url which ends with specific extension names
|
data/lib/miteru/http_client.rb
CHANGED
@@ -23,6 +23,15 @@ module Miteru
|
|
23
23
|
destination
|
24
24
|
end
|
25
25
|
|
26
|
+
def head(url, options = {})
|
27
|
+
options = options.merge default_options
|
28
|
+
|
29
|
+
HTTP.follow
|
30
|
+
.timeout(3)
|
31
|
+
.headers(urlscan_url?(url) ? urlscan_headers : default_headers)
|
32
|
+
.head(url, options)
|
33
|
+
end
|
34
|
+
|
26
35
|
def get(url, options = {})
|
27
36
|
options = options.merge default_options
|
28
37
|
|
@@ -48,6 +57,10 @@ module Miteru
|
|
48
57
|
def post(url, options = {})
|
49
58
|
new.post url, options
|
50
59
|
end
|
60
|
+
|
61
|
+
def head(url, options = {})
|
62
|
+
new.head url, options
|
63
|
+
end
|
51
64
|
end
|
52
65
|
|
53
66
|
private
|
data/lib/miteru/version.rb
CHANGED
data/lib/miteru/website.rb
CHANGED
@@ -4,6 +4,8 @@ require "oga"
|
|
4
4
|
|
5
5
|
module Miteru
|
6
6
|
class Website
|
7
|
+
VALID_EXTENSIONS = [".zip", ".rar", ".7z", ".tar", ".gz"].freeze
|
8
|
+
|
7
9
|
attr_reader :url
|
8
10
|
def initialize(url)
|
9
11
|
@url = url
|
@@ -14,12 +16,25 @@ module Miteru
|
|
14
16
|
end
|
15
17
|
|
16
18
|
def kits
|
17
|
-
|
19
|
+
if ext?
|
20
|
+
return [] unless check(url)
|
21
|
+
|
22
|
+
link = url.split("/").last
|
23
|
+
base_url = url.split("/")[0..-2].join("/")
|
24
|
+
kit = Kit.new(base_url: base_url, link: link)
|
25
|
+
return kit.valid? ? [kit] : []
|
26
|
+
end
|
27
|
+
|
28
|
+
links.map do |link|
|
18
29
|
kit = Kit.new(base_url: url, link: link.to_s)
|
19
30
|
kit.valid? ? kit : nil
|
20
31
|
end.compact
|
21
32
|
end
|
22
33
|
|
34
|
+
def ext?
|
35
|
+
VALID_EXTENSIONS.any? { |ext| url.end_with?(ext) }
|
36
|
+
end
|
37
|
+
|
23
38
|
def ok?
|
24
39
|
response.code == 200
|
25
40
|
end
|
@@ -33,6 +48,8 @@ module Miteru
|
|
33
48
|
end
|
34
49
|
|
35
50
|
def has_kits?
|
51
|
+
return kits? if ext?
|
52
|
+
|
36
53
|
ok? && index? && kits?
|
37
54
|
rescue Addressable::URI::InvalidURIError, ArgumentError, Encoding::CompatibilityError, HTTP::Error, LL::ParserError, OpenSSL::SSL::SSLError => _e
|
38
55
|
false
|
@@ -52,6 +69,13 @@ module Miteru
|
|
52
69
|
@response ||= get
|
53
70
|
end
|
54
71
|
|
72
|
+
def check(url)
|
73
|
+
res = HTTPClient.head(url)
|
74
|
+
res.status.success?
|
75
|
+
rescue StandardError
|
76
|
+
false
|
77
|
+
end
|
78
|
+
|
55
79
|
def get
|
56
80
|
HTTPClient.get url
|
57
81
|
end
|