epub_book 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -6
- data/lib/epub_book/book.rb +19 -12
- data/lib/epub_book/version.rb +1 -1
- data/lib/epub_book.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 242f6d9ee15d028f0c72cd604790292af9c9b2d9
|
4
|
+
data.tar.gz: 9856509153f5caafd9f2aae760dc4f8013e302a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 088faed36f70d1b635ae0e4eff49648d0f96b985388af0b5fdb319495c62b37662a559a9dc9a06e94564f6cd18173bbbb1238657be56d36f1fffadd3afa3ee27
|
7
|
+
data.tar.gz: 516aee02a5ffa3f7b6fee89ff55fd2399ae7564b69510d7ea1d4c70693906784bcc5df88a012be9223d508cc17033f6cb535f59999ddf76f514bb914953c1e44
|
data/README.md
CHANGED
@@ -71,13 +71,21 @@ Or use a ./default_setting.yml file have following content
|
|
71
71
|
mail_to: 'yourmail@example.com'
|
72
72
|
|
73
73
|
#special host book setting(the key is book_url's host which replacing the dot with underline)
|
74
|
+
#http://www.piaotian.net/html/0/431/index.html
|
74
75
|
www_piaotian_net:
|
75
|
-
cover_css: '
|
76
|
-
description_css: '.
|
77
|
-
title_css: '
|
78
|
-
index_item_css: '
|
79
|
-
body_css: '
|
80
|
-
|
76
|
+
cover_css: '#content td>table:not(.grid) img[src$=jpg]'
|
77
|
+
description_css: '#content td>table:not(.grid) div:last-child > text()'
|
78
|
+
title_css: '#content h1'
|
79
|
+
index_item_css: '.centent a'
|
80
|
+
body_css: 'body > text()'
|
81
|
+
|
82
|
+
#http://www.shumilou.co/yitongjiangshan/
|
83
|
+
www_shumilou_co:
|
84
|
+
cover_css: ".content .list img.sayimg"
|
85
|
+
description_css: ".content .list:contains(img) > text()"
|
86
|
+
title_css: ".content .list .tit b:first"
|
87
|
+
index_item_css: ".content .list ul li a"
|
88
|
+
body_css: '#content p'
|
81
89
|
```
|
82
90
|
|
83
91
|
if you have setting file , you can create book like following
|
data/lib/epub_book/book.rb
CHANGED
@@ -49,6 +49,7 @@ module EpubBook
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def book
|
52
|
+
Dir.mkdir(@book_path) unless test(?d,@book_path)
|
52
53
|
@book ||= test(?s,File.join(@book_path,'index.yml')) ? YAML.load(File.open(File.join(@book_path,'index.yml'))) : ({files: []})
|
53
54
|
end
|
54
55
|
|
@@ -61,7 +62,6 @@ module EpubBook
|
|
61
62
|
|
62
63
|
#创建书本
|
63
64
|
def generate_book(book_name=nil)
|
64
|
-
Dir.mkdir(@book_path) unless test(?d,@book_path)
|
65
65
|
#获取epub源数据
|
66
66
|
fetch_book
|
67
67
|
if !@cover_css && @cover
|
@@ -107,6 +107,8 @@ module EpubBook
|
|
107
107
|
end
|
108
108
|
|
109
109
|
|
110
|
+
|
111
|
+
|
110
112
|
#得到书目索引
|
111
113
|
def fetch_index(url=nil)
|
112
114
|
url ||= @index_url
|
@@ -127,14 +129,7 @@ module EpubBook
|
|
127
129
|
_href = URI.encode(item.attr(@item_attr).to_s)
|
128
130
|
next if _href.start_with?('javascript') || _href.start_with?('#')
|
129
131
|
|
130
|
-
|
131
|
-
_href
|
132
|
-
elsif _href.start_with?("/")
|
133
|
-
_href = "#{link_host}#{_href}"
|
134
|
-
else
|
135
|
-
@path_name ||= @index_url[/.*\//]
|
136
|
-
_href = "#{@path_name}#{_href}"
|
137
|
-
end
|
132
|
+
_href = generate_abs_url(_href)
|
138
133
|
|
139
134
|
book[:files] << {label: item.text, url: _href}
|
140
135
|
end
|
@@ -142,7 +137,7 @@ module EpubBook
|
|
142
137
|
#如果有分页
|
143
138
|
if @page_css && @page_attr
|
144
139
|
if next_page = doc.css(@page_css).attr(@page_attr).to_s
|
145
|
-
fetch_index(next_page)
|
140
|
+
fetch_index(generate_abs_url(next_page))
|
146
141
|
else
|
147
142
|
return
|
148
143
|
end
|
@@ -176,7 +171,7 @@ module EpubBook
|
|
176
171
|
puts item[:label]
|
177
172
|
|
178
173
|
rescue Exception => e
|
179
|
-
puts e.message
|
174
|
+
puts "Error:#{e.message}"
|
180
175
|
puts e.backtrace.inspect
|
181
176
|
next
|
182
177
|
end
|
@@ -197,7 +192,7 @@ module EpubBook
|
|
197
192
|
book[:title] = doc.css(@title_css).text.strip
|
198
193
|
if @cover_css && !book[:cover]
|
199
194
|
cover_url = doc.css(@cover_css).attr("src").to_s
|
200
|
-
cover_url = link_host + cover_url unless cover_url.start_with?("http")
|
195
|
+
cover_url = generate_abs_url(cover_url) #link_host + cover_url unless cover_url.start_with?("http")
|
201
196
|
cover_path = File.join(@book_path,@cover)
|
202
197
|
system("curl #{cover_url} -o #{cover_path} ")
|
203
198
|
book[:cover] = cover_path
|
@@ -208,6 +203,18 @@ module EpubBook
|
|
208
203
|
end
|
209
204
|
end
|
210
205
|
|
206
|
+
def generate_abs_url(url)
|
207
|
+
if _href.start_with?("http")
|
208
|
+
url
|
209
|
+
elsif _href.start_with?("/")
|
210
|
+
"#{link_host}#{_href}"
|
211
|
+
else
|
212
|
+
@path_name ||= @index_url[/.*\//]
|
213
|
+
"#{@path_name}#{_href}"
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
211
218
|
end
|
212
219
|
|
213
220
|
end
|
data/lib/epub_book/version.rb
CHANGED
data/lib/epub_book.rb
CHANGED