image-dumper 0.7.6 → 0.7.7

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
  SHA1:
3
- metadata.gz: b548a213f8c821767f5fd654bec37d4e107628d1
4
- data.tar.gz: e7bb501fbb0c5730c4dec92a776b00dd8c11d586
3
+ metadata.gz: 142125bfd86802635caf3776cfd19bc7feae04fb
4
+ data.tar.gz: 280d4de2b98d1794ac97cfaf6e38537c06e86d2d
5
5
  SHA512:
6
- metadata.gz: f1ab03832e03a3aaef4354746b898380380ac929185b35c70586e8f8a8d3d0fff149d3b4f2a2b83b4324010e02bb0777d6bb9cfc8866b0edf5c636d955d91186
7
- data.tar.gz: 2345abf3659d0cd1c33daf1a54fed23b717586b4131f35069b055e79b47aa00b942510cf5ad952231143a4b26984aa7668ea032719ef874881e71dbf2d6aed54
6
+ metadata.gz: 6f8e8b131e24836e9e34a6699b401f4ce38a0ee3a664c64cfd943455292af7bf170b6f0fbba23c32a2a07da61ce1e946fb28ba41fe8f0c4b7ae48e2aea691ff8
7
+ data.tar.gz: 030273ac86759b0b3affff3cd0d2eed119e0a24c6ed6809610feb65995b558a5ed2763cde53bb0abdf9e2f187d8708cbe65e49e5d0b290946417fc6544aa1852
data/bin/dumper CHANGED
File without changes
data/lib/dumper.rb CHANGED
@@ -37,8 +37,8 @@ require 'dumper/profiles'
37
37
  require 'dumper/dumper'
38
38
  require 'dumper/version'
39
39
 
40
- Dir.glob(File.expand_path("../dumper/profiles/*.rb", __FILE__)).each { |f|
40
+ Dir.glob(File.expand_path("../dumper/profiles/*.rb", __FILE__)).each do |f|
41
41
  require "dumper/profiles/#{File.basename(f).split(?.)[0]}"
42
- }
42
+ end
43
43
 
44
44
  Dumper.is_observed_by Dumper::Logger.new, on_fire: false
data/lib/dumper/dumper.rb CHANGED
@@ -52,7 +52,7 @@ module Dumper
52
52
  def shut_up!
53
53
  @verbose == false
54
54
  end
55
- alias_method :mute!, :shut_up!
55
+ alias_method :mute!, :shut_up!
56
56
 
57
57
  def verbose!
58
58
  @verbose == true
@@ -64,15 +64,15 @@ module Dumper
64
64
  end
65
65
 
66
66
  def list
67
- Dir.glob(File.expand_path('../profiles/*.rb', __FILE__)).sort { |a, b| b <=> a }.map { |f|
67
+ Dir.glob(File.expand_path('../profiles/*.rb', __FILE__)).sort { |a, b| b <=> a }.map do |f|
68
68
  f = File.basename(f).split(?.)[0]
69
- }
69
+ end
70
70
  end
71
-
71
+
72
72
  def get(path, url, options = {})
73
73
  url = url.to_s
74
74
  errors = 0
75
-
75
+
76
76
  begin
77
77
  if url.start_with? 'data:image/'
78
78
  filename = File.join path, options[:filename] || rand(1000).to_s + '.' + url.split('data:image/')[1].split(?;)[0]
@@ -81,12 +81,10 @@ module Dumper
81
81
  url.gsub /data:image\/png;base64,/, ''
82
82
 
83
83
  if File.exists? filename
84
- notify_observers error: "File #{filename} already exists."
84
+ notify_observers error: "File #{filename} already exists."
85
85
  else
86
86
  notify_observers status: "Downloading base64 image as #{filename}..."
87
- File.open(filename, 'wb') { |f|
88
- f.write Base64.decode64(url)
89
- }
87
+ File.open(filename, 'wb') { |f| f.write Base64.decode64(url) }
90
88
  end
91
89
  else
92
90
  filename = File.join path, options[:filename] || File.basename(url)
@@ -98,13 +96,20 @@ module Dumper
98
96
  filename = File.join(path, rand(1000).to_s + '.jpg') unless filename[-4] == ?. || filename[-5] == ?.
99
97
  notify_observers status: "Downloading #{url} as #{filename}..."
100
98
 
