mangdown 0.15.0 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mangdown/adapter/mangareader.rb +3 -1
- data/lib/mangdown/adapter/proxy.rb +34 -0
- data/lib/mangdown/adapter.rb +0 -1
- data/lib/mangdown/manga.rb +5 -1
- data/lib/mangdown/page.rb +11 -4
- data/lib/mangdown/version.rb +1 -1
- data/lib/mangdown.rb +7 -5
- data/test/lib/mangdown/chapter_test.rb +1 -1
- data/test/lib/mangdown_test.rb +6 -3
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c55c78329762e6af9921776a2c8c643ea563ec5
|
4
|
+
data.tar.gz: 3556d64b7a4dfb176e13929c3560b37d09c9c8f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22dba31e19428a793823ad4afd6ec132c02307254d349bccd23b1b9036d08e20d2487b2571629ec7952826bbe8d2d7d533da2304a948314c3bb26fd3718b4b1b
|
7
|
+
data.tar.gz: 683f50a23e461e3ffd0728217c6fe6a15247495f8aa06621fcb914683252654c7659c40bc7de0d6950c47f74a138aec966a63c76cd305aef483026fd2edf49e5
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
module Mangdown
|
2
4
|
class Mangareader < Adapter::Base
|
3
5
|
|
@@ -62,7 +64,7 @@ module Mangdown
|
|
62
64
|
def page_list
|
63
65
|
last_page = doc.css('select')[1].css('option').length
|
64
66
|
(1..last_page).map { |page|
|
65
|
-
slug = manga_name.gsub(' ', '-').gsub(/[
|
67
|
+
slug = manga_name.gsub(' ', '-').gsub(/[:,!]/, '')
|
66
68
|
uri = "#{root}/#{slug}/#{chapter_number}/#{page}"
|
67
69
|
uri = URI.escape(uri).downcase
|
68
70
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Mangdown
|
2
|
+
module Adapter
|
3
|
+
# Wraps Adapters to provide error reporting
|
4
|
+
class Proxy
|
5
|
+
include Logging
|
6
|
+
|
7
|
+
attr_reader :adapter
|
8
|
+
|
9
|
+
def initialize(adapter)
|
10
|
+
@adapter = adapter
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
return super unless @adapter.respond_to?(method)
|
17
|
+
|
18
|
+
adapter.public_send(method, *args, &block)
|
19
|
+
rescue => e
|
20
|
+
logger.error({
|
21
|
+
msg: 'Adapter method failed',
|
22
|
+
adapter: adapter.class,
|
23
|
+
uri: adapter.uri,
|
24
|
+
doc: adapter.doc.to_s,
|
25
|
+
method: method,
|
26
|
+
error: e,
|
27
|
+
error_msg: e.message,
|
28
|
+
backtrace: e.backtrace
|
29
|
+
}.to_s)
|
30
|
+
raise Mangdown::Error, "Adapter failed: #{e.message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/mangdown/adapter.rb
CHANGED
data/lib/mangdown/manga.rb
CHANGED
@@ -49,7 +49,11 @@ module Mangdown
|
|
49
49
|
skipped << chapter
|
50
50
|
end
|
51
51
|
if chapter_result[:failed].any?
|
52
|
-
logger.error
|
52
|
+
logger.error({
|
53
|
+
msg: "Chapter was not fully downloaded",
|
54
|
+
uri: chapter.uri,
|
55
|
+
chapter: chapter.name
|
56
|
+
}.to_s)
|
53
57
|
end
|
54
58
|
end
|
55
59
|
{ failed: failed, succeeded: succeeded, skipped: skipped }
|
data/lib/mangdown/page.rb
CHANGED
@@ -28,7 +28,7 @@ module Mangdown
|
|
28
28
|
dir ||= File.join(manga, chapter)
|
29
29
|
dir = Tools.valid_path_name(dir)
|
30
30
|
if Dir.exist?(dir)
|
31
|
-
file = Dir.entries(dir).find { |
|
31
|
+
file = Dir.entries(dir).find { |f| f[name] }
|
32
32
|
end
|
33
33
|
path = File.join(dir, file || name)
|
34
34
|
@path = Tools.relative_or_absolute_path(path)
|
@@ -40,13 +40,20 @@ module Mangdown
|
|
40
40
|
delete_files!(dir) if opts[:force_download]
|
41
41
|
|
42
42
|
return if file_exist?(dir)
|
43
|
-
|
43
|
+
|
44
44
|
image = Tools.get(uri)
|
45
45
|
|
46
46
|
append_file_data(dir, image)
|
47
47
|
append_file_ext(dir)
|
48
|
-
rescue => error
|
49
|
-
logger.error
|
48
|
+
rescue => error
|
49
|
+
logger.error({
|
50
|
+
msg: 'Failed to download page',
|
51
|
+
page: self,
|
52
|
+
uri: uri,
|
53
|
+
error: error,
|
54
|
+
error_msg: error.message,
|
55
|
+
backtrace: error.backtrace
|
56
|
+
}.to_s)
|
50
57
|
end
|
51
58
|
|
52
59
|
def append_file_data(dir, data)
|
data/lib/mangdown/version.rb
CHANGED
data/lib/mangdown.rb
CHANGED
@@ -16,6 +16,7 @@ require_relative 'mangdown/manga_list.rb'
|
|
16
16
|
require_relative 'mangdown/md_hash'
|
17
17
|
|
18
18
|
require_relative 'mangdown/adapter'
|
19
|
+
require_relative 'mangdown/adapter/proxy'
|
19
20
|
require_relative 'mangdown/adapter/no_adapter_error'
|
20
21
|
require_relative 'mangdown/adapter/mangareader.rb'
|
21
22
|
|
@@ -36,11 +37,12 @@ module Mangdown
|
|
36
37
|
adapter_name = (uri || site).to_s
|
37
38
|
klass = ADAPTERS.values.find { |adapter| adapter.for?(adapter_name) }
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
raise Adapter::NoAdapterError, adapter_name unless klass
|
41
|
+
|
42
|
+
Adapter::Proxy.new(klass.new(uri, doc, name))
|
43
|
+
end
|
44
|
+
|
45
|
+
class Error < StandardError
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
data/test/lib/mangdown_test.rb
CHANGED
@@ -20,14 +20,17 @@ class MangdownTest < Minitest::Test
|
|
20
20
|
|
21
21
|
def test_adapter
|
22
22
|
assert_equal TestAdapter, Mangdown.adapter(:test)
|
23
|
+
assert_equal TestAdapter, Mangdown.adapter(:test)
|
23
24
|
end
|
24
25
|
|
25
26
|
def test_adapter!
|
26
|
-
assert_instance_of
|
27
|
-
|
27
|
+
assert_instance_of Mangdown::Adapter::Proxy, Mangdown.adapter!("test")
|
28
|
+
|
29
|
+
assert_instance_of TestAdapter, Mangdown.adapter!("test").adapter
|
30
|
+
assert_instance_of TestAdapter, Mangdown.adapter!(nil, "test").adapter
|
28
31
|
assert_instance_of TestAdapter, Mangdown.adapter!(
|
29
32
|
"test", nil, doc, "test"
|
30
|
-
)
|
33
|
+
).adapter
|
31
34
|
|
32
35
|
adapters = Mangdown::ADAPTERS.dup
|
33
36
|
Mangdown::ADAPTERS.clear
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mangdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.15.
|
4
|
+
version: 0.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jphager2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '5.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: Download Manga
|
112
126
|
email: jphager2@gmail.com
|
113
127
|
executables: []
|
@@ -120,6 +134,7 @@ files:
|
|
120
134
|
- lib/mangdown/adapter.rb
|
121
135
|
- lib/mangdown/adapter/mangareader.rb
|
122
136
|
- lib/mangdown/adapter/no_adapter_error.rb
|
137
|
+
- lib/mangdown/adapter/proxy.rb
|
123
138
|
- lib/mangdown/chapter.rb
|
124
139
|
- lib/mangdown/client.rb
|
125
140
|
- lib/mangdown/manga.rb
|