mangdown 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/help.txt +7 -3
- data/lib/mangdown/cbz.rb +10 -12
- data/lib/mangdown/chapter.rb +10 -9
- data/lib/mangdown/commands.rb +47 -38
- data/lib/mangdown/manga_list.rb +6 -2
- data/lib/mangdown/mangdown_hash.rb +15 -6
- data/lib/mangdown/page.rb +31 -25
- data/lib/mangdown/properties.rb +10 -1
- data/spec/lib/mangdown/cbz_spec.rb +40 -0
- data/spec/lib/mangdown/chapter_spec.rb +76 -0
- data/spec/lib/mangdown/commands_spec.rb +67 -0
- data/spec/lib/mangdown/manga_list_spec.rb +42 -0
- data/spec/mangdown/chapter_spec.rb +4 -4
- data/spec/mangdown/commands_spec.rb +28 -28
- data/spec/mangdown/manga_spec.rb +15 -15
- data/spec/mangdown/mangdown_hash_spec.rb +3 -3
- data/spec/mangdown/page_spec.rb +15 -15
- data/spec/spec_helper.rb +16 -33
- metadata +48 -3
- data/spec/objects/make_chapter.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39eae36cb18260f996d55849997b0b28bd306985
|
4
|
+
data.tar.gz: 1b097d36b0d567f0464ec06ac0913a5f8efded53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8cfb84002fed92ae7eb6ddba6a6d6e0fc73d7873f43afee0ed06324ee6975eb1988eca03c331f96322771b1d2df9a56351fb53bc85966e029bc5489fd32fc9
|
7
|
+
data.tar.gz: 89b574acbf8fa239f780307b9befbd73eb40481a7a44d637a50954c814f85cec2c14538a14254792ba392dfe7f3a2f2fa75cb670fc4e76ae1bdb75706669157f
|
data/doc/help.txt
CHANGED
@@ -3,7 +3,7 @@ Mangdown
|
|
3
3
|
|
4
4
|
Commands
|
5
5
|
|
6
|
-
M
|
6
|
+
M.find(string) - Will return an array of Mangdown::MDHash given
|
7
7
|
a string which is matched to manga names of the
|
8
8
|
3000 most popular mangas on Mangareader.
|
9
9
|
|
@@ -37,12 +37,16 @@ Commands
|
|
37
37
|
# naruto is the Mangdown::Manga object from the example above
|
38
38
|
naruto.download_to(Dir.home + '/manga', 500, 549)
|
39
39
|
|
40
|
-
M
|
40
|
+
M.cbz(path) - Will validate names of subdirectories in the path
|
41
|
+
and thier files and then Zip those subdirectories
|
42
|
+
with a .cbz extention
|
43
|
+
|
44
|
+
M.clean_up - Will delete .manga_list.yml file from the home
|
41
45
|
directory
|
42
46
|
|
43
47
|
M.clean_up
|
44
48
|
|
45
49
|
|
46
|
-
M
|
50
|
+
M.help - Will display help for commands
|
47
51
|
|
48
52
|
=======================================================================
|
data/lib/mangdown/cbz.rb
CHANGED
@@ -3,6 +3,16 @@ module Mangdown
|
|
3
3
|
extend self
|
4
4
|
extend ::Mangdown::Tools
|
5
5
|
|
6
|
+
def all(main_dir)
|
7
|
+
# Make sure all sub dirs are checked
|
8
|
+
validate_file_or_dir_names(main_dir)
|
9
|
+
# Make sure all sub dirs have files checked
|
10
|
+
check_dir(main_dir) { |dir| validate_file_or_dir_names(dir)}
|
11
|
+
# Create cbz files for all sub dirs
|
12
|
+
cbz_sub_dirs(main_dir)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
6
16
|
def cbz_dir(dir)
|
7
17
|
zip_file_name = dir + '.cbz'
|
8
18
|
dir += '/' unless dir[-1] == '/'
|
@@ -20,17 +30,6 @@ module Mangdown
|
|
20
30
|
end
|
21
31
|
end
|
22
32
|
|
23
|
-
def all(main_dir)
|
24
|
-
# Make sure all sub dirs are checked
|
25
|
-
validate_file_or_dir_names(main_dir)
|
26
|
-
# Make sure all sub dirs have files checked
|
27
|
-
check_dir(main_dir) { |dir| validate_file_or_dir_names(dir)}
|
28
|
-
# Create cbz files for all sub dirs
|
29
|
-
cbz_sub_dirs(main_dir)
|
30
|
-
# new line
|
31
|
-
puts
|
32
|
-
end
|
33
|
-
|
34
33
|
def check_dir(dir)
|
35
34
|
Dir.glob(dir + '/*').each do |file_name|
|
36
35
|
#do block on each file name, but skip .cbz files
|
@@ -56,6 +55,5 @@ module Mangdown
|
|
56
55
|
num = "0" * zeros_to_add + num
|
57
56
|
name.sub(/(\d+)(\.jpg)*\Z/, num + '\2')
|
58
57
|
end
|
59
|
-
|
60
58
|
end
|
61
59
|
end
|
data/lib/mangdown/chapter.rb
CHANGED
@@ -5,19 +5,23 @@ module Mangdown
|
|
5
5
|
attr_reader :name, :uri, :pages, :manga, :chapter
|
6
6
|
|
7
7
|
def initialize(name, uri)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
# use a valid name
|
9
|
+
@name = name.sub(/\s(\d+)$/) { |num|
|
10
|
+
' ' + num.to_i.to_s.rjust(3, '0')
|
11
|
+
}
|
12
|
+
@manga = name.slice(/(^.+)\s/, 1)
|
13
|
+
@chapter = name.slice(/\d+\z/)
|
14
|
+
@uri = Mangdown::Uri.new(uri)
|
13
15
|
@properties = Properties.new(@uri)
|
16
|
+
@pages = []
|
14
17
|
|
15
18
|
get_pages
|
19
|
+
@pages.sort_by! {|page| page.name}
|
16
20
|
end
|
17
21
|
|
18
22
|
# enumerates through pages
|
19
23
|
def each
|
20
|
-
@pages.each {|page| yield(page)
|
24
|
+
block_given? ? @pages.each { |page| yield(page) } : @pages.each
|
21
25
|
end
|
22
26
|
|
23
27
|
# explicit conversion to chapter
|
@@ -41,7 +45,6 @@ module Mangdown
|
|
41
45
|
end
|
42
46
|
|
43
47
|
private
|
44
|
-
|
45
48
|
# get page objects for all pages in a chapter
|
46
49
|
def get_pages
|
47
50
|
threads = []
|
@@ -74,7 +77,6 @@ module Mangdown
|
|
74
77
|
# mangareader chapter object
|
75
78
|
class MRChapter < Chapter
|
76
79
|
private
|
77
|
-
|
78
80
|
# get the doc for a given page number
|
79
81
|
def get_page_doc(num)
|
80
82
|
root = @properties.root
|
@@ -103,7 +105,6 @@ module Mangdown
|
|
103
105
|
# mangafox chapter object
|
104
106
|
class MFChapter < Chapter
|
105
107
|
private
|
106
|
-
|
107
108
|
# get the doc for a given page number
|
108
109
|
def get_page_doc(num)
|
109
110
|
Tools.get_doc(
|
data/lib/mangdown/commands.rb
CHANGED
@@ -4,59 +4,68 @@ module M
|
|
4
4
|
include ::Mangdown
|
5
5
|
|
6
6
|
DATA_FILE_PATH = Dir.home + '/.manga_list.yml'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
search =~ /\w/
|
11
|
-
end
|
12
|
-
|
13
|
-
# check if the data file is current
|
14
|
-
def file_current?(file)
|
15
|
-
File.exists?(file) ? File.mtime(file) > (Time.now - 604800) : false
|
16
|
-
end
|
7
|
+
HELP_FILE_PATH = File.expand_path(
|
8
|
+
'../../doc/help.txt', File.dirname(__FILE__)
|
9
|
+
)
|
17
10
|
|
18
11
|
# return a list of hash with :uri and :name of mangas found in list
|
19
12
|
def find(search)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if file_current?(DATA_FILE_PATH)
|
26
|
-
list = YAML.load(File.open(DATA_FILE_PATH, 'r').read)
|
27
|
-
else
|
28
|
-
list = MangaList.new(
|
29
|
-
'http://www.mangareader.net/alphabetical',
|
30
|
-
'http://mangafox.me/manga/'
|
31
|
-
)
|
32
|
-
|
33
|
-
File.open(DATA_FILE_PATH, 'w+') do |file|
|
34
|
-
file.write( list.to_yaml )
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
search_result = list.mangas.select do |manga|
|
39
|
-
manga[:name].downcase.include?(search.downcase)
|
40
|
-
end
|
41
|
-
|
42
|
-
search_result
|
13
|
+
validate_search(search)
|
14
|
+
current_manga_list.mangas.select { |manga|
|
15
|
+
manga[:name].downcase.include?(search.downcase)
|
16
|
+
}
|
43
17
|
end
|
44
18
|
|
45
19
|
# cbz all subdirectories in a directory
|
46
20
|
def cbz(dir)
|
47
|
-
Dir.exist?(dir) ? CBZ.all(dir) : (
|
21
|
+
Dir.exist?(dir) ? (CBZ.all(dir)) : (raise Errno::ENOENT, dir)
|
48
22
|
end
|
49
23
|
|
50
24
|
# display help file
|
51
25
|
def help
|
52
|
-
|
53
|
-
'../../doc/help.txt', File.dirname(__FILE__)
|
54
|
-
)
|
55
|
-
puts File.open(help_file, 'r').read
|
26
|
+
puts File.open(HELP_FILE_PATH, 'r').read
|
56
27
|
end
|
57
28
|
|
58
29
|
# delete data file
|
59
30
|
def clean_up
|
60
31
|
File.delete(DATA_FILE_PATH) if File.exist?(DATA_FILE_PATH)
|
61
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
# convenience method to access the data file path
|
36
|
+
def path
|
37
|
+
DATA_FILE_PATH
|
38
|
+
end
|
39
|
+
|
40
|
+
# check if the data file is current
|
41
|
+
def file_current?(f)
|
42
|
+
File.exists?(f) && File.mtime(f) > (Time.now - 604800)
|
43
|
+
end
|
44
|
+
|
45
|
+
# attempt to get the list from the data file
|
46
|
+
def data_from_file
|
47
|
+
YAML.load(File.open(path, 'r').read) if file_current?(path)
|
48
|
+
rescue Psych::SyntaxError => error
|
49
|
+
error
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# get saved current manga list, if data is less than a week old
|
54
|
+
# otherwise fetch new data and write it to the data file
|
55
|
+
def current_manga_list
|
56
|
+
data = data_from_file
|
57
|
+
return data if data.is_a? Mangdown::MangaList
|
58
|
+
|
59
|
+
MangaList.new(
|
60
|
+
'http://www.mangareader.net/alphabetical',
|
61
|
+
'http://mangafox.me/manga/'
|
62
|
+
).tap { |list| File.open(path,'w+') {|f| f.write(list.to_yaml)} }
|
63
|
+
end
|
64
|
+
|
65
|
+
# check if the search key contains letters or numbers
|
66
|
+
def validate_search(search)
|
67
|
+
unless search =~ /\w/
|
68
|
+
raise ArgumentError, "Searches must contain letters and numbers"
|
69
|
+
end
|
70
|
+
end
|
62
71
|
end
|
data/lib/mangdown/manga_list.rb
CHANGED
@@ -14,8 +14,12 @@ module Mangdown
|
|
14
14
|
# get a list of mangas from the uri
|
15
15
|
def get_mangas(uri)
|
16
16
|
properties = Properties.new(uri)
|
17
|
-
|
18
|
-
|
17
|
+
if properties.empty?
|
18
|
+
raise ArgumentError,
|
19
|
+
"Bad URI: No Properties Specified for URI <#{uri}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
doc = Tools.get_doc(uri)
|
19
23
|
# This should be put in a tool
|
20
24
|
doc.css(properties.manga_list_css_klass).each do |a|
|
21
25
|
@mangas << MDHash.new(
|
@@ -2,25 +2,34 @@ module Mangdown
|
|
2
2
|
class MDHash < ::Hash
|
3
3
|
|
4
4
|
def initialize(options = {})
|
5
|
-
self[:uri]
|
6
|
-
self[:name]
|
5
|
+
self[:uri] = options[:uri]
|
6
|
+
self[:name] = options[:name]
|
7
7
|
end
|
8
8
|
|
9
9
|
# explicit conversion to manga
|
10
10
|
def to_manga
|
11
|
-
Manga.new(
|
11
|
+
Manga.new(name, uri)
|
12
12
|
end
|
13
13
|
|
14
14
|
# explicit conversion to chapter
|
15
15
|
def to_chapter
|
16
|
-
|
17
|
-
klass.new(self[:name], self[:uri])
|
16
|
+
Properties.new(uri).chapter_klass.new(name, uri)
|
18
17
|
end
|
19
18
|
|
20
19
|
# explicit conversion to page
|
21
20
|
def to_page
|
22
|
-
Page.new(
|
21
|
+
Page.new(name, uri)
|
23
22
|
end
|
23
|
+
|
24
|
+
# name reader
|
25
|
+
def name
|
26
|
+
self[:name]
|
27
|
+
end
|
28
|
+
|
29
|
+
# uri reader
|
30
|
+
def uri
|
31
|
+
self[:uri]
|
32
|
+
end
|
24
33
|
end
|
25
34
|
end
|
26
35
|
|
data/lib/mangdown/page.rb
CHANGED
@@ -1,33 +1,39 @@
|
|
1
|
-
|
1
|
+
module Mangdown
|
2
|
+
class Page
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
include Mangdown
|
5
|
+
include Comparable
|
5
6
|
|
6
|
-
|
7
|
+
attr_reader :name, :uri
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def initialize(name, uri)
|
10
|
+
@name = name.sub(/(\s)(\d+)(\.\w+)$/) {
|
11
|
+
"#{Regexp.last_match[1]}" +
|
12
|
+
"#{Regexp.last_match[2].to_s.rjust(3, '0')}" +
|
13
|
+
"#{Regexp.last_match[3]}"
|
14
|
+
}
|
15
|
+
@uri = Mangdown::Uri.new(uri)
|
16
|
+
end
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
# space ship operator for sorting
|
19
|
+
def <=>(other)
|
20
|
+
self.name <=> other.name
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
# explicit conversion to page
|
24
|
+
def to_page
|
25
|
+
self
|
26
|
+
end
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
# downloads to specified directory
|
29
|
+
def download_to(dir = Dir.pwd)
|
30
|
+
path = dir + '/' + name
|
31
|
+
# don't download again
|
32
|
+
return if File.exist?(path)
|
33
|
+
image = open(uri).read
|
34
|
+
File.open(path, 'wb') {|file| file.write(image)}
|
35
|
+
rescue SocketError => error
|
36
|
+
STDERR.puts( "#{error.message} | #{name} | #{uri}" )
|
37
|
+
end
|
32
38
|
end
|
33
39
|
end
|
data/lib/mangdown/properties.rb
CHANGED
@@ -9,7 +9,10 @@ module Mangdown
|
|
9
9
|
case site
|
10
10
|
when /mangareader/
|
11
11
|
mangareader
|
12
|
-
when /mangapanda/
|
12
|
+
when /mangapanda/
|
13
|
+
#mangapanda is a mirror of mangareader
|
14
|
+
#that being said, I really don't think this works
|
15
|
+
#especially with @info[:root]
|
13
16
|
mangareader
|
14
17
|
when /mangafox/
|
15
18
|
mangafox
|
@@ -36,8 +39,14 @@ module Mangdown
|
|
36
39
|
@info[:reverse] = true
|
37
40
|
end
|
38
41
|
|
42
|
+
def empty?
|
43
|
+
@info.empty?
|
44
|
+
end
|
45
|
+
|
39
46
|
private
|
40
47
|
def method_missing(method, *args, &block)
|
48
|
+
# this should probably be if @info.has_key?(method)
|
49
|
+
# or more consisely @info.fetch(method) { super }
|
41
50
|
return @info[method] unless @info[method].nil?
|
42
51
|
super
|
43
52
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Mangdown::CBZ do
|
4
|
+
describe 'CBZ all' do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@fixtures_dir = File.expand_path('../../../fixtures', __FILE__)
|
8
|
+
@tmp_dir = File.expand_path('../../../../tmp', __FILE__)
|
9
|
+
@nisekoi_dir = @tmp_dir + "/Nisekoi"
|
10
|
+
FileUtils.cp_r(@fixtures_dir + '/Nisekoi', @tmp_dir)
|
11
|
+
Mangdown::CBZ.all(@nisekoi_dir)
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
FileUtils.rm_r(@nisekoi_dir, force: true)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'must have equal numbers of cbz files and chapter directories' do
|
19
|
+
chapter_count = Dir["#{@nisekoi_dir}/*/"].length
|
20
|
+
cbz_count = Dir["#{@nisekoi_dir}/*.cbz"].length
|
21
|
+
cbz_count.must_equal(chapter_count)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'cbz file names should be valid' do
|
25
|
+
filenames = Dir["#{@nisekoi_dir}/*.cbz"]
|
26
|
+
filenames.each do |name|
|
27
|
+
name.must_match /\d{3}\.cbz/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'cbz image file names should be valid' do
|
32
|
+
zips = Dir["#{@nisekoi_dir}/*.cbz"]
|
33
|
+
names = zips.flat_map {|f| Zip::File.new(f).glob('*').map(&:name)}
|
34
|
+
names.each do |name|
|
35
|
+
# Don't use #must_match, it causes an error with Zip::File
|
36
|
+
(name =~ /Page \d{3}/).wont_be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Mangdown::Chapter do
|
4
|
+
let(:download_path) { File.expand_path('../../../../tmp', __FILE__) }
|
5
|
+
let(:chapter_name) { "Dragon Ball 1" }
|
6
|
+
let(:uri) {
|
7
|
+
"http://www.mangareader.net/105-2100-1/dragon-ball/chapter-1.html"
|
8
|
+
}
|
9
|
+
|
10
|
+
before do
|
11
|
+
VCR.insert_cassette 'events', record: :new_episodes
|
12
|
+
@chapter = Mangdown::MRChapter.new(chapter_name, uri)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
VCR.eject_cassette
|
17
|
+
FileUtils.rm_r("#{download_path}/#{chapter_name}", force: true)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'new' do
|
21
|
+
it 'must return a kind of Chapter but not an instance of Chapter' do
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'to_chapter' do
|
26
|
+
it 'must return the same class of chapter' do
|
27
|
+
new_chapter = @chapter.to_chapter
|
28
|
+
new_chapter.must_be_instance_of @chapter.class
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'each' do
|
33
|
+
it 'must return an enumerator' do
|
34
|
+
@chapter.each.must_be_instance_of Enumerator
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'must iterate through each page' do
|
38
|
+
count = 0
|
39
|
+
@chapter.each do |page|
|
40
|
+
page.must_be_instance_of Mangdown::Page
|
41
|
+
count += 1
|
42
|
+
end
|
43
|
+
count.must_equal @chapter.pages.length
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'download_to' do
|
48
|
+
before do
|
49
|
+
# @times will start at 0 and end at N, where N is the number
|
50
|
+
# of specs in this describe block
|
51
|
+
@times ||= 0
|
52
|
+
@chapter.download_to(download_path) if @times == 0
|
53
|
+
@times += 1
|
54
|
+
end
|
55
|
+
|
56
|
+
after do
|
57
|
+
# @times will start at 0 and end at N, where N is the number
|
58
|
+
# of specs in this describe block
|
59
|
+
if @times == 2 && Dir.exist?("#{download_path}/#{chapter_name}")
|
60
|
+
FileUtils.rm_r(@nisekoi_dir, force: true)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'must create a subdirectory with the chapter name' do
|
65
|
+
Dir.exist?("#{download_path}/#{chapter_name}").must_equal true
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'must have page files in the sub directory' do
|
69
|
+
files = Dir["#{download_path}/#{chapter_name}/*"]
|
70
|
+
files.each do |name|
|
71
|
+
@chapter.pages.any? { |page| name =~ /#{page.name}/ }
|
72
|
+
.must_equal true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe M do
|
5
|
+
before do
|
6
|
+
VCR.insert_cassette 'events', record: :new_episodes
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
VCR.eject_cassette
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'find' do
|
14
|
+
it 'must return an array of MDHash' do
|
15
|
+
results = M.find('Naruto')
|
16
|
+
results.each do |result|
|
17
|
+
result.must_be_instance_of Mangdown::MDHash
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'must only accept good search terms' do
|
22
|
+
bad = ['@#$$#', '........', '@#%@#$%^']
|
23
|
+
good = ["666 Bats", "1 2 3", "Go! For! IT!"]
|
24
|
+
bad.each { |term| -> { M.find(term) }.must_raise ArgumentError }
|
25
|
+
good.each { |term| -> { M.find(term) }.must_be_silent }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'cbz' do
|
30
|
+
# CBZ is tested in cbz_spec.rb
|
31
|
+
it 'must fail if given a bad path' do
|
32
|
+
path = "super_bad_path/that/cant/possibly/exist!!!"
|
33
|
+
-> { M.cbz(path) }.must_raise Errno::ENOENT
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'must not fail if given a good path' do
|
37
|
+
# Before
|
38
|
+
fixtures_dir = File.expand_path('../../../fixtures', __FILE__)
|
39
|
+
tmp_dir = File.expand_path('../../../../tmp', __FILE__)
|
40
|
+
nisekoi_dir = tmp_dir + "/Nisekoi"
|
41
|
+
FileUtils.cp_r(fixtures_dir + '/Nisekoi', tmp_dir)
|
42
|
+
|
43
|
+
-> { M.cbz(nisekoi_dir) }.must_be_silent
|
44
|
+
|
45
|
+
# After
|
46
|
+
FileUtils.rm_r(nisekoi_dir, force: true)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'help' do
|
51
|
+
it "must output instructions for the command methods" do
|
52
|
+
output = SpecHelper.stdout_for { M.help }
|
53
|
+
output.length.wont_be :zero?
|
54
|
+
["M.help", "M.cbz", "M.clean_up"].each do |command|
|
55
|
+
output.must_match /#{command}/
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'clean_up' do
|
61
|
+
it "must delete the data file" do
|
62
|
+
File.open(M::DATA_FILE_PATH, 'a') { |f| f.write("HELLO!") }
|
63
|
+
M.clean_up
|
64
|
+
File.exist?(M::DATA_FILE_PATH).must_equal false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative '../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Mangdown::MangaList do
|
4
|
+
before do
|
5
|
+
VCR.insert_cassette 'events', record: :new_episodes
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
VCR.eject_cassette
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'new' do
|
13
|
+
let(:mangareader) {
|
14
|
+
Mangdown::MangaList.new('http://www.mangareader.net/alphabetical')
|
15
|
+
}
|
16
|
+
let(:mangafox) {
|
17
|
+
Mangdown::MangaList.new('http://mangafox.me/manga/')
|
18
|
+
}
|
19
|
+
let(:multiple) { Mangdown::MangaList.new(
|
20
|
+
'http://www.mangareader.net/alphabetical',
|
21
|
+
'http://mangafox.me/manga/'
|
22
|
+
) }
|
23
|
+
|
24
|
+
it 'must have a manga list with mangas (as md hashes)' do
|
25
|
+
[mangareader, mangafox].each do |type|
|
26
|
+
type.mangas.must_be_instance_of Array
|
27
|
+
type.mangas.each do |manga|
|
28
|
+
manga.must_be_instance_of Mangdown::MDHash
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'must raise an ArgumentError if given a bad url' do
|
34
|
+
-> { Mangdown::MangaList.new('garbage-url.com/bogus') }
|
35
|
+
.must_raise ArgumentError
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'must return a manga list with mangas from all input urls' do
|
39
|
+
multiple.mangas.length.must_be :>, (mangareader.mangas.length)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -6,9 +6,9 @@ module Mangdown
|
|
6
6
|
name: 'Bleach 537',
|
7
7
|
manga: 'Bleach',
|
8
8
|
chapter: '537',
|
9
|
-
|
9
|
+
)
|
10
10
|
|
11
|
-
|
11
|
+
chapter = @@chapter_hash.to_chapter
|
12
12
|
chapter.download
|
13
13
|
|
14
14
|
STUB_PATH = File.expand_path('../../objects/chapter.yml', __FILE__)
|
@@ -49,9 +49,9 @@ module Mangdown
|
|
49
49
|
name: 'Kitsune no Yomeiri 1',
|
50
50
|
manga: 'Kitsune no Yomeiri',
|
51
51
|
chapter: 1,
|
52
|
-
|
52
|
+
)
|
53
53
|
|
54
|
-
|
54
|
+
chapter = hash.to_chapter
|
55
55
|
|
56
56
|
expect(chapter.pages).not_to be_empty
|
57
57
|
end
|
@@ -3,32 +3,32 @@ require 'spec_helper.rb'
|
|
3
3
|
module M
|
4
4
|
|
5
5
|
describe "commands" do
|
6
|
-
|
6
|
+
before(:all) do
|
7
7
|
hash = MDHash.new(
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
uri: 'http://www.mangareader.net/6-no-trigger',
|
9
|
+
name: '6 no Trigger'
|
10
|
+
)
|
11
11
|
@manga = hash.to_manga
|
12
12
|
|
13
13
|
hash = MDHash.new(
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
uri: 'http://mangafox.me/manga/naruto/',
|
15
|
+
name: 'Naruto'
|
16
|
+
)
|
17
17
|
@mf_manga = hash.to_manga
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
M.download(@manga, 1, 3)
|
20
|
+
M.cbz("./#{@manga.name}")
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
it "should find a manga with the find command" do
|
24
|
+
m = M.find('Naruto')
|
25
|
+
expect(m.first[:name]).to eq('Naruto')
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
it "should find a list of manga with the find command" do
|
29
|
+
m = M.find('Trigger')
|
30
|
+
expect(m.length).to be > 1
|
31
|
+
end
|
32
32
|
|
33
33
|
it "should find a manga from MF" do
|
34
34
|
m = M.find('naruto')
|
@@ -48,19 +48,19 @@ module M
|
|
48
48
|
|
49
49
|
it "should download a manga from MF" do
|
50
50
|
dir = Dir.pwd
|
51
|
-
|
51
|
+
#@mf_manga.remove_chapters
|
52
52
|
M.download(@mf_manga, 500, 501)
|
53
53
|
expect(Dir.glob(dir + "/#{@mf_manga.name}/*").length).to eq(2)
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
it "should download a manga with the download command" do
|
57
|
+
chps = Dir.glob("#{Dir.pwd}/#{@manga.name}/*/")
|
58
|
+
expect(chps.length).to eq(3)
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
it "should cbz a manga with the cbz command" do
|
62
|
+
cbz_s = Dir.glob("#{Dir.pwd}/#{@manga.name}/*.cbz")
|
63
|
+
expect(cbz_s.length).to eq(3)
|
64
|
+
end
|
65
|
+
end
|
66
66
|
end
|
data/spec/mangdown/manga_spec.rb
CHANGED
@@ -4,9 +4,9 @@ module Mangdown
|
|
4
4
|
@@manga_hash = MDHash.new(
|
5
5
|
uri: 'http://www.mangareader.net/94/bleach.html',
|
6
6
|
name: 'Bleach'
|
7
|
-
|
7
|
+
)
|
8
8
|
|
9
|
-
|
9
|
+
manga = @@manga_hash.to_manga
|
10
10
|
|
11
11
|
MANGA_STUB_PATH = File.expand_path('../../objects/manga.yml',
|
12
12
|
__FILE__)
|
@@ -34,9 +34,9 @@ module Mangdown
|
|
34
34
|
context "as a MangaFox manga" do
|
35
35
|
it "should have chapters" do
|
36
36
|
hash = MDHash.new(
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
uri: 'http://mangafox.me/manga/masca_the_beginning/',
|
38
|
+
name: 'Masca: The Beginning'
|
39
|
+
)
|
40
40
|
manga = hash.to_manga
|
41
41
|
expect(manga.chapters_list).not_to be_empty
|
42
42
|
end
|
@@ -65,10 +65,10 @@ module Mangdown
|
|
65
65
|
|
66
66
|
context "when a chapter is retrieved" do
|
67
67
|
before(:all) do
|
68
|
-
|
68
|
+
@manga2 = YAML.load(File.open(
|
69
69
|
Mangdown::MANGA_STUB_PATH, 'r').read)
|
70
70
|
@manga2.get_chapter(0)
|
71
|
-
|
71
|
+
@mchapter = @manga2.chapters_list[0]
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should have a chapter in chapters" do
|
@@ -79,14 +79,14 @@ module Mangdown
|
|
79
79
|
expect(@manga2.chapters[0].name).to eq(@mchapter[:name])
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
it "should have the right chapter sub class" do
|
83
|
+
klass = Chapter
|
84
|
+
if @mchapter[:uri].include?('mangareader')
|
85
|
+
klass = MRChapter
|
86
|
+
end
|
87
|
+
|
88
|
+
expect(@manga2.chapters[0].class).to eq(klass)
|
89
|
+
end
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -5,9 +5,9 @@ module Mangdown
|
|
5
5
|
describe MDHash do
|
6
6
|
before(:all) do
|
7
7
|
@hash = MDHash.new(
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
uri: 'http://www.mangareader.net/103/one-piece.html',
|
9
|
+
name: 'One Piece'
|
10
|
+
)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should get a manga object from get_manga" do
|
data/spec/mangdown/page_spec.rb
CHANGED
@@ -2,22 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Mangdown
|
4
4
|
describe Page do
|
5
|
-
|
6
|
-
|
5
|
+
before(:all) do
|
6
|
+
@dir = Dir.pwd
|
7
7
|
@page_hash = MDHash.new(
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
uri: 'http://i25.mangareader.net/bleach/537/bleach-4149721.jpg',
|
9
|
+
name: "Bleach 537 - Page 1"
|
10
|
+
)
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
@page = @page_hash.to_page
|
13
|
+
@page.download
|
14
14
|
PAGE_STUB_PATH = File.expand_path('../../objects/page.yml',
|
15
15
|
__FILE__)
|
16
16
|
|
17
17
|
File.open(PAGE_STUB_PATH, 'w+') do |file|
|
18
18
|
file.write(@page.to_yaml)
|
19
19
|
end
|
20
|
-
|
20
|
+
@page2 = YAML.load(File.open(PAGE_STUB_PATH, 'r').read)
|
21
21
|
end
|
22
22
|
|
23
23
|
context "when page is downloaded" do
|
@@ -26,14 +26,14 @@ module Mangdown
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
context "when a page is compared with a page loaded from a .yml file" do
|
30
30
|
it "should compare with #eql?" do
|
31
|
-
|
32
|
-
|
31
|
+
expect(@page.eql?(@page2))
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
it "should not compare with ==" do
|
35
|
+
expect(!@page == @page2)
|
36
|
+
end
|
37
|
+
end
|
38
38
|
end
|
39
39
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,39 +1,22 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'yaml'
|
3
1
|
require_relative '../lib/mangdown'
|
4
2
|
|
5
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'webmock/minitest'
|
5
|
+
require 'vcr'
|
6
|
+
require 'fileutils'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
dir = File.expand_path(d, __FILE__)
|
11
|
-
if Dir.exist?(dir)
|
12
|
-
print '*'
|
13
|
-
FileUtils.rm_rf(dir)
|
14
|
-
end
|
8
|
+
VCR.configure do |c|
|
9
|
+
c.cassette_library_dir = 'spec/fixtures/cpo_cassettes'
|
10
|
+
c.hook_into :webmock
|
15
11
|
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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'
|
13
|
+
module SpecHelper
|
14
|
+
extend self
|
15
|
+
def stdout_for
|
16
|
+
out, temp = StringIO.new, $stdout
|
17
|
+
$stdout = out
|
18
|
+
yield
|
19
|
+
out, $stdout = $stdout, temp
|
20
|
+
out.rewind and out.read
|
21
|
+
end
|
39
22
|
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.9.
|
4
|
+
version: 0.9.3
|
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-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -122,6 +122,48 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rake
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
125
167
|
description: A gem to download Manga, (pg integration in dev)
|
126
168
|
email: jphager2@gmail.com
|
127
169
|
executables: []
|
@@ -152,6 +194,10 @@ files:
|
|
152
194
|
- models/manga.rb
|
153
195
|
- models/page.rb
|
154
196
|
- models/site.rb
|
197
|
+
- spec/lib/mangdown/cbz_spec.rb
|
198
|
+
- spec/lib/mangdown/chapter_spec.rb
|
199
|
+
- spec/lib/mangdown/commands_spec.rb
|
200
|
+
- spec/lib/mangdown/manga_list_spec.rb
|
155
201
|
- spec/mangdown/chapter_spec.rb
|
156
202
|
- spec/mangdown/commands_spec.rb
|
157
203
|
- spec/mangdown/manga_list_spec.rb
|
@@ -160,7 +206,6 @@ files:
|
|
160
206
|
- spec/mangdown/page_spec.rb
|
161
207
|
- spec/mangdown/popular_spec.rb
|
162
208
|
- spec/mangdown/tools_spec.rb
|
163
|
-
- spec/objects/make_chapter.rb
|
164
209
|
- spec/spec_helper.rb
|
165
210
|
homepage: https://github.com/jphager2/mangdown
|
166
211
|
licenses:
|