mangdown 0.10.0 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mangdown/chapter.rb +15 -6
- data/lib/mangdown/manga.rb +39 -3
- data/lib/mangdown/mangdown.rb +1 -1
- data/lib/mangdown/mangdown_hash.rb +6 -2
- data/lib/mangdown/page.rb +2 -1
- metadata +6 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fcefd9f91de261d15fdb0c165ec5be1852c9507
|
4
|
+
data.tar.gz: 23b77f0de9dfd3b57bea6d7d23a2d63ed51165b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fffa3aca22c07425b59007d0d50500a01f28d8292763494ee2518e07348d98f1f8a921e54914db654b297be3c38ce99dae0c7c7cd2d2d87e7b6d3e3aead7acff
|
7
|
+
data.tar.gz: 69c6e148cfefb9dd5906860ece93b5d8ead402b4ee71814cabcb33bbb991b6a81af747e4b3d74d2977561a467b3de5fee45c25181ec340891e02b23b1360c615
|
data/lib/mangdown/chapter.rb
CHANGED
@@ -20,6 +20,13 @@ module Mangdown
|
|
20
20
|
@pages.sort_by! {|page| page.name}
|
21
21
|
end
|
22
22
|
|
23
|
+
def inspect
|
24
|
+
"#<#{self.class} @name=#{name} @uri=#{uri} " +
|
25
|
+
"@pages=[#{pages.first(10).join(',')}" +
|
26
|
+
"#{",..." if pages.length > 10}]>"
|
27
|
+
end
|
28
|
+
alias_method :to_s, :inspect
|
29
|
+
|
23
30
|
# enumerates through pages
|
24
31
|
def each
|
25
32
|
block_given? ? @pages.each { |page| yield(page) } : @pages.each
|
@@ -35,14 +42,16 @@ module Mangdown
|
|
35
42
|
dir = File.expand_path(dir + '/' + @name)
|
36
43
|
Dir.mkdir(dir) unless Dir.exists?(dir)
|
37
44
|
|
38
|
-
threads
|
39
|
-
|
40
|
-
threads
|
41
|
-
|
45
|
+
# Limit active threads to 20
|
46
|
+
each_slice(20) do |slice|
|
47
|
+
threads = []
|
48
|
+
slice.each do |page|
|
49
|
+
threads << Thread.new(page) do |this_page|
|
50
|
+
this_page.to_page.download_to(dir)
|
51
|
+
end
|
42
52
|
end
|
53
|
+
threads.each {|thread| thread.join}
|
43
54
|
end
|
44
|
-
|
45
|
-
threads.each {|thread| thread.join}
|
46
55
|
end
|
47
56
|
|
48
57
|
private
|
data/lib/mangdown/manga.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'progress_bar'
|
2
|
+
|
1
3
|
module Mangdown
|
2
4
|
|
3
5
|
DOWNLOAD_DIR ||= Dir.home + '/manga'
|
@@ -16,8 +18,15 @@ module Mangdown
|
|
16
18
|
@properties = Properties.new(@uri)
|
17
19
|
|
18
20
|
get_chapters
|
19
|
-
|
21
|
+
@chapters.select! { |chapter| @properties.is_chapter?(chapter) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
"#<#{self.class} @name=#{name} @uri=#{uri} " +
|
26
|
+
"@chapters=[#{chapters.first(10).join(',')}" +
|
27
|
+
"#{",..." if chapters.length > 10}]>"
|
20
28
|
end
|
29
|
+
alias_method :to_s, :inspect
|
21
30
|
|
22
31
|
# download to current directory convenience method
|
23
32
|
def download(*args)
|
@@ -26,11 +35,14 @@ module Mangdown
|
|
26
35
|
|
27
36
|
# download using enumerable
|
28
37
|
def download_to(dir, start = 0, stop = -1)
|
29
|
-
|
38
|
+
start, stop = validate_indeces!(start, stop)
|
39
|
+
dir = setup_download_dir!(dir)
|
40
|
+
|
41
|
+
bar = progress_bar(start, stop)
|
30
42
|
reset(start, stop)
|
31
|
-
Dir.mkdir(dir) unless Dir.exist?(dir)
|
32
43
|
loop do
|
33
44
|
self.next.to_chapter.download_to(dir)
|
45
|
+
bar.increment!
|
34
46
|
end
|
35
47
|
end
|
36
48
|
|
@@ -72,5 +84,29 @@ module Mangdown
|
|
72
84
|
|
73
85
|
@chapters.reverse! if @properties.reverse
|
74
86
|
end
|
87
|
+
|
88
|
+
def chapter_indeces(start, stop)
|
89
|
+
[chapters.index(chapters[start]), chapters.index(chapters[stop])]
|
90
|
+
end
|
91
|
+
|
92
|
+
def setup_download_dir!(dir)
|
93
|
+
dir += "/#{name}"
|
94
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
95
|
+
dir
|
96
|
+
end
|
97
|
+
|
98
|
+
def validate_indeces!(start, stop)
|
99
|
+
i_start, i_stop = chapter_indeces(start, stop)
|
100
|
+
if i_stop < i_stop
|
101
|
+
error = 'Last index must be greater than first index'
|
102
|
+
raise ArgumentError, error
|
103
|
+
end
|
104
|
+
[i_start, i_stop]
|
105
|
+
end
|
106
|
+
|
107
|
+
# create a progress bar object for start and stop indexes
|
108
|
+
def progress_bar(start, stop)
|
109
|
+
ProgressBar.new(stop - start + 1)
|
110
|
+
end
|
75
111
|
end
|
76
112
|
end
|
data/lib/mangdown/mangdown.rb
CHANGED
data/lib/mangdown/page.rb
CHANGED
@@ -5,6 +5,7 @@ module Mangdown
|
|
5
5
|
attr_reader :name, :uri
|
6
6
|
|
7
7
|
def initialize(name, uri)
|
8
|
+
name.gsub!(/_/, ' ') && name.gsub!(/-/, '')
|
8
9
|
@name = name.sub(/([^\d])(\d+)(\.\w+)$/) {
|
9
10
|
"#{Regexp.last_match[1]}" +
|
10
11
|
"#{Regexp.last_match[2].to_s.rjust(3, '0')}" +
|
@@ -29,7 +30,7 @@ module Mangdown
|
|
29
30
|
# don't download again
|
30
31
|
return if File.exist?(path)
|
31
32
|
image = open(uri).read
|
32
|
-
File.open(path, 'wb') {|file| file.write(image)}
|
33
|
+
Tools.no_time_out { File.open(path, 'wb') { |file| file.write(image) } }
|
33
34
|
rescue SocketError => error
|
34
35
|
STDERR.puts( "#{error.message} | #{name} | #{uri}" )
|
35
36
|
end
|
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.10.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jphager2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -81,47 +81,19 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.1.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: progress_bar
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
90
|
-
type: :
|
89
|
+
version: 1.0.3
|
90
|
+
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: guard-rspec
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: reek
|
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'
|
96
|
+
version: 1.0.3
|
125
97
|
- !ruby/object:Gem::Dependency
|
126
98
|
name: webmock
|
127
99
|
requirement: !ruby/object:Gem::Requirement
|