bookscan 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/bin/bookscan +0 -15
- data/bookscan.gemspec +9 -4
- data/lib/bookscan/agent.rb +29 -12
- data/lib/bookscan/book.rb +8 -2
- data/lib/bookscan/commands.rb +1 -1
- metadata +62 -29
data/Rakefile
CHANGED
@@ -25,6 +25,8 @@ Jeweler::Tasks.new do |gem|
|
|
25
25
|
gem.add_runtime_dependency 'keystorage', '> 0.1'
|
26
26
|
gem.add_runtime_dependency 'mechanize', '>= 1.0.0'
|
27
27
|
gem.add_runtime_dependency 'highline', '> 1.6'
|
28
|
+
gem.add_runtime_dependency 'progressbar', '>= 0.9.0'
|
29
|
+
gem.add_runtime_dependency 'httpclient', '>= 2.1.6.1'
|
28
30
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
29
31
|
end
|
30
32
|
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
data/bin/bookscan
CHANGED
@@ -5,19 +5,4 @@ require 'bookscan/cli'
|
|
5
5
|
Bookscan::CLI::run(ARGV)
|
6
6
|
exit
|
7
7
|
|
8
|
-
require 'optparse'
|
9
|
-
|
10
|
-
|
11
|
-
require 'rubygems'
|
12
|
-
require 'highline'
|
13
|
-
require 'mutter'
|
14
|
-
|
15
|
-
require 'moat';include Moat
|
16
|
-
|
17
|
-
load_passwords
|
18
|
-
|
19
|
-
Moat::SITES[@site] = {:username => username, :password => password }
|
20
|
-
show_credentials_for(@site) if @generated
|
21
|
-
save_passwords
|
22
|
-
|
23
8
|
|
data/bookscan.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bookscan}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Yoshihiro TAKAHARA"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-21}
|
13
13
|
s.default_executable = %q{bookscan}
|
14
14
|
s.description = %q{This is a scraper of Bookscan (http://www.bookscan.co.jp) Service.This is *NOT* a official software of Bookscan.}
|
15
15
|
s.email = %q{y.takahara@gmail.com}
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.homepage = %q{http://github.com/tumf/bookscan}
|
41
41
|
s.licenses = ["MIT"]
|
42
42
|
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = %q{1.
|
43
|
+
s.rubygems_version = %q{1.4.2}
|
44
44
|
s.summary = %q{BookScan Scraper}
|
45
45
|
s.test_files = [
|
46
46
|
"test/helper.rb",
|
@@ -48,7 +48,6 @@ Gem::Specification.new do |s|
|
|
48
48
|
]
|
49
49
|
|
50
50
|
if s.respond_to? :specification_version then
|
51
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
51
|
s.specification_version = 3
|
53
52
|
|
54
53
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
@@ -60,6 +59,8 @@ Gem::Specification.new do |s|
|
|
60
59
|
s.add_runtime_dependency(%q<keystorage>, ["> 0.1"])
|
61
60
|
s.add_runtime_dependency(%q<mechanize>, [">= 1.0.0"])
|
62
61
|
s.add_runtime_dependency(%q<highline>, ["> 1.6"])
|
62
|
+
s.add_runtime_dependency(%q<progressbar>, [">= 0.9.0"])
|
63
|
+
s.add_runtime_dependency(%q<httpclient>, [">= 2.1.6.1"])
|
63
64
|
else
|
64
65
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
65
66
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -69,6 +70,8 @@ Gem::Specification.new do |s|
|
|
69
70
|
s.add_dependency(%q<keystorage>, ["> 0.1"])
|
70
71
|
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
71
72
|
s.add_dependency(%q<highline>, ["> 1.6"])
|
73
|
+
s.add_dependency(%q<progressbar>, [">= 0.9.0"])
|
74
|
+
s.add_dependency(%q<httpclient>, [">= 2.1.6.1"])
|
72
75
|
end
|
73
76
|
else
|
74
77
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
@@ -79,6 +82,8 @@ Gem::Specification.new do |s|
|
|
79
82
|
s.add_dependency(%q<keystorage>, ["> 0.1"])
|
80
83
|
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
81
84
|
s.add_dependency(%q<highline>, ["> 1.6"])
|
85
|
+
s.add_dependency(%q<progressbar>, [">= 0.9.0"])
|
86
|
+
s.add_dependency(%q<httpclient>, [">= 2.1.6.1"])
|
82
87
|
end
|
83
88
|
end
|
84
89
|
|
data/lib/bookscan/agent.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require "rubygems"
|
3
3
|
require "mechanize"
|
4
|
+
require 'httpclient'
|
5
|
+
require 'progressbar'
|
4
6
|
|
5
7
|
require "bookscan"
|
6
8
|
require "bookscan/groups"
|
@@ -151,20 +153,35 @@ module Bookscan
|
|
151
153
|
end
|
152
154
|
|
153
155
|
def download(url,path)
|
154
|
-
|
155
|
-
|
156
|
-
|
156
|
+
url = URI.parse(url)
|
157
|
+
cli = HTTPClient.new
|
158
|
+
@cookie_jar.cookies(url).each do |cookie|
|
159
|
+
cli.cookie_manager.parse(cookie.to_s,url)
|
160
|
+
end
|
157
161
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
162
|
+
length = 0;total = 0
|
163
|
+
res = cli.head(url)
|
164
|
+
if res.status == 302
|
165
|
+
url = URI.parse(res.header["Location"].to_s)
|
166
|
+
end
|
167
|
+
total = cli.head(url).header["Content-Length"].to_s.to_i
|
168
|
+
t = Thread.new {
|
169
|
+
conn = cli.get_async(url)
|
170
|
+
io = conn.pop.content
|
171
|
+
::File::open(path, "wb") { |f|
|
172
|
+
while str = io.read(40)
|
173
|
+
f.write str
|
174
|
+
length += str.length
|
175
|
+
end
|
176
|
+
}
|
177
|
+
}
|
178
|
+
pbar = ProgressBar.new("Loading",total)
|
179
|
+
while total > length
|
180
|
+
sleep 1
|
181
|
+
pbar.set(length)
|
167
182
|
end
|
183
|
+
pbar.finish
|
184
|
+
t.join
|
168
185
|
end
|
169
186
|
|
170
187
|
end
|
data/lib/bookscan/book.rb
CHANGED
@@ -11,11 +11,11 @@ module Bookscan
|
|
11
11
|
def to_s
|
12
12
|
table = Mutter::Table.new(:delimiter => '|') do
|
13
13
|
column :style => :green
|
14
|
-
column :width =>
|
14
|
+
column :width => 100
|
15
15
|
end
|
16
16
|
|
17
17
|
each do |b|
|
18
|
-
table << [b.book_id,b.
|
18
|
+
table << [b.book_id,b.title_short]
|
19
19
|
end
|
20
20
|
table.to_s if length > 0
|
21
21
|
end
|
@@ -60,6 +60,12 @@ module Bookscan
|
|
60
60
|
@title
|
61
61
|
end
|
62
62
|
|
63
|
+
def title_short
|
64
|
+
@title.sub(/\.pdf$/,"").
|
65
|
+
sub(/_s$/,"").
|
66
|
+
sub(/_[0-9a-zA-Z]+$/,"")
|
67
|
+
end
|
68
|
+
|
63
69
|
def filename
|
64
70
|
return @title if isbn
|
65
71
|
if /(.*)\.pdf$/ =~ @title
|
data/lib/bookscan/commands.rb
CHANGED
@@ -195,7 +195,7 @@ module Bookscan
|
|
195
195
|
next unless book.tune_type == type
|
196
196
|
if Dir.glob(directory + "/**/*" + book.book_id + "*.pdf").length == 0
|
197
197
|
path = directory + "/" +book.filename
|
198
|
-
puts "
|
198
|
+
puts "=> " + path
|
199
199
|
unless dry_run
|
200
200
|
start
|
201
201
|
@agent.download(book.url,path)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookscan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yoshihiro TAKAHARA
|
@@ -15,11 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-21 00:00:00 +09:00
|
19
19
|
default_executable: bookscan
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
type: :development
|
23
|
+
name: shoulda
|
23
24
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
@@ -29,11 +30,11 @@ dependencies:
|
|
29
30
|
segments:
|
30
31
|
- 0
|
31
32
|
version: "0"
|
33
|
+
prerelease: false
|
32
34
|
requirement: *id001
|
33
|
-
name: shoulda
|
34
|
-
type: :development
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
|
36
|
+
type: :development
|
37
|
+
name: bundler
|
37
38
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
39
|
none: false
|
39
40
|
requirements:
|
@@ -45,11 +46,11 @@ dependencies:
|
|
45
46
|
- 0
|
46
47
|
- 0
|
47
48
|
version: 1.0.0
|
49
|
+
prerelease: false
|
48
50
|
requirement: *id002
|
49
|
-
name: bundler
|
50
|
-
type: :development
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
|
52
|
+
type: :development
|
53
|
+
name: jeweler
|
53
54
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
55
|
none: false
|
55
56
|
requirements:
|
@@ -61,11 +62,11 @@ dependencies:
|
|
61
62
|
- 5
|
62
63
|
- 2
|
63
64
|
version: 1.5.2
|
65
|
+
prerelease: false
|
64
66
|
requirement: *id003
|
65
|
-
name: jeweler
|
66
|
-
type: :development
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
|
68
|
+
type: :development
|
69
|
+
name: rcov
|
69
70
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
71
|
none: false
|
71
72
|
requirements:
|
@@ -75,11 +76,11 @@ dependencies:
|
|
75
76
|
segments:
|
76
77
|
- 0
|
77
78
|
version: "0"
|
79
|
+
prerelease: false
|
78
80
|
requirement: *id004
|
79
|
-
name: rcov
|
80
|
-
type: :development
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
|
82
|
+
type: :runtime
|
83
|
+
name: mutter
|
83
84
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
85
|
none: false
|
85
86
|
requirements:
|
@@ -89,11 +90,11 @@ dependencies:
|
|
89
90
|
segments:
|
90
91
|
- 0
|
91
92
|
version: "0"
|
93
|
+
prerelease: false
|
92
94
|
requirement: *id005
|
93
|
-
name: mutter
|
94
|
-
type: :runtime
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
|
-
|
96
|
+
type: :runtime
|
97
|
+
name: keystorage
|
97
98
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
98
99
|
none: false
|
99
100
|
requirements:
|
@@ -104,11 +105,11 @@ dependencies:
|
|
104
105
|
- 0
|
105
106
|
- 1
|
106
107
|
version: "0.1"
|
108
|
+
prerelease: false
|
107
109
|
requirement: *id006
|
108
|
-
name: keystorage
|
109
|
-
type: :runtime
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
|
111
|
+
type: :runtime
|
112
|
+
name: mechanize
|
112
113
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
113
114
|
none: false
|
114
115
|
requirements:
|
@@ -120,11 +121,11 @@ dependencies:
|
|
120
121
|
- 0
|
121
122
|
- 0
|
122
123
|
version: 1.0.0
|
124
|
+
prerelease: false
|
123
125
|
requirement: *id007
|
124
|
-
name: mechanize
|
125
|
-
type: :runtime
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
|
127
|
+
type: :runtime
|
128
|
+
name: highline
|
128
129
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
129
130
|
none: false
|
130
131
|
requirements:
|
@@ -135,9 +136,41 @@ dependencies:
|
|
135
136
|
- 1
|
136
137
|
- 6
|
137
138
|
version: "1.6"
|
139
|
+
prerelease: false
|
138
140
|
requirement: *id008
|
139
|
-
|
141
|
+
- !ruby/object:Gem::Dependency
|
140
142
|
type: :runtime
|
143
|
+
name: progressbar
|
144
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 59
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
- 9
|
153
|
+
- 0
|
154
|
+
version: 0.9.0
|
155
|
+
prerelease: false
|
156
|
+
requirement: *id009
|
157
|
+
- !ruby/object:Gem::Dependency
|
158
|
+
type: :runtime
|
159
|
+
name: httpclient
|
160
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
hash: 125
|
166
|
+
segments:
|
167
|
+
- 2
|
168
|
+
- 1
|
169
|
+
- 6
|
170
|
+
- 1
|
171
|
+
version: 2.1.6.1
|
172
|
+
prerelease: false
|
173
|
+
requirement: *id010
|
141
174
|
description: This is a scraper of Bookscan (http://www.bookscan.co.jp) Service.This is *NOT* a official software of Bookscan.
|
142
175
|
email: y.takahara@gmail.com
|
143
176
|
executables:
|
@@ -195,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
228
|
requirements: []
|
196
229
|
|
197
230
|
rubyforge_project:
|
198
|
-
rubygems_version: 1.
|
231
|
+
rubygems_version: 1.4.2
|
199
232
|
signing_key:
|
200
233
|
specification_version: 3
|
201
234
|
summary: BookScan Scraper
|