101
- File.open(filename, 'wb') { |f|
102
- f.write open(url,
103
- ssl_verify: OpenSSL::SSL::VERIFY_NONE,
104
- 'User-Agent' => options[:user_agent] || USER_AGENT,
105
- 'Referer' => options[:referer ] || url
106
- ).read
99
+ url.prepend('http:') if url.start_with?('//')
100
+ uri = URI(url)
101
+ http_options = {
102
+ 'User-Agent' => options[:user_agent] || USER_AGENT,
103
+ 'Referer' => options[:referer ] || url
107
104
  }
105
+
106
+ http = Net::HTTP.start(uri.host, uri.port)
107
+ http.use_ssl = uri.scheme == 'https'
108
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
109
+
110
+ File.open(filename, 'wb') do |f|
111
+ f.write http.get(uri.path, http_options).body
112
+ end
108
113
  end
109
114
  end
110
115
  rescue Exception => e
@@ -117,22 +122,23 @@ module Dumper
117
122
  return false
118
123
  end
119
124
  end
120
-
125
+
121
126
  true
122
127
  end
123
128
 
124
129
  def get_generic(url, path, xpath)
125
130
  uri = nil
126
- Nokogiri::HTML(open(url)).xpath(xpath).each { |p|
131
+ Nokogiri::HTML(open(url)).xpath(xpath).each do |p|
127
132
  if p.to_s.start_with? ?/
128
133
  uri = URI(url) if uri.nil?
129
134
  p = "#{uri.scheme}://#{uri.host}#{p}"
130
135
  end
136
+
131
137
  get path, p
132
- }
138
+ end
133
139
  end
134
140
  end
135
-
141
+
136
142
  def method_missing(method, *args, &block)
137
143
  "'#{method.split('get_')[1]}' profile not found."
138
144
  end
data/lib/dumper/logger.rb CHANGED
@@ -35,13 +35,13 @@ module Dumper
35
35
  end
36
36
 
37
37
  def log_on_screen(data)
38
- data.each { |status, message|
38
+ data.each do |status, message|
39
39
  if status == :critical_error_dump
40
- p message
40
+ p message
41
41
  else
42
42
  puts message
43
43
  end
44
- }
44
+ end
45
45
  end
46
46
  end
47
47
 
@@ -58,4 +58,4 @@ module Dumper
58
58
  end
59
59
 
60
60
  end
61
- end
61
+ end
@@ -47,4 +47,4 @@ module Dumper
47
47
  end
48
48
 
49
49
  end
50
- end
50
+ end
@@ -46,4 +46,4 @@ module Dumper
46
46
  end
47
47
 
48
48
  end
49
- end
49
+ end
@@ -23,7 +23,7 @@ module Dumper
23
23
  class Booru < Profile
24
24
  def dump(url, path, from, to)
25
25
  page = 0
26
-
26
+
27
27
  from.upto(to) { |i|
28
28
  notify_observers status: "--- Page #{i} ---"
29
29
 
@@ -32,7 +32,7 @@ module Dumper
32
32
  Dumper.get path, u.child.child['src'].gsub(/thumbs/, 'img').gsub(/thumbnails\//, 'images/').gsub(/thumbnail_/, '')
33
33
  }
34
34
  }
35
-
35
+
36
36
  page += 40
37
37
  }
38
38
  end
@@ -52,4 +52,4 @@ module Dumper
52
52
  end
53
53
 
54
54
  end
55
- end
55
+ end
@@ -24,12 +24,12 @@ module Dumper
24
24
  def dump(url, path, from, to)
25
25
  url += '/read' unless url.end_with? '/read'
26
26
  errors = 0
27
-
27
+
28
28
  cdn = open(url).read.split('window.params.thumbs')[1].split('\/thumbs\/')[0].gsub(/\\\//m, ?/)[5..-1] + '/images/'
29
29
 
30
30
  from.upto(to) { |i|
31
31
  return if errors == 3
32
-
32
+
33
33
  file = "%03d.jpg" % i
34
34
  filename = "#{cdn}#{file}"
35
35
 
@@ -37,7 +37,7 @@ module Dumper
37
37
  unless Dumper.get path, URI.parse(URI.encode(filename, '[]')), { referer: url }
38
38
  sleep 3
39
39
  errors += 1
40
-
40
+
41
41
  file = File.join(path, file).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
42
42
  File.delete(file) if File.exists? file
43
43
  end
@@ -60,4 +60,4 @@ module Dumper
60
60
  end
61
61
 
62
62
  end
63
- end
63
+ end
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Dumper
21
21
  def self.version
22
- '0.7.6'
22
+ '0.7.7'
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image-dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri