mangdown 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/doc/help.txt +33 -0
- data/lib/mangdown/cbz.rb +38 -0
- data/lib/mangdown/chapter.rb +131 -0
- data/lib/mangdown/commands.rb +45 -0
- data/lib/mangdown/manga.rb +46 -0
- data/lib/mangdown/mangdown_hash.rb +8 -0
- data/lib/mangdown/page.rb +16 -0
- data/lib/mangdown/popular.rb +52 -0
- data/lib/mangdown/tools.rb +110 -0
- data/lib/mangdown.rb +19 -0
- data/scripts/cbz_dirs.rb +67 -0
- data/scripts/dl_fk_ch.rb +14 -0
- data/scripts/dl_fk_chps.rb +25 -0
- data/scripts/dl_slow.rb +77 -0
- data/scripts/get_all_fk_page.rb +72 -0
- data/spec/mangdown/chapter_spec.rb +120 -0
- data/spec/mangdown/commands_spec.rb +35 -0
- data/spec/mangdown/manga_spec.rb +77 -0
- data/spec/mangdown/page_spec.rb +34 -0
- data/spec/mangdown/popular_spec.rb +67 -0
- data/spec/objects/make_chapter.rb +5 -0
- data/spec/spec_helper.rb +39 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0eeabd1173684b550b4cdf72608c175b4391510
|
4
|
+
data.tar.gz: 65dc5fd208fbea67661742c9783f52faaa12aaeb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce29debf06fb2c5b16ff66f133c8cd0ef2bc8a2f6de9b234d7d37647a214f4e7011d9a0432965b12983381f219cc2d233e253a609fcc0ed7281c03aef7cbb854
|
7
|
+
data.tar.gz: f389ae7aaab05d16ac7669cf1a98f8b7ec358ee5c71a6871a5d5c0aadfe1e5022dd4615ca8061fa9ecf2efd0391fc824ca94832912c860386ec57b93d25c76d0
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 John Hager
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/doc/help.txt
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
==============================================================================
|
2
|
+
Mangdown
|
3
|
+
|
4
|
+
Commands
|
5
|
+
|
6
|
+
M#find(string) - Will return an array of Mangdown::MDHash given a string
|
7
|
+
which is matched to manga names of the 3000 most popular
|
8
|
+
mangas on Mangareader.
|
9
|
+
|
10
|
+
results = M.find('Naruto')
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
*** Use Mangdown::MDHash#get_manga to get a Mangdown::Manga object ***
|
15
|
+
|
16
|
+
naruto = results[0].get_manga
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
M#download(manga, int = 0, int = -1)
|
21
|
+
- Will download a manga (Mangdown::Manga object) from the
|
22
|
+
first int (index of the first chapter) to the last int
|
23
|
+
(index of the last chapter) to a subdirectory named
|
24
|
+
#{manga.name}". If no indexes are given, all chapters
|
25
|
+
are downloaded.
|
26
|
+
|
27
|
+
M.download(naruto, 500, 549)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
M#help - Will display help for commands
|
32
|
+
|
33
|
+
==============================================================================
|
data/lib/mangdown/cbz.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Mangdown
|
2
|
+
module CBZ
|
3
|
+
extend self
|
4
|
+
extend ::Mangdown::Tools
|
5
|
+
|
6
|
+
def cbz_dir(dir)
|
7
|
+
zip_file_name = dir + '.cbz'
|
8
|
+
dir += '/' unless dir[-1] == '/'
|
9
|
+
|
10
|
+
::Zip::File.open(zip_file_name, ::Zip::File::CREATE) do |zp|
|
11
|
+
Dir[File.join(dir, '**', '**')].each do |file|
|
12
|
+
zp.add(file.sub(dir, ''), file)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def cbz_sub_dirs(dir)
|
18
|
+
check_dir(dir) do |d|
|
19
|
+
cbz_dir(d)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def all(main_dir)
|
24
|
+
if Dir.exist?(main_dir)
|
25
|
+
# Make sure all sub dirs are checked
|
26
|
+
validate_file_or_dir_names(main_dir)
|
27
|
+
# Make sure all sub dirs have files checked
|
28
|
+
check_dir(main_dir) { |d| validate_file_or_dir_names(d)}
|
29
|
+
# Create cbz files for all sub dirs
|
30
|
+
cbz_sub_dirs(main_dir)
|
31
|
+
# new line
|
32
|
+
puts
|
33
|
+
else
|
34
|
+
puts "Cannot find directory"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module Mangdown
|
2
|
+
class Chapter
|
3
|
+
include ::Mangdown::Tools
|
4
|
+
|
5
|
+
attr_reader :name, :pages, :uri, :num_pages
|
6
|
+
|
7
|
+
def initialize( uri, name )
|
8
|
+
@uri = uri
|
9
|
+
@name = name
|
10
|
+
@pages = []
|
11
|
+
@root = get_root(@uri)
|
12
|
+
|
13
|
+
get_pages
|
14
|
+
end
|
15
|
+
|
16
|
+
def download
|
17
|
+
start_dir = Dir.pwd
|
18
|
+
Dir.mkdir(@name) unless Dir.exists?(@name)
|
19
|
+
Dir.chdir(@name)
|
20
|
+
|
21
|
+
@pages.each {|page| page.download}
|
22
|
+
|
23
|
+
Dir.chdir(start_dir)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_pages
|
27
|
+
uri = @uri
|
28
|
+
get_doc(uri)
|
29
|
+
@num_pages ||= get_num_pages
|
30
|
+
|
31
|
+
@num_pages.times do
|
32
|
+
page_uri, page_name = get_page
|
33
|
+
@pages << Page.new( page_uri, page_name )
|
34
|
+
uri = get_next_uri
|
35
|
+
get_doc(uri)
|
36
|
+
end
|
37
|
+
|
38
|
+
@doc = "Nokogiri::HTML::Document"
|
39
|
+
end
|
40
|
+
|
41
|
+
#def get_page # STAR
|
42
|
+
# image = @doc.css('img')[0]
|
43
|
+
# [image['src'], image['alt']]
|
44
|
+
#end
|
45
|
+
|
46
|
+
#def get_next_uri # STAR
|
47
|
+
# get_root(@uri)
|
48
|
+
# @root + @doc.css('div#imgholder a')[0]['href']
|
49
|
+
#end
|
50
|
+
end
|
51
|
+
|
52
|
+
class MRChapter < Chapter
|
53
|
+
def get_page # STAR
|
54
|
+
image = @doc.css('img')[0]
|
55
|
+
[image['src'], image['alt']]
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_next_uri # STAR
|
59
|
+
@root + @doc.css('div#imgholder a')[0]['href']
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_num_pages
|
63
|
+
@doc.css('select')[1].children.length
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class FKChapter < Chapter
|
68
|
+
attr_reader :num_pages
|
69
|
+
|
70
|
+
def initialize(uri, name, num_pages)
|
71
|
+
@num_pages = num_pages
|
72
|
+
|
73
|
+
super(uri, name)
|
74
|
+
end
|
75
|
+
|
76
|
+
=begin
|
77
|
+
def get_pages
|
78
|
+
uri = @uri
|
79
|
+
get_doc(uri)
|
80
|
+
|
81
|
+
@num_pages.times do
|
82
|
+
page_uri, page_name = get_page
|
83
|
+
@pages << Page.new( page_uri, page_name )
|
84
|
+
uri = get_next_uri
|
85
|
+
get_doc(uri)
|
86
|
+
end
|
87
|
+
|
88
|
+
@doc = "Nokogiri::HTML::Document"
|
89
|
+
end
|
90
|
+
=end
|
91
|
+
|
92
|
+
def get_page # STAR
|
93
|
+
page = (@pages.length + 1).to_s
|
94
|
+
while page.length < 3
|
95
|
+
page = '0' + page
|
96
|
+
end
|
97
|
+
|
98
|
+
# puts "Doc: #{@doc.css('script').text.length}"
|
99
|
+
#
|
100
|
+
# It seems that Nokogiri cuts out the spaces that were previously there
|
101
|
+
# before
|
102
|
+
#
|
103
|
+
# Watch this because I'm guessing this might revert back
|
104
|
+
#
|
105
|
+
#s = /(http:\/\/t\.fakku\.net)(.+?)('\+x\+')(\.jpg)/
|
106
|
+
#image = @doc.css('script').text.slice(s)
|
107
|
+
#image.sub!(/'\+x\+'/, page)
|
108
|
+
|
109
|
+
script = @doc.css('script').text
|
110
|
+
|
111
|
+
if script.include?("' + x + '.jpg")
|
112
|
+
# puts "With spaces"
|
113
|
+
ss = "'\s\\+\sx\s\\+\s'"
|
114
|
+
else
|
115
|
+
# puts "No spaces"
|
116
|
+
ss = "'\\+x\\+'"
|
117
|
+
end
|
118
|
+
|
119
|
+
s = Regexp.new("(http:\/\/t\.fakku\.net)(.+?)(#{ss})(\.jpg)")
|
120
|
+
image = script.slice(s)
|
121
|
+
image.sub!(Regexp.new(ss), page)
|
122
|
+
|
123
|
+
|
124
|
+
[image, "Page - #{page}"]
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_next_uri # STAR
|
128
|
+
"#{::URI.join( @uri, 'read#page=')}#{@pages.length + 2}"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module M
|
2
|
+
extend self
|
3
|
+
|
4
|
+
include ::Mangdown
|
5
|
+
extend ::Mangdown::Tools
|
6
|
+
|
7
|
+
#returns a list of hash with :uri and :name of mangas found in @@list
|
8
|
+
def find(manga_name)
|
9
|
+
unless manga_name =~ /\w/
|
10
|
+
puts 'Bad search term'
|
11
|
+
return []
|
12
|
+
end
|
13
|
+
|
14
|
+
@@list ||= PopularManga.new('http://www.mangareader.net/popular', 3000)
|
15
|
+
|
16
|
+
fnd = @@list.mangas_list.select do |m|
|
17
|
+
m[1].downcase.include?(manga_name.downcase)
|
18
|
+
end
|
19
|
+
|
20
|
+
fnd.collect! do |m|
|
21
|
+
h = MDHash.new
|
22
|
+
h[:uri], h[:name] = m[0], m[1]
|
23
|
+
h
|
24
|
+
end
|
25
|
+
|
26
|
+
puts "Could not find manga" if fnd.empty?
|
27
|
+
|
28
|
+
fnd
|
29
|
+
end
|
30
|
+
|
31
|
+
def download(manga, bgn = 0, nd = -1)
|
32
|
+
m = slow_get_chapters(manga, bgn, nd)
|
33
|
+
slow_dl_chapters(m)
|
34
|
+
end
|
35
|
+
|
36
|
+
def cbz(dir)
|
37
|
+
CBZ.all(dir)
|
38
|
+
end
|
39
|
+
|
40
|
+
def help
|
41
|
+
help_file = File.expand_path('../../doc/help.txt', File.dirname(__FILE__))
|
42
|
+
puts help_file
|
43
|
+
puts File.open(help_file, 'r').read
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Mangdown
|
2
|
+
class Manga
|
3
|
+
include ::Mangdown::Tools
|
4
|
+
|
5
|
+
attr_reader :chapters, :chapters_list, :name, :uri
|
6
|
+
|
7
|
+
def initialize(uri, name)
|
8
|
+
@uri = uri
|
9
|
+
@name = name
|
10
|
+
@chapters = []
|
11
|
+
@chapters_list = []
|
12
|
+
@doc = get_doc(@uri)
|
13
|
+
@root = get_root(@uri)
|
14
|
+
|
15
|
+
get_chapters_list
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_chapters_list
|
19
|
+
@doc.css('div#chapterlist td a').each do |chapter|
|
20
|
+
@chapters_list << ([@root + chapter['href'], chapter.text])
|
21
|
+
end
|
22
|
+
|
23
|
+
@doc = "Nokogiri::HTML::Document"
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_chapter(index)
|
27
|
+
|
28
|
+
uri, name = @chapters_list[index]
|
29
|
+
|
30
|
+
unless @chapters.find {|chp| (chp.name == name) or (chp.uri == uri)}
|
31
|
+
# this is far from ideal
|
32
|
+
chapter_klass = if @root.include?('mangareader')
|
33
|
+
MRChapter
|
34
|
+
elsif @root.include?('fakku')
|
35
|
+
FKChapter
|
36
|
+
else
|
37
|
+
NO_Chapter
|
38
|
+
end
|
39
|
+
|
40
|
+
@chapters << chapter_klass.new(uri, name)
|
41
|
+
else
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Mangdown
|
2
|
+
class Page
|
3
|
+
attr_reader :filename, :uri
|
4
|
+
|
5
|
+
def initialize( uri, filename )
|
6
|
+
@filename = filename + '.jpg'
|
7
|
+
@uri = uri
|
8
|
+
end
|
9
|
+
|
10
|
+
def download
|
11
|
+
File.open(@filename, 'wb') do |file|
|
12
|
+
file.write(open(URI.encode(@uri, '[]')).read)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Mangdown
|
2
|
+
class PopularManga
|
3
|
+
include ::Mangdown::Tools
|
4
|
+
|
5
|
+
attr_reader :uri, :mangas_list, :mangas, :name
|
6
|
+
|
7
|
+
def initialize(uri, num_mangas, name = "My Pop Manga")
|
8
|
+
@uri = uri
|
9
|
+
@num_mangas = num_mangas
|
10
|
+
@name = name
|
11
|
+
|
12
|
+
@mangas_list = []
|
13
|
+
@mangas = []
|
14
|
+
|
15
|
+
@root = get_root(@uri)
|
16
|
+
|
17
|
+
get_mangas_list
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_manga(index)
|
21
|
+
uri, name = @mangas_list[index - 1]
|
22
|
+
unless @mangas.find {|manga| (manga.name == name) or (manga.uri == uri)}
|
23
|
+
@mangas << Manga.new( uri, name )
|
24
|
+
else
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_mangas_list
|
30
|
+
(@num_mangas / 30.0).ceil.times do |time|
|
31
|
+
get_pop_page_manga(time).each { |manga| @mangas_list << manga }
|
32
|
+
end
|
33
|
+
|
34
|
+
@doc = "Nokogiri::HTML::Document"
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_pop_page_manga(time)
|
38
|
+
num = 30 * (time)
|
39
|
+
page = @root + '/popular/' + num.to_s
|
40
|
+
get_doc(page)
|
41
|
+
|
42
|
+
last = (@num_mangas > 30) ? 30 : @num_mangas
|
43
|
+
@num_mangas -= 30
|
44
|
+
|
45
|
+
get_manga_on_page[0..(last - 1)]
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_manga_on_page
|
49
|
+
@doc.css('h3 a').map {|a| [@root + a['href'], a.text]}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Mangdown
|
2
|
+
module Tools
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def get_doc(uri)
|
6
|
+
@doc = ::Nokogiri::HTML(open(uri))
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_root(uri)
|
10
|
+
@root = ::URI::join(uri, "/").to_s[0..-2]
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"<#{self.class}::#{self.object_id} : #{@name} : #{@uri}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def eql?(other)
|
18
|
+
(@name == other.name) and (@uri == other.uri)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(other)
|
22
|
+
puts 'You may want to use :eql?'
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def no_time_out(tries = 3)
|
27
|
+
begin
|
28
|
+
timeout(120) do
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
rescue
|
32
|
+
if tries > 0
|
33
|
+
tries -= 1
|
34
|
+
puts "Tries left: #{tries}"
|
35
|
+
no_time_out(tries)
|
36
|
+
else
|
37
|
+
return
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def slow_get_chapters(manga, bgn, nd)
|
43
|
+
@@file_name = File.expand_path("#{manga.name}_temp.yml")
|
44
|
+
|
45
|
+
exists = File.exist?(@@file_name)
|
46
|
+
manga_from_file = YAML.load(File.open(@@file_name, 'r').read) if exists
|
47
|
+
|
48
|
+
if manga_from_file and (manga_from_file.chapters.length > 0)
|
49
|
+
frst = (manga.chapters_list[bgn][1] ==
|
50
|
+
manga_from_file.chapters.first.name)
|
51
|
+
lst = (manga.chapters_list[nd][1] == manga_from_file.chapters.last.name)
|
52
|
+
manga = manga_from_file if (frst and lst)
|
53
|
+
else
|
54
|
+
manga.chapters_list[bgn..nd].each_index do |i|
|
55
|
+
no_time_out {manga.get_chapter(i + bgn)}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
File.open(@@file_name, 'w') {|f| f.write(manga.to_yaml)}
|
60
|
+
|
61
|
+
manga
|
62
|
+
end
|
63
|
+
|
64
|
+
def slow_dl_chapters(manga)
|
65
|
+
start_dir = Dir.pwd
|
66
|
+
Dir.mkdir(manga.name) unless Dir.exist?(manga.name)
|
67
|
+
Dir.chdir(manga.name)
|
68
|
+
|
69
|
+
manga.chapters.each do |chap|
|
70
|
+
# puts "DL - #{chap.name}.."
|
71
|
+
no_time_out {chap.download}
|
72
|
+
end
|
73
|
+
|
74
|
+
File.delete(@@file_name)
|
75
|
+
Dir.chdir(start_dir)
|
76
|
+
end
|
77
|
+
|
78
|
+
def check_file_or_dir_name(name)
|
79
|
+
num = name.slice(/(\d+)(\.jpg)*\Z/, 1)
|
80
|
+
|
81
|
+
if num
|
82
|
+
while num.length < 3
|
83
|
+
num = '0' + num
|
84
|
+
end
|
85
|
+
|
86
|
+
name = name.sub(/(\d+)(\.jpg)*\Z/, num + '\2')
|
87
|
+
end
|
88
|
+
|
89
|
+
name
|
90
|
+
end
|
91
|
+
|
92
|
+
def check_dir(dir)
|
93
|
+
Dir.glob(dir + '/*').each do |d|
|
94
|
+
next if d.include?('.cbz')
|
95
|
+
yield(d)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def validate_file_or_dir_names(dir)
|
100
|
+
check_dir(dir) do |e|
|
101
|
+
f = check_file_or_dir_name(e)
|
102
|
+
|
103
|
+
unless f == e
|
104
|
+
File.rename(e, f)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
data/lib/mangdown.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'yaml'
|
5
|
+
require 'timeout'
|
6
|
+
require 'zip'
|
7
|
+
|
8
|
+
require_relative 'mangdown/tools'
|
9
|
+
require_relative 'mangdown/page'
|
10
|
+
require_relative 'mangdown/chapter'
|
11
|
+
require_relative 'mangdown/manga'
|
12
|
+
require_relative 'mangdown/popular'
|
13
|
+
require_relative 'mangdown/cbz'
|
14
|
+
require_relative 'mangdown/commands'
|
15
|
+
require_relative 'mangdown/mangdown_hash'
|
16
|
+
|
17
|
+
unless $0 == __FILE__
|
18
|
+
puts '*** Use "M.help" for commands ***'
|
19
|
+
end
|
data/scripts/cbz_dirs.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
|
4
|
+
main_dir = File.expand_path(ARGV[0] || '.')
|
5
|
+
|
6
|
+
# main_dir = Dir.pwd + '/' + main_dir.to_s unless main_dir =~ /[a-zA-Z]:[\/\\]/
|
7
|
+
|
8
|
+
Dir.chdir(main_dir)
|
9
|
+
|
10
|
+
def check_file_or_dir_name(name)
|
11
|
+
num = name.slice(/(\d+)(\.jpg)*\Z/, 1)
|
12
|
+
|
13
|
+
if num
|
14
|
+
while num.length < 3
|
15
|
+
num = '0' + num
|
16
|
+
end
|
17
|
+
|
18
|
+
name.sub(/(\d+)(\.jpg)*\Z/, num + '\2')
|
19
|
+
end
|
20
|
+
|
21
|
+
name
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_dir(dir)
|
25
|
+
Dir.glob(dir + '/*').each do |d|
|
26
|
+
next if d.include?('.cbz')
|
27
|
+
yield(d)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_file_or_dir_names(dir)
|
32
|
+
check_dir(dir) do |e|
|
33
|
+
f = check_file_or_dir_name(e)
|
34
|
+
|
35
|
+
unless f == e
|
36
|
+
File.rename(e, f)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def cbz_dir(dir)
|
42
|
+
zip_file_name = dir + '.cbz'
|
43
|
+
dir += '/' unless dir[-1] == '/'
|
44
|
+
|
45
|
+
Zip::File.open(zip_file_name, Zip::File::CREATE) do |zp|
|
46
|
+
Dir[File.join(dir, '**', '**')].each do |file|
|
47
|
+
zp.add(file.sub(dir, ''), file)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def cbz_sub_dirs(dir)
|
53
|
+
check_dir(dir) do |d|
|
54
|
+
cbz_dir(d)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if __FILE__ == $0
|
59
|
+
# Make sure all sub dirs are checked
|
60
|
+
validate_file_or_dir_names(main_dir)
|
61
|
+
# Make sure all sub dirs have files checked
|
62
|
+
check_dir(main_dir) { |d| validate_file_or_dir_names(d)}
|
63
|
+
# Create cbz files for all sub dirs
|
64
|
+
cbz_sub_dirs(main_dir)
|
65
|
+
# new line
|
66
|
+
puts
|
67
|
+
end
|
data/scripts/dl_fk_ch.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../lib/mangdown'
|
2
|
+
|
3
|
+
if ARGV.length == 3
|
4
|
+
uri, name, pages = ARGV
|
5
|
+
pages = pages.to_i
|
6
|
+
else
|
7
|
+
puts 'Wrong number of arguments'
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
Dir.chdir('D:/Downloads/Manga/FK')
|
12
|
+
|
13
|
+
fk = Mangdown::FKChapter.new(uri, name, pages)
|
14
|
+
fk.download
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'get_all_fk_page'
|
2
|
+
|
3
|
+
|
4
|
+
module Mangdown
|
5
|
+
fk_dir = 'd:/downloads/manga/FK'
|
6
|
+
|
7
|
+
Dir.chdir(fk_dir)
|
8
|
+
|
9
|
+
chps = ARGV[0].to_i
|
10
|
+
chps = 1 unless (chps > 0 and chps < 100)
|
11
|
+
|
12
|
+
# puts "chps is: #{chps}"
|
13
|
+
|
14
|
+
chapters_list = get_chapters(chps)
|
15
|
+
|
16
|
+
# puts chapters_list.length
|
17
|
+
# puts chapters_list
|
18
|
+
|
19
|
+
chapters_list.each do |ch|
|
20
|
+
fk = FKChapter.new(ch[0], ch[1], ch[2])
|
21
|
+
fk.download
|
22
|
+
end
|
23
|
+
|
24
|
+
CBZ.cbz_sub_dirs(fk_dir)
|
25
|
+
end
|
data/scripts/dl_slow.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative '../lib/mangdown'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
Dir.chdir('D:/downloads/manga')
|
5
|
+
|
6
|
+
module Mangdown
|
7
|
+
def no_time_out(tries = 3)
|
8
|
+
begin
|
9
|
+
timeout(120) do
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
rescue
|
13
|
+
if tries > 0
|
14
|
+
tries -= 1
|
15
|
+
puts "Tries left: #{tries}"
|
16
|
+
no_time_out(tries)
|
17
|
+
else
|
18
|
+
return
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def slow_get_chapters(m, bgn, nd)
|
24
|
+
@@file_name = File.expand_path("#{m.name}_temp.yml")
|
25
|
+
|
26
|
+
exists = File.exist?(@@file_name)
|
27
|
+
m_from_file = YAML.load(File.open(@@file_name, 'r').read) if exists
|
28
|
+
|
29
|
+
if m_from_file and (m_from_file.chapters.length > 0)
|
30
|
+
frst = (m.chapters_list[bgn][1] == m_from_file.chapters.first.name)
|
31
|
+
lst = (m.chapters_list[nd][1] == m_from_file.chapters.last.name)
|
32
|
+
|
33
|
+
m = m_from_file if (frst and lst)
|
34
|
+
else
|
35
|
+
m.chapters_list[bgn..nd].each_index do |i|
|
36
|
+
no_time_out {m.get_chapter(i + bgn)}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
File.open(@@file_name, 'w') {|f| f.write(m.to_yaml)}
|
41
|
+
m
|
42
|
+
end
|
43
|
+
|
44
|
+
def slow_dl_chapters(m)
|
45
|
+
Dir.mkdir(m.name) unless Dir.exist?(m.name)
|
46
|
+
Dir.chdir(m.name)
|
47
|
+
|
48
|
+
m.chapters.each do |chap|
|
49
|
+
puts "DL - #{chap.name}.."
|
50
|
+
no_time_out {chap.download}
|
51
|
+
end
|
52
|
+
|
53
|
+
File.delete(@@file_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
if __FILE__ == $0
|
60
|
+
unless ARGV.length >= 2
|
61
|
+
puts 'Wrong number of arguments'
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
|
65
|
+
uri, name = ARGV
|
66
|
+
|
67
|
+
m = Manga.new(uri, name)
|
68
|
+
|
69
|
+
bgn = ARGV[2] ? ARGV[2].to_i - 1 : 0
|
70
|
+
nd = ARGV[3] ? ARGV[3].to_i - 1 : m.chapters_list.length
|
71
|
+
|
72
|
+
m = slow_get_chapters(m, bgn, nd)
|
73
|
+
slow_dl_chapters(m)
|
74
|
+
else
|
75
|
+
puts "Mangdown module included."
|
76
|
+
puts "Ready.."
|
77
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative '../lib/mangdown'
|
2
|
+
|
3
|
+
module Mangdown
|
4
|
+
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def fk_uri(uri)
|
8
|
+
"http://www.fakku.net#{uri}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_chapters(num)
|
12
|
+
t = 0
|
13
|
+
fk_list = []
|
14
|
+
while fk_list.length < num
|
15
|
+
page = fk_uri("/page/#{t + 1}")
|
16
|
+
|
17
|
+
doc = Mangdown::Tools.get_doc(page)
|
18
|
+
|
19
|
+
doc.css('h2 a.content-title').each do |ch|
|
20
|
+
fk_list.push([ch.text, ch[:href]])
|
21
|
+
end
|
22
|
+
|
23
|
+
t += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
fk_list[0..num-1]
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_chapters(num)
|
30
|
+
fk_list = []
|
31
|
+
|
32
|
+
# t.times do |num|
|
33
|
+
|
34
|
+
# page = "http://www.fakku.net/page/#{num + 1}"
|
35
|
+
|
36
|
+
# doc = Mangdown::Tools.get_doc(page)
|
37
|
+
|
38
|
+
# fk_list = doc.css('h2 a.content-title').map {|ch| [ch.text, ch[:href]]}
|
39
|
+
# end
|
40
|
+
fk_list = find_chapters(num)
|
41
|
+
|
42
|
+
chapters_list = []
|
43
|
+
|
44
|
+
fk_list.each do |ch|
|
45
|
+
ch_uri = fk_uri(ch[1])
|
46
|
+
name = ch[0]
|
47
|
+
|
48
|
+
doc = Mangdown::Tools.get_doc(ch_uri)
|
49
|
+
|
50
|
+
# uri = fk_uri(doc.css('div.images a')[0][:href])
|
51
|
+
uri = ch_uri + '/read#page=1'
|
52
|
+
|
53
|
+
pages = doc.css('div#right div.left b')[0].text.to_i
|
54
|
+
|
55
|
+
chapters_list.push([uri, name, pages])
|
56
|
+
end
|
57
|
+
|
58
|
+
chapters_list
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
if __FILE__ == $0
|
65
|
+
t = ARGV[0].to_i
|
66
|
+
t = 1 if t <= 0
|
67
|
+
|
68
|
+
Mangdown.get_chapters(t)
|
69
|
+
else
|
70
|
+
puts "Script loaded"
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mangdown
|
4
|
+
@@uri = 'http://www.mangareader.net/bleach/537'
|
5
|
+
@@chapter_name = 'Bleach 537'
|
6
|
+
|
7
|
+
chapter = MRChapter.new( @@uri, @@chapter_name )
|
8
|
+
chapter.download
|
9
|
+
|
10
|
+
STUB_PATH = File.expand_path('../../objects/chapter.yml', __FILE__)
|
11
|
+
File.open(STUB_PATH, 'w+') do |file|
|
12
|
+
file.write(chapter.to_yaml)
|
13
|
+
end
|
14
|
+
|
15
|
+
@@fc_uri = 'http://www.fakku.net/doujinshi/pipiruma-extra-edition-dokidoki-summer-vacation/read#page=1'
|
16
|
+
@@fc_chapter_name = 'Pipiruma! Extra Edition -DokiDoki Summer Vacation-'
|
17
|
+
@@fc_num_pages = 26
|
18
|
+
|
19
|
+
f_chapter = FKChapter.new( @@fc_uri, @@fc_chapter_name, @@fc_num_pages)
|
20
|
+
f_chapter.download
|
21
|
+
|
22
|
+
FC_STUB_PATH = File.expand_path('../../objects/f_chapter.yml', __FILE__)
|
23
|
+
File.open(FC_STUB_PATH, 'w+') do |file|
|
24
|
+
file.write(f_chapter.to_yaml)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe MRChapter do
|
28
|
+
before(:each) do
|
29
|
+
print 'o'
|
30
|
+
@chapter = YAML.load(File.open(Mangdown::STUB_PATH, 'r').read)
|
31
|
+
@chapter.get_doc(@@uri)
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when chapter is initialized" do
|
35
|
+
it "should have the right chapter uri" do
|
36
|
+
expect(@chapter.uri).to eq(@@uri)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should get pages when initialized" do
|
40
|
+
expect(@chapter.pages.size).to be > 0
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have the first page at the 0 index" do
|
44
|
+
expect(@chapter.pages.first.filename).to eq('Bleach 537 - Page 1.jpg')
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have the last page at the -1 index" do
|
48
|
+
expect(@chapter.pages.last.filename).to eq('Bleach 537 - Page 21.jpg')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the functions for get_pages are run" do
|
53
|
+
it "should have the right chapter uri" do
|
54
|
+
expect(@chapter.uri).to eq(@@uri)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Probably can get rid of this, not using chapter_mark for functionality
|
58
|
+
# xit "should get the right chapter mark from a uri" do
|
59
|
+
# expect(@chapter.get_chapter_mark).to eq('Bleach 537')
|
60
|
+
# end
|
61
|
+
|
62
|
+
it "should get the right image link and filename from a uri" do
|
63
|
+
expect(@chapter.get_page).to eq(
|
64
|
+
['http://i25.mangareader.net/bleach/537/bleach-4149721.jpg',
|
65
|
+
'Bleach 537 - Page 1'])
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should get the right root from uri" do
|
69
|
+
expect(@chapter.get_root(@@uri)).to eq('http://www.mangareader.net')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should get the right link to the next page from a uri" do
|
73
|
+
expect(@chapter.get_next_uri).to eq(
|
74
|
+
'http://www.mangareader.net/bleach/537/2')
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should evaluate the expression to stop get_pages" do
|
78
|
+
next_chapter_uri = 'http://www.mangareader.net/bleach/538'
|
79
|
+
expect(@chapter.get_doc(next_chapter_uri)).not_to eq(@chapter.name)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when chapter is downloaded" do
|
84
|
+
it "should have the right chapter uri" do
|
85
|
+
expect(@chapter.uri).to eq(@@uri)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should create a directory in the current directory" do
|
89
|
+
dir = Dir.pwd
|
90
|
+
expect(Dir.glob(dir + '/*' )).to include(dir + '/' + @chapter.name)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should download all it's pages" do
|
94
|
+
dir = Dir.pwd + '/' + @chapter.name
|
95
|
+
expect(dir).to include("mangdown/#{@chapter.name}")
|
96
|
+
@chapter.pages.each do |page|
|
97
|
+
expect(Dir.glob(dir + '/*' )).to include(dir + '/' + page.filename)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe FKChapter do
|
104
|
+
before(:each) do
|
105
|
+
@f_chapter = YAML.load(File.open(Mangdown::FC_STUB_PATH, 'r').read)
|
106
|
+
@f_chapter.get_doc(@@fc_uri)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should be downloaded' do
|
110
|
+
dir = File.expand_path("../../../#{@f_chapter.name}", __FILE__)
|
111
|
+
expect(dir).to include("mangdown/#{@f_chapter.name}")
|
112
|
+
@f_chapter.pages.each do |page|
|
113
|
+
expect(Dir.glob(dir + '/*')).to include(dir + '/' + page.filename)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
module M
|
4
|
+
|
5
|
+
describe "commands" do
|
6
|
+
before(:all) do
|
7
|
+
@manga = Mangdown::Manga.new('http://www.mangareader.net/6-no-trigger',
|
8
|
+
'6 NO TRIGGER')
|
9
|
+
|
10
|
+
M.download(@manga, 1, 3)
|
11
|
+
M.cbz("./#{@manga.name}")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should find a manga with the find command" do
|
15
|
+
m = M.find('Naruto')
|
16
|
+
expect(m.first.name).to eq('Naruto')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should find a list of manga with the find command" do
|
20
|
+
m = M.find('Trigger')
|
21
|
+
expect(m.length).to be > 1
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should download a manga with the download command" do
|
25
|
+
puts Dir.pwd
|
26
|
+
chps = Dir.glob("#{Dir.pwd}/#{@manga.name}/*/")
|
27
|
+
expect(chps.length).to eq(3)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should cbz a manga with the cbz command" do
|
31
|
+
cbz_s = Dir.glob("#{Dir.pwd}/#{@manga.name}/*.cbz")
|
32
|
+
expect(cbz_s.length).to eq(3)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
module Mangdown
|
4
|
+
@@m_uri = 'http://www.mangareader.net/94/bleach.html'
|
5
|
+
@@manga_name = 'Bleach'
|
6
|
+
|
7
|
+
manga = Manga.new( @@m_uri, @@manga_name )
|
8
|
+
|
9
|
+
MANGA_STUB_PATH = File.expand_path('../../objects/manga.yml', __FILE__)
|
10
|
+
File.open(MANGA_STUB_PATH, 'w+') do |file|
|
11
|
+
file.write(manga.to_yaml)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe Manga do
|
16
|
+
before(:each) do
|
17
|
+
print '@'
|
18
|
+
@manga = YAML.load(File.open(Mangdown::MANGA_STUB_PATH, 'r').read)
|
19
|
+
@manga.get_doc(@@m_uri)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "When a manga is initialized" do
|
23
|
+
it "should have chapters" do
|
24
|
+
expect(@manga.chapters).to be_empty
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have chapters listed in chapters_list" do
|
28
|
+
expect(@manga.chapters_list).not_to be_empty
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with Bleach manga" do
|
33
|
+
it "should have more that 500 chapters" do
|
34
|
+
expect(@manga.chapters_list.length).to be > 500
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have the right first chapter" do
|
38
|
+
expect(@manga.chapters_list.first).to eq([
|
39
|
+
'http://www.mangareader.net/94-8-1/bleach/chapter-1.html',
|
40
|
+
'Bleach 1'])
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have the right 465th chapter" do
|
44
|
+
expect(@manga.chapters_list[464]).to eq([
|
45
|
+
'http://www.mangareader.net/bleach/465',
|
46
|
+
'Bleach 465'])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when a chapter is retrieved" do
|
51
|
+
before(:all) do
|
52
|
+
@manga2 = YAML.load(File.open(Mangdown::MANGA_STUB_PATH, 'r').read)
|
53
|
+
@manga2.get_chapter(0)
|
54
|
+
@mchapter = @manga2.chapters_list[0]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have a chapter in chapters" do
|
58
|
+
expect(@manga2.chapters.length).to eq(1)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should have chapter 1 in chapters" do
|
62
|
+
expect(@manga2.chapters[0].name).to eq(@mchapter[1])
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have the right chapter sub class" do
|
66
|
+
klass = Chapter
|
67
|
+
if @mchapter[0].include?('mangareader')
|
68
|
+
klass = MRChapter
|
69
|
+
elsif @mchapter[0].include?('fakku')
|
70
|
+
klass = FKChapter
|
71
|
+
end
|
72
|
+
|
73
|
+
expect(@manga2.chapters[0].class).to eq(klass)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mangdown
|
4
|
+
describe Page do
|
5
|
+
before(:all) do
|
6
|
+
@dir = Dir.pwd
|
7
|
+
@uri = 'http://i25.mangareader.net/bleach/537/bleach-4149721.jpg'
|
8
|
+
@filename = "Bleach 537 - Page 1"
|
9
|
+
@page = Page.new( @uri, @filename )
|
10
|
+
@page.download
|
11
|
+
PAGE_STUB_PATH = File.expand_path('../../objects/page.yml', __FILE__)
|
12
|
+
File.open(PAGE_STUB_PATH, 'w+') do |file|
|
13
|
+
file.write(@page.to_yaml)
|
14
|
+
end
|
15
|
+
@page2 = YAML.load(File.open(PAGE_STUB_PATH, 'r').read)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when page is downloaded" do
|
19
|
+
it "should download itself to the current directory" do
|
20
|
+
expect(Dir.glob(@dir + '/*')).to include(@dir + '/' + @page.filename)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when a page is compared with a page loaded from a .yml file" do
|
25
|
+
it "should compare with #eql?" do
|
26
|
+
expect(@page.eql?(@page2))
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not compare with ==" do
|
30
|
+
expect(!@page == @page2)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
module Mangdown
|
4
|
+
describe PopularManga do
|
5
|
+
before(:all) do
|
6
|
+
end
|
7
|
+
|
8
|
+
context "when initialized" do
|
9
|
+
before(:each) do
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with top 20" do
|
13
|
+
it "should have a manga list with top 20 mangas" do
|
14
|
+
@pop2 = PopularManga.new('http://www.mangareader.net/popular', 20)
|
15
|
+
expect(@pop2.mangas_list.length).to eq(20)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with top 50" do
|
20
|
+
it "should have a manga list with top 50 mangas" do
|
21
|
+
@pop3 = PopularManga.new('http://www.mangareader.net/popular', 50)
|
22
|
+
expect(@pop3.mangas_list.length).to eq(50)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with top 90" do
|
27
|
+
it "should have a manga list with top 90 mangas" do
|
28
|
+
@pop4 = PopularManga.new('http://www.mangareader.net/popular', 90)
|
29
|
+
expect(@pop4.mangas_list.length).to eq(90)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have an empty mangas array" do
|
34
|
+
@pop = PopularManga.new('http://www.mangareader.net/popular', 20)
|
35
|
+
expect(@pop.mangas).to be_empty
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when get_manga is called" do
|
40
|
+
it "should have 1 manga in mangas" do
|
41
|
+
@pop = PopularManga.new('http://www.mangareader.net/popular', 20)
|
42
|
+
@pop.get_manga(1)
|
43
|
+
expect(@pop.mangas.length).to eq(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should have 2 mangas in mangas" do
|
47
|
+
@pop = PopularManga.new('http://www.mangareader.net/popular', 20)
|
48
|
+
@pop.get_manga(1)
|
49
|
+
@pop.get_manga(2)
|
50
|
+
expect(@pop.mangas.length).to eq(2)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have Bleach in mangas" do
|
54
|
+
@pop = PopularManga.new('http://www.mangareader.net/popular', 20)
|
55
|
+
@pop.get_manga(1)
|
56
|
+
expect(@pop.mangas.length).to eq(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should only get manga once" do
|
60
|
+
@pop = PopularManga.new('http://www.mangareader.net/popular', 20)
|
61
|
+
@pop.get_manga(1)
|
62
|
+
@pop.get_manga(1)
|
63
|
+
expect(@pop.mangas.length).to eq(1)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative '../lib/mangdown'
|
4
|
+
|
5
|
+
dirs = ['../../Bleach 537',
|
6
|
+
'../../Pipiruma! Extra Edition -DokiDoki Summer Vacation-',
|
7
|
+
'../../6 NO TRIGGER']
|
8
|
+
|
9
|
+
dirs.each do |d|
|
10
|
+
dir = File.expand_path(d, __FILE__)
|
11
|
+
if Dir.exist?(dir)
|
12
|
+
print '*'
|
13
|
+
FileUtils.rm_rf(dir)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
path = File.expand_path('../../Bleach 537 - Page 1.jpg', __FILE__)
|
18
|
+
if File.exist?(path)
|
19
|
+
print '*'
|
20
|
+
FileUtils.rm(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
24
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
25
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
26
|
+
# loaded once.
|
27
|
+
#
|
28
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
29
|
+
RSpec.configure do |config|
|
30
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
31
|
+
config.run_all_when_everything_filtered = true
|
32
|
+
config.filter_run :focus
|
33
|
+
|
34
|
+
# Run specs in random order to surface order dependencies. If you find an
|
35
|
+
# order dependency and want to debug it, you can fix the order by providing
|
36
|
+
# the seed, which is printed after each run.
|
37
|
+
# --seed 1234
|
38
|
+
config.order = 'random'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mangdown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jphager2
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem to download Manga
|
14
|
+
email: jphager2@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/mangdown/cbz.rb
|
20
|
+
- lib/mangdown/chapter.rb
|
21
|
+
- lib/mangdown/commands.rb
|
22
|
+
- lib/mangdown/manga.rb
|
23
|
+
- lib/mangdown/mangdown_hash.rb
|
24
|
+
- lib/mangdown/page.rb
|
25
|
+
- lib/mangdown/popular.rb
|
26
|
+
- lib/mangdown/tools.rb
|
27
|
+
- lib/mangdown.rb
|
28
|
+
- scripts/cbz_dirs.rb
|
29
|
+
- scripts/dl_fk_ch.rb
|
30
|
+
- scripts/dl_fk_chps.rb
|
31
|
+
- scripts/dl_slow.rb
|
32
|
+
- scripts/get_all_fk_page.rb
|
33
|
+
- spec/mangdown/chapter_spec.rb
|
34
|
+
- spec/mangdown/commands_spec.rb
|
35
|
+
- spec/mangdown/manga_spec.rb
|
36
|
+
- spec/mangdown/page_spec.rb
|
37
|
+
- spec/mangdown/popular_spec.rb
|
38
|
+
- spec/objects/make_chapter.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
- LICENSE
|
41
|
+
- doc/help.txt
|
42
|
+
homepage:
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.0.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Downloads Manga
|
66
|
+
test_files: []
|