epub_book 0.1.19 → 0.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/epub_book.gemspec +6 -7
- data/lib/epub_book/book.rb +17 -6
- data/lib/epub_book/version.rb +1 -1
- data/lib/epub_book.rb +3 -3
- metadata +46 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe0acde1dee44a1b78b5919f5918b9251046dc77d99845b8e7f30b7727bb9bdb
|
4
|
+
data.tar.gz: 10ba271cdac6b7afe9b79dd874c3a373e0e97c115f6e1b9c642d73aa517ee093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8afdb3e0e9ed70782894c00207afa174b97d4792ad67235f15f0d0a193e1278cdca97fd7081dcefb4db131a0af16c3ce4f7f092bec3fb31e56e0abffecde430
|
7
|
+
data.tar.gz: 80a46d793b3d69e4f19154c07202e77197bf2f08cdd1cdf23c207cd6122d6a6b46c4df850e0676d2b099e32e8d48542da1f5cd4e4d4f475022f540fc81a19940
|
data/Gemfile
CHANGED
data/epub_book.gemspec
CHANGED
@@ -28,17 +28,16 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
spec.add_dependency 'http','~> 2.1'
|
31
|
-
|
32
|
-
spec.add_dependency "nokogiri", ">= 1.11.4"
|
31
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.11', '>= 1.11.4'
|
33
32
|
spec.add_dependency 'eeepub', '~> 0.8.1'
|
34
33
|
spec.add_dependency 'zip-zip', '~> 0.3'
|
35
34
|
spec.add_dependency 'mail', '~>2.7.0'
|
36
35
|
|
37
36
|
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency "rake",
|
37
|
+
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.27'
|
38
|
+
spec.add_development_dependency "rake", '~> 12.3','>= 12.3.3'
|
40
39
|
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
-
spec.add_development_dependency "pry",
|
42
|
-
spec.add_development_dependency "pry-byebug",
|
43
|
-
spec.add_development_dependency "pry-doc",
|
40
|
+
spec.add_development_dependency "pry", '~> 0.14', '>= 0.14.1'
|
41
|
+
spec.add_development_dependency "pry-byebug", '~> 3.8', '>= 3.8.0'
|
42
|
+
spec.add_development_dependency "pry-doc", '~> 1.2', '>= 1.2.0'
|
44
43
|
end
|
data/lib/epub_book/book.rb
CHANGED
@@ -22,7 +22,7 @@ module EpubBook
|
|
22
22
|
class Book
|
23
23
|
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36"
|
24
24
|
Referer = "http://www.baidu.com/"
|
25
|
-
attr_accessor :title_css, :index_item_css, :body_css, :limit, :item_attr, :page_css, :page_attr,:cover,:cover_css, :description_css,:path,:user_agent,:referer,:creator,:mail_to, :folder_name,:des_url,:ext_name
|
25
|
+
attr_accessor :title_css, :index_item_css, :body_css, :limit, :item_attr, :page_css, :page_attr,:cover,:cover_css, :description_css,:path,:user_agent,:referer,:creator,:mail_to, :folder_name,:des_url,:ext_name,:ignore_txt
|
26
26
|
|
27
27
|
|
28
28
|
Reg = /<script.*?>.*?<\/script>/m
|
@@ -76,7 +76,7 @@ module EpubBook
|
|
76
76
|
if ext_name == 'epub'
|
77
77
|
if !@cover_css && @cover
|
78
78
|
generate_cover = <<-eof
|
79
|
-
|
79
|
+
convert #{File.expand_path("../../../#{@cover}",__FILE__)} -font tsxc.ttf -gravity center -fill red -pointsize 16 -draw "text 0,0 '#{book[:title]}'" #{File.join(book_path,@cover)}
|
80
80
|
eof
|
81
81
|
system(generate_cover)
|
82
82
|
end
|
@@ -126,7 +126,7 @@ module EpubBook
|
|
126
126
|
def fetch_index(url=nil)
|
127
127
|
book[:files] = []
|
128
128
|
url ||= @index_url
|
129
|
-
doc = Nokogiri::HTML(judge_encoding(HTTP.headers("User-Agent" => @user_agent ,'Referer'=> @referer).get(
|
129
|
+
doc = Nokogiri::HTML(judge_encoding(HTTP.headers("User-Agent" => @user_agent ,'Referer'=> @referer).get(url).to_s))
|
130
130
|
#generate index.yml
|
131
131
|
EpubBook.logger.info "------Fetch index--#{url}---------------"
|
132
132
|
|
@@ -134,14 +134,14 @@ module EpubBook
|
|
134
134
|
doc1 = if @des_url.nil?
|
135
135
|
doc
|
136
136
|
else
|
137
|
-
Nokogiri::HTML(judge_encoding(HTTP.headers("User-Agent" => @user_agent ,'Referer'=> @referer).get(
|
137
|
+
Nokogiri::HTML(judge_encoding(HTTP.headers("User-Agent" => @user_agent ,'Referer'=> @referer).get(generate_abs_url(doc.css(@des_url).attr("href").to_s)).to_s))
|
138
138
|
end
|
139
139
|
get_des(doc1)
|
140
140
|
end
|
141
141
|
|
142
142
|
#binding.pry
|
143
143
|
doc.css(@index_item_css).each do |item|
|
144
|
-
_href =
|
144
|
+
_href = item.attr(@item_attr).to_s
|
145
145
|
next if _href.start_with?('javascript') || _href.start_with?('#')
|
146
146
|
|
147
147
|
_href = generate_abs_url(_href)
|
@@ -171,7 +171,11 @@ module EpubBook
|
|
171
171
|
#open a txt file to write
|
172
172
|
if ext_name == 'txt'
|
173
173
|
txt_file = File.open(book[:file_abs_name], 'a')
|
174
|
+
txt_file.write("简介\n\n")
|
175
|
+
txt_file.write(' ')
|
176
|
+
txt_file.write(book[:description] || " ")
|
174
177
|
end
|
178
|
+
|
175
179
|
book[:files].each_with_index do |item,index|
|
176
180
|
break if limit && index >= limit
|
177
181
|
|
@@ -203,8 +207,15 @@ module EpubBook
|
|
203
207
|
next
|
204
208
|
end
|
205
209
|
end
|
210
|
+
if ext_name == 'txt'
|
211
|
+
txt_file.close
|
212
|
+
EpubBook.logger.info "=============去除包含指定忽略字符的行======="
|
213
|
+
EpubBook.logger.info ignore_txt
|
214
|
+
if ignore_txt
|
215
|
+
system("sed -i 's/#{ignore_txt}//' #{book[:file_abs_name]}")
|
216
|
+
end
|
206
217
|
|
207
|
-
|
218
|
+
end
|
208
219
|
|
209
220
|
end
|
210
221
|
|
data/lib/epub_book/version.rb
CHANGED
data/lib/epub_book.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epub_book
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- qmliu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -28,6 +28,9 @@ dependencies:
|
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
31
34
|
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
36
|
version: 1.11.4
|
@@ -35,6 +38,9 @@ dependencies:
|
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.11'
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: 1.11.4
|
@@ -84,30 +90,42 @@ dependencies:
|
|
84
90
|
name: bundler
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '2.2'
|
87
96
|
- - ">="
|
88
97
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.2.
|
98
|
+
version: 2.2.27
|
90
99
|
type: :development
|
91
100
|
prerelease: false
|
92
101
|
version_requirements: !ruby/object:Gem::Requirement
|
93
102
|
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '2.2'
|
94
106
|
- - ">="
|
95
107
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.2.
|
108
|
+
version: 2.2.27
|
97
109
|
- !ruby/object:Gem::Dependency
|
98
110
|
name: rake
|
99
111
|
requirement: !ruby/object:Gem::Requirement
|
100
112
|
requirements:
|
101
113
|
- - "~>"
|
102
114
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
115
|
+
version: '12.3'
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 12.3.3
|
104
119
|
type: :development
|
105
120
|
prerelease: false
|
106
121
|
version_requirements: !ruby/object:Gem::Requirement
|
107
122
|
requirements:
|
108
123
|
- - "~>"
|
109
124
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
125
|
+
version: '12.3'
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 12.3.3
|
111
129
|
- !ruby/object:Gem::Dependency
|
112
130
|
name: rspec
|
113
131
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +145,9 @@ dependencies:
|
|
127
145
|
requirement: !ruby/object:Gem::Requirement
|
128
146
|
requirements:
|
129
147
|
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0.14'
|
150
|
+
- - ">="
|
130
151
|
- !ruby/object:Gem::Version
|
131
152
|
version: 0.14.1
|
132
153
|
type: :development
|
@@ -134,6 +155,9 @@ dependencies:
|
|
134
155
|
version_requirements: !ruby/object:Gem::Requirement
|
135
156
|
requirements:
|
136
157
|
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.14'
|
160
|
+
- - ">="
|
137
161
|
- !ruby/object:Gem::Version
|
138
162
|
version: 0.14.1
|
139
163
|
- !ruby/object:Gem::Dependency
|
@@ -142,28 +166,40 @@ dependencies:
|
|
142
166
|
requirements:
|
143
167
|
- - "~>"
|
144
168
|
- !ruby/object:Gem::Version
|
145
|
-
version: '3.
|
169
|
+
version: '3.8'
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 3.8.0
|
146
173
|
type: :development
|
147
174
|
prerelease: false
|
148
175
|
version_requirements: !ruby/object:Gem::Requirement
|
149
176
|
requirements:
|
150
177
|
- - "~>"
|
151
178
|
- !ruby/object:Gem::Version
|
152
|
-
version: '3.
|
179
|
+
version: '3.8'
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: 3.8.0
|
153
183
|
- !ruby/object:Gem::Dependency
|
154
184
|
name: pry-doc
|
155
185
|
requirement: !ruby/object:Gem::Requirement
|
156
186
|
requirements:
|
157
187
|
- - "~>"
|
158
188
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
189
|
+
version: '1.2'
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: 1.2.0
|
160
193
|
type: :development
|
161
194
|
prerelease: false
|
162
195
|
version_requirements: !ruby/object:Gem::Requirement
|
163
196
|
requirements:
|
164
197
|
- - "~>"
|
165
198
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
199
|
+
version: '1.2'
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: 1.2.0
|
167
203
|
description: 'create epub from a book index url and mail to you. by setting a default_setting.yml
|
168
204
|
you can use it in shell. '
|
169
205
|
email:
|