kindler 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kindler/version.rb +1 -1
- data/lib/kindler.rb +24 -19
- metadata +5 -5
data/lib/kindler/version.rb
CHANGED
data/lib/kindler.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
require 'rubygems'
|
2
|
-
require File.dirname(__FILE__)+"/kindler/version"
|
3
3
|
require "readability"
|
4
4
|
require "open-uri"
|
5
5
|
# require 'mini_magick'
|
6
|
-
|
6
|
+
require_relative 'kindler/railtie' if defined?(Rails)
|
7
|
+
require_relative "kindler/version"
|
7
8
|
|
8
9
|
module Kindler
|
9
10
|
class Book
|
@@ -189,24 +190,28 @@ module Kindler
|
|
189
190
|
@doc_infos.each do |url,infos|
|
190
191
|
article = Nokogiri::HTML(infos[:content])
|
191
192
|
article.css('img').each do |img|
|
192
|
-
|
193
|
-
|
194
|
-
image_remote_address
|
193
|
+
begin
|
194
|
+
image_remote_address = img.attr('src')
|
195
|
+
unless image_remote_address.start_with?('http')
|
196
|
+
image_remote_address = "http://#{URI(url).host}#{image_remote_address}"
|
197
|
+
end
|
198
|
+
image_local_address = File.join(tmp_dir,"#{images_count}#{File.extname(image_remote_address)}")
|
199
|
+
# download images
|
200
|
+
debug "begin fetch image #{image_remote_address}"
|
201
|
+
debug "save to #{image_local_address}"
|
202
|
+
File.open(image_local_address,'w') do |f|
|
203
|
+
f.puts open(image_remote_address).read
|
204
|
+
end
|
205
|
+
debug 'Image saved'
|
206
|
+
# replace local url address
|
207
|
+
img.attributes['src'].value = "#{images_count}#{File.extname(image_remote_address)}"
|
208
|
+
infos[:content] = article.inner_html
|
209
|
+
# add to manifest
|
210
|
+
@images << "#{images_count}#{File.extname(image_remote_address)}"
|
211
|
+
images_count += 1
|
212
|
+
rescue Exception => e
|
213
|
+
debug "got error when fetch and save image: #{e}"
|
195
214
|
end
|
196
|
-
image_local_address = File.join(tmp_dir,"#{images_count}#{File.extname(image_remote_address)}")
|
197
|
-
# download images
|
198
|
-
debug "begin fetch image #{image_remote_address}"
|
199
|
-
debug "save to #{image_local_address}"
|
200
|
-
File.open(image_local_address,'w') do |f|
|
201
|
-
f.puts open(image_remote_address).read
|
202
|
-
end
|
203
|
-
debug 'Image saved'
|
204
|
-
# replace local url address
|
205
|
-
img.attributes['src'].value = "#{images_count}#{File.extname(image_remote_address)}"
|
206
|
-
infos[:content] = article.inner_html
|
207
|
-
# add to manifest
|
208
|
-
@images << "#{images_count}#{File.extname(image_remote_address)}"
|
209
|
-
images_count += 1
|
210
215
|
end
|
211
216
|
end
|
212
217
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kindler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-03 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mini_magick
|
16
|
-
requirement: &
|
16
|
+
requirement: &2155686500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2155686500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ruby-readability
|
27
|
-
requirement: &
|
27
|
+
requirement: &2155686080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2155686080
|
36
36
|
description: kindler is a rubygem allow you to generate kindle mobi book from urls
|
37
37
|
very easily
|
38
38
|
email:
|