epub_book 0.1.19 → 0.1.24
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 +7 -8
- data/lib/epub_book/book.rb +18 -7
- data/lib/epub_book/version.rb +1 -1
- data/lib/epub_book.rb +3 -3
- metadata +54 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9ac65a058cdf7b53e8b45e94a46a96fd60d41a554565c085adbb8b97a86f12d
|
4
|
+
data.tar.gz: 660f5dbc39901304ab576d6a0dd2fcfd1071c1bcd648531ca1d4da38ce18ef34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d4f021a6326c17c1ca3a1e6df6c9ce146486142b12217b687bd67c67d3bb10e3cdadc9740d4073e559ca35817b7078622ee6cd634b2c5ece6cb5f3c90b31e49
|
7
|
+
data.tar.gz: 708a9cd652f79ee677914573f45a8f52f308141164c2c818df13b896949ae95e83de6dc2123e56ff118f144449cd5af6a59f6bf89b69ac61b8fcee2e689aa0be
|
data/Gemfile
CHANGED
data/epub_book.gemspec
CHANGED
@@ -27,18 +27,17 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_dependency 'http','~>
|
31
|
-
|
32
|
-
spec.add_dependency "nokogiri", ">= 1.11.4"
|
30
|
+
spec.add_dependency 'http','~> 5.0', '>= 5.0.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", '~> 13.0','>= 13.0.6'
|
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
@@ -17,12 +17,12 @@ require 'yaml'
|
|
17
17
|
#referer 访问原地址
|
18
18
|
#creator 责任人
|
19
19
|
#ext_name 扩展名 epub,txt
|
20
|
-
|
20
|
+
#ignore_txt 忽略字符,带有ignore_txt的行将被删除
|
21
21
|
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 -r '/#{ignore_txt}/d' #{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.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- qmliu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -16,18 +16,27 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.0.4
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '5.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.0.4
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: nokogiri
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.11'
|
31
40
|
- - ">="
|
32
41
|
- !ruby/object:Gem::Version
|
33
42
|
version: 1.11.4
|
@@ -35,6 +44,9 @@ dependencies:
|
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.11'
|
38
50
|
- - ">="
|
39
51
|
- !ruby/object:Gem::Version
|
40
52
|
version: 1.11.4
|
@@ -84,30 +96,42 @@ dependencies:
|
|
84
96
|
name: bundler
|
85
97
|
requirement: !ruby/object:Gem::Requirement
|
86
98
|
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.2'
|
87
102
|
- - ">="
|
88
103
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.2.
|
104
|
+
version: 2.2.27
|
90
105
|
type: :development
|
91
106
|
prerelease: false
|
92
107
|
version_requirements: !ruby/object:Gem::Requirement
|
93
108
|
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.2'
|
94
112
|
- - ">="
|
95
113
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.2.
|
114
|
+
version: 2.2.27
|
97
115
|
- !ruby/object:Gem::Dependency
|
98
116
|
name: rake
|
99
117
|
requirement: !ruby/object:Gem::Requirement
|
100
118
|
requirements:
|
101
119
|
- - "~>"
|
102
120
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
121
|
+
version: '13.0'
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 13.0.6
|
104
125
|
type: :development
|
105
126
|
prerelease: false
|
106
127
|
version_requirements: !ruby/object:Gem::Requirement
|
107
128
|
requirements:
|
108
129
|
- - "~>"
|
109
130
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
131
|
+
version: '13.0'
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 13.0.6
|
111
135
|
- !ruby/object:Gem::Dependency
|
112
136
|
name: rspec
|
113
137
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +151,9 @@ dependencies:
|
|
127
151
|
requirement: !ruby/object:Gem::Requirement
|
128
152
|
requirements:
|
129
153
|
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0.14'
|
156
|
+
- - ">="
|
130
157
|
- !ruby/object:Gem::Version
|
131
158
|
version: 0.14.1
|
132
159
|
type: :development
|
@@ -134,6 +161,9 @@ dependencies:
|
|
134
161
|
version_requirements: !ruby/object:Gem::Requirement
|
135
162
|
requirements:
|
136
163
|
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0.14'
|
166
|
+
- - ">="
|
137
167
|
- !ruby/object:Gem::Version
|
138
168
|
version: 0.14.1
|
139
169
|
- !ruby/object:Gem::Dependency
|
@@ -142,28 +172,40 @@ dependencies:
|
|
142
172
|
requirements:
|
143
173
|
- - "~>"
|
144
174
|
- !ruby/object:Gem::Version
|
145
|
-
version: '3.
|
175
|
+
version: '3.8'
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: 3.8.0
|
146
179
|
type: :development
|
147
180
|
prerelease: false
|
148
181
|
version_requirements: !ruby/object:Gem::Requirement
|
149
182
|
requirements:
|
150
183
|
- - "~>"
|
151
184
|
- !ruby/object:Gem::Version
|
152
|
-
version: '3.
|
185
|
+
version: '3.8'
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 3.8.0
|
153
189
|
- !ruby/object:Gem::Dependency
|
154
190
|
name: pry-doc
|
155
191
|
requirement: !ruby/object:Gem::Requirement
|
156
192
|
requirements:
|
157
193
|
- - "~>"
|
158
194
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
195
|
+
version: '1.2'
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: 1.2.0
|
160
199
|
type: :development
|
161
200
|
prerelease: false
|
162
201
|
version_requirements: !ruby/object:Gem::Requirement
|
163
202
|
requirements:
|
164
203
|
- - "~>"
|
165
204
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
205
|
+
version: '1.2'
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 1.2.0
|
167
209
|
description: 'create epub from a book index url and mail to you. by setting a default_setting.yml
|
168
210
|
you can use it in shell. '
|
169
211
|
email:
|