mangdown 0.7.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3601e69092554b4994957c59e79fde24ed0b5014
4
- data.tar.gz: eab931deff079ce8f0aa89636c3ba089733b6faa
3
+ metadata.gz: 2661378fbd595b26a9bf3287f4ac62998aa6839c
4
+ data.tar.gz: 020610efc7afb039d77415d18ac5f5a232541ca5
5
5
  SHA512:
6
- metadata.gz: 4489b2f82b82f1fcfe40462a28a900eca489bb09ffbf7e482f179d97c1b7e7c6a778c8f8255c5eabb163d10ad33d1aa5da484d759c01bd2aa4357bee3d08f4fc
7
- data.tar.gz: 67923d472168c32a8271f428039e9e8aaf726790d17f0a788eaf91bbd7c98162388ab44235199eb7b9d026a98700e6dac1dc6c4347f5f82180e4f34720f7df79
6
+ metadata.gz: 6ce635544cdd44bdfa0c6b8bb39cd296ecac6e356130440ceceeb5c86a0b617496ac5b66cc0a027e64f20934515dbc6b7da37e7dc314b7e56ef950c5f0be4c27
7
+ data.tar.gz: d96dbacc58a1388b8b3a57bf89538af380b2920100dc5453d61fc8402b3653f005f2fab566f506a2a24a78b531737e36983cbb97d4b0826e1bf74c488742c001
@@ -1,33 +1,39 @@
1
- ==============================================================================
1
+ ========================================================================
2
2
  Mangdown
3
3
 
4
4
  Commands
5
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.
6
+ M#find(string) - Will return an array of Mangdown::MDHash given
7
+ a string which is matched to manga names of the
8
+ 3000 most popular mangas on Mangareader.
9
9
 
10
10
  results = M.find('Naruto')
11
11
 
12
12
 
13
13
 
14
- *** Use Mangdown::MDHash#get_manga to get a Mangdown::Manga object ***
14
+ **Use Mangdown::MDHash#get_manga to get a Mangdown::Manga object**
15
15
 
16
16
  naruto = results[0].get_manga
17
17
 
18
18
 
19
19
 
20
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.
21
+ - Will download a manga (Mangdown::Manga object)
22
+ from the first int (index of the first chapter)
23
+ to the last int (index of the last chapter) to
24
+ a subdirectory named #{manga.name}". If no
25
+ indexes are given, all chapters are downloaded.
26
26
 
27
27
  M.download(naruto, 500, 549)
28
28
 
29
+
30
+
31
+ M#clean_up - Will delete .manga_list.yml file from the home
32
+ directory
33
+
34
+ M.clean_up
29
35
 
30
36
 
31
37
  M#help - Will display help for commands
32
38
 
33
- ==============================================================================
39
+ =======================================================================
@@ -10,6 +10,7 @@ require_relative 'mangdown/page'
10
10
  require_relative 'mangdown/chapter'
11
11
  require_relative 'mangdown/manga'
12
12
  require_relative 'mangdown/popular'
13
+ require_relative 'mangdown/manga_list.rb'
13
14
  require_relative 'mangdown/cbz'
14
15
  require_relative 'mangdown/commands'
15
16
  require_relative 'mangdown/mangdown_hash'
@@ -1,22 +1,34 @@
1
1
  module Mangdown
2
2
  class Chapter
3
3
 
4
- attr_reader :name, :pages, :uri
5
-
6
- def initialize( uri, name )
7
- @uri = uri
8
- @name = name
4
+ attr_reader :pages
5
+
6
+ # initialize with MDHash and only have @info[:key]
7
+ def initialize(info)
8
+ @info = info
9
9
  @pages = []
10
10
 
11
11
  get_pages
12
12
  end
13
13
 
14
+ # reader method for uri
15
+ def uri
16
+ @info[:uri]
17
+ end
18
+
19
+ # reader method for name
20
+ def name
21
+ @info[:name]
22
+ end
23
+
14
24
  # download should be in its own module
25
+ # and the start_dir is sandwich code and should be moved and
26
+ # passed a block
15
27
  def download
16
28
  start_dir = Dir.pwd
17
29
 
18
- Dir.mkdir(@name) unless Dir.exists?(@name)
19
- Dir.chdir(@name)
30
+ Dir.mkdir(@info[:name]) unless Dir.exists?(@info[:name])
31
+ Dir.chdir(@info[:name])
20
32
 
21
33
  @pages.each {|page| page.download}
22
34
 
@@ -25,14 +37,14 @@ module Mangdown
25
37
 
26
38
  private
27
39
  def get_pages
28
- uri = @uri
40
+ uri = @info[:uri]
29
41
  doc = ::Mangdown::Tools.get_doc(uri)
30
42
 
31
43
  get_num_pages(doc).times do
32
- page_uri, page_name = get_page(doc)
44
+ page = get_page(doc)
33
45
  uri = get_next_uri(doc)
34
46
 
35
- @pages << Page.new( page_uri, page_name )
47
+ @pages << Page.new(page)
36
48
  doc = ::Mangdown::Tools.get_doc(uri)
37
49
  end
38
50
  end
@@ -42,12 +54,15 @@ module Mangdown
42
54
  private
43
55
  def get_page(doc)
44
56
  image = doc.css('img')[0]
45
- [image['src'], image['alt']]
57
+
58
+ hash = MDHash.new
59
+ hash[:uri], hash[:name] = image['src'], (image['alt'] + ".jpg")
60
+ hash
46
61
  end
47
62
 
48
63
  def get_next_uri(doc)
49
64
  #root url + the href of the link to the next page
50
- ::Mangdown::Tools.get_root(@uri) +
65
+ ::Mangdown::Tools.get_root(@info[:uri]) +
51
66
  doc.css('div#imgholder a')[0]['href']
52
67
  end
53
68
 
@@ -56,4 +71,26 @@ module Mangdown
56
71
  doc.css('select')[1].children.length
57
72
  end
58
73
  end
74
+
75
+ class MFChapter < Chapter
76
+ private
77
+ def get_page(doc)
78
+ image = doc.css('img')[0]
79
+
80
+ hash = MDHash.new
81
+ hash[:uri] = image[:src]
82
+ hash[:name] = image[:src].sub(/.+\//, '')
83
+ hash
84
+ end
85
+
86
+
87
+ def get_next_uri(doc)
88
+ root = @info[:uri].slice(/.+\//)
89
+ root + doc.css('div#viewer a')[0][:href]
90
+ end
91
+
92
+ def get_num_pages(doc)
93
+ doc.css('select')[1].children.length - 1
94
+ end
95
+ end
59
96
  end
@@ -8,6 +8,10 @@ module M
8
8
  search =~ /\w/
9
9
  end
10
10
 
11
+ def file_path
12
+ Dir.home + '/.manga_list.yml'
13
+ end
14
+
11
15
  #returns a list of hash with :uri and :name of mangas found in @@list
12
16
  def find(search)
13
17
  unless valid_search?(search)
@@ -15,34 +19,44 @@ module M
15
19
  return []
16
20
  end
17
21
 
18
- # change this: Check for yml file with popular list
19
- # if it exists, then check if it was created this week
20
- # if it wasn't get a new list
21
- # if the yaml file doesn't exist get a new list
22
- # write the new list to the yaml file
23
- @@list ||= PopularManga.new(
24
- 'http://www.mangareader.net/popular', 3000)
25
-
26
- search_result = @@list.mangas_list.select do |manga|
27
- manga[:name].downcase.include?(search.downcase)
28
- end
22
+ # Previously, popular manga was used for find, but there is a
23
+ # much better way to do it
24
+ # PopularManga.new('http://www.mangareader.net/popular', 3000)
29
25
 
30
- =begin
31
- search_result.collect! do |manga|
32
- h = MDHash.new
33
- h[:uri], h[:name] = manga[:uri], manga[:name]
34
- h
26
+ if File.exist?(file_path)
27
+ file_current = File.mtime(file_path) > (Time.now - 60*60*24*7)
28
+ end
29
+
30
+ if file_current
31
+ @@list = YAML.load(File.open(file_path, 'r').read)
32
+ else
33
+ @@list = MangaList.new(
34
+ 'http://www.mangareader.net/alphabetical',
35
+ 'http://mangafox.me/manga/'
36
+ )
37
+
38
+ File.open(file_path, 'w+') do |f|
39
+ f.write( @@list.to_yaml )
40
+ end
35
41
  end
36
- =end
37
42
 
43
+ search_result = @@list.mangas.select do |manga|
44
+ manga[:name].downcase.include?(search.downcase)
45
+ end
46
+
38
47
  puts "Could not find manga" if search_result.empty?
39
48
 
40
49
  search_result
41
50
  end
42
51
 
43
52
  def download(manga, first_chapter = 0, last_chapter = -1)
44
- chapters = slow_get_chapters(manga, first_chapter, last_chapter)
45
- slow_dl_chapters(chapters)
53
+ if manga.class == MDHash
54
+ manga = Manga.new(manga)
55
+ end
56
+
57
+ chapters = ::Mangdown::Tools.slow_get_chapters(
58
+ manga, first_chapter, last_chapter)
59
+ ::Mangdown::Tools.slow_dl_chapters(chapters)
46
60
  end
47
61
 
48
62
  def cbz(dir)
@@ -54,4 +68,8 @@ module M
54
68
  File.dirname(__FILE__))
55
69
  puts File.open(help_file, 'r').read
56
70
  end
71
+
72
+ def clean_up
73
+ File.delete(file_path) if File.exist?(file_path)
74
+ end
57
75
  end
@@ -2,11 +2,11 @@ module Mangdown
2
2
  class Manga
3
3
  include ::Mangdown::Tools
4
4
 
5
- attr_reader :chapters, :chapters_list, :name, :uri
5
+ attr_reader :chapters, :chapters_list
6
6
 
7
- def initialize(uri, name)
8
- @uri = uri
9
- @name = name
7
+ #initialize only use @info[:key]
8
+ def initialize(info)
9
+ @info = info
10
10
 
11
11
  #Keeping these chapter objects in memory could be expensive
12
12
  @chapters = []
@@ -15,30 +15,69 @@ module Mangdown
15
15
  get_chapters_list
16
16
  end
17
17
 
18
+ # reader method for uri
19
+ def uri
20
+ @info[:uri]
21
+ end
22
+
23
+ # reader method for name
24
+ def name
25
+ @info[:name]
26
+ end
27
+
18
28
  def get_chapters_list
19
- doc = ::Mangdown::Tools.get_doc(@uri)
20
- root = ::Mangdown::Tools.get_root(@uri)
29
+ doc = ::Mangdown::Tools.get_doc(@info[:uri])
30
+ root = ::Mangdown::Tools.get_root(@info[:uri])
21
31
 
22
32
  #get the link with chapter name and uri
23
- doc.css('div#chapterlist td a').each do |chapter|
24
- @chapters_list << ([root + chapter['href'], chapter.text])
33
+ doc.css(css_klass(root)).each do |chapter|
34
+ hash = MDHash.new
35
+ hash[:uri] = (root + chapter[:href].sub(root, ''))
36
+ hash[:name] = chapter.text
37
+ @chapters_list << hash
38
+ end
39
+
40
+ if root =~ /mangafox/
41
+ @chapters_list.reverse!
25
42
  end
26
43
  end
27
44
 
45
+ def css_klass(site)
46
+ case site
47
+ when /mangareader/
48
+ 'div#chapterlist td a'
49
+ when /mangafox/
50
+ 'a.tips'
51
+ else
52
+ nil
53
+ end
54
+ end
55
+
56
+ # chapter is an MDHash
57
+ def chapter_found(chapter)
58
+ @chapters.find do |chp|
59
+ (chp.name == chapter[:name]) or (chp.uri == chapter[:uri])
60
+ end
61
+ end
62
+
28
63
  def get_chapter(index)
29
64
 
30
- root = ::Mangdown::Tools.get_root(@uri)
31
- uri, name = @chapters_list[index]
32
-
33
- unless @chapters.find {|chp| (chp.name == name) or (chp.uri == uri)}
34
- # this is far from ideal
35
- chapter_klass = if root.include?('mangareader')
36
- MRChapter
65
+ root = ::Mangdown::Tools.get_root(@info[:uri])
66
+ chapter = @chapters_list[index]
67
+
68
+ unless chapter_found(chapter)
69
+ # this should be put in a module the case is used in
70
+ # almost every class
71
+ chapter_klass = case root
72
+ when /mangareader/
73
+ ::Mangdown::MRChapter
74
+ when /mangafox/
75
+ ::Mangdown::MFChapter
37
76
  else
38
- NO_Chapter
77
+ return :no_chapter
39
78
  end
40
79
 
41
- @chapters << chapter_klass.new(uri, name)
80
+ @chapters << chapter_klass.new(chapter)
42
81
  else
43
82
  puts "This chapter has already been added"
44
83
  end
@@ -0,0 +1,47 @@
1
+ module Mangdown
2
+ class MangaList
3
+
4
+ attr_reader :mangas
5
+
6
+ def initialize(*uri)
7
+ @uri = uri
8
+ @mangas = []
9
+
10
+ @uri.each {|uri| get_mangas(uri)}
11
+ end
12
+
13
+ def get_mangas(uri)
14
+ doc = ::Mangdown::Tools.get_doc(uri)
15
+ root = ::Mangdown::Tools.get_root(uri)
16
+
17
+
18
+ # This should be put in a tool
19
+ doc.css(css_klass(root)).each do |a|
20
+ hash = MDHash.new
21
+ #hot fix
22
+ url = case root
23
+ when /mangareader/
24
+ root + a[:href]
25
+ when /mangafox/
26
+ a[:href]
27
+ else
28
+ nil
29
+ end
30
+
31
+ hash[:uri], hash[:name] = url, a.text
32
+ @mangas << hash
33
+ end
34
+ end
35
+
36
+ def css_klass(site)
37
+ case site
38
+ when /mangareader/
39
+ 'ul.series_alpha li a'
40
+ when /mangafox/
41
+ 'div.manga_list li a'
42
+ else
43
+ nil
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,7 +1,7 @@
1
1
  module Mangdown
2
2
  class MDHash < ::Hash
3
3
  def get_manga
4
- Manga.new(self[:uri], self[:name])
4
+ Manga.new(self)
5
5
  end
6
6
  end
7
7
  end
@@ -1,20 +1,29 @@
1
1
  module Mangdown
2
2
  class Page
3
- attr_reader :filename, :uri
4
3
 
5
- def initialize( uri, filename )
4
+ attr_reader :info
6
5
 
7
- # this will probably become a problem when adding different
8
- # Manga sites which may use different file types than .jpg
9
- @filename = filename + '.jpg'
10
- @uri = uri
6
+ # like chapter and manga, should initialize with MDHash, and use
7
+ # @info[:key]
8
+ def initialize(info)
9
+ @info = info
10
+ end
11
+
12
+ def filename
13
+ @info[:name]
14
+ end
15
+
16
+ def uri
17
+ @info[:uri]
11
18
  end
12
19
 
13
20
  # this method should probably be moved somewhere else because
14
21
  # pages, chapters and mangas can all be "downloaded"
15
22
  def download
16
- File.open(@filename, 'wb') do |file|
17
- file.write(open(URI.encode(@uri, '[]')).read)
23
+ unless File.exist?(@info[:name])
24
+ File.open(@info[:name], 'wb') do |file|
25
+ file.write(open(URI.encode(@info[:uri], '[]')).read)
26
+ end
18
27
  end
19
28
  end
20
29
  end
@@ -16,15 +16,14 @@ module Mangdown
16
16
  get_mangas_list
17
17
  end
18
18
 
19
- #Depreciated
19
+ #Depreciated use MDHash.get_manga
20
20
  def get_manga(number)
21
21
  puts "This has been depreciated, don't use PopularManga @mangas!"
22
- uri = @mangas_list[number - 1][:uri]
23
- name = @mangas_list[number - 1][:name]
22
+ manga = @mangas_list[number - 1]
24
23
 
25
- unless @mangas.find {|manga| (manga.name == name) or
26
- (manga.uri == uri)}
27
- @mangas << Manga.new( uri, name )
24
+ unless @mangas.find {|mnga| (mnga.name == manga[:name]) or
25
+ (mnga.uri == manga[:uri])}
26
+ @mangas << Manga.new(manga)
28
27
  else
29
28
  puts "This manga has already been added.."
30
29
  end
@@ -2,6 +2,16 @@ module Mangdown
2
2
  module Tools
3
3
  extend self
4
4
 
5
+ def special?(klass)
6
+ klasses = [Manga, Chapter, Page, MRChapter, MFChapter]
7
+
8
+ if klasses.find(self.class)
9
+ true
10
+ else
11
+ false
12
+ end
13
+ end
14
+
5
15
  def get_doc(uri)
6
16
  @doc = ::Nokogiri::HTML(open(uri))
7
17
  end
@@ -11,30 +21,41 @@ module Mangdown
11
21
  end
12
22
 
13
23
  def to_s
14
- "<#{self.class}::#{self.object_id} : #{@name} : #{@uri}>"
24
+ if special?(self.class)
25
+ "<#{self.class}::#{self.object_id} : #{@name} : #{@uri}>"
26
+ else
27
+ super
28
+ end
15
29
  end
16
30
 
17
31
  def eql?(other)
18
- (@name == other.name) and (@uri == other.uri)
32
+ if special?(self.class)
33
+ (self.name == other.name) and (self.uri == other.uri)
34
+ else
35
+ super
36
+ end
19
37
  end
20
38
 
21
39
  def ==(other)
22
- puts 'You may want to use :eql?'
40
+ if special?(self.class)
41
+ puts 'You may want to use eql?'
42
+ end
43
+
23
44
  super
24
45
  end
25
46
 
26
- def no_time_out(tries = 3)
47
+ def no_time_out(tries = 3, &block)
48
+ tries -= 1
27
49
  begin
28
50
  timeout(120) do
29
51
  yield
30
52
  end
31
- rescue
32
- if tries > 0
33
- tries -= 1
53
+ rescue
54
+ if tries >= 0
34
55
  puts "Tries left: #{tries}"
35
- no_time_out(tries)
56
+ no_time_out(tries, &block)
36
57
  else
37
- return
58
+ return :timed_out
38
59
  end
39
60
  end
40
61
  end
@@ -42,17 +63,17 @@ module Mangdown
42
63
  def slow_get_chapters(manga, bgn, nd)
43
64
  @@file_name = File.expand_path("#{manga.name}_temp.yml")
44
65
 
45
- exists = File.exist?(@@file_name)
46
-
47
- if exists
66
+ # get Manga object from file if it exists
67
+ if File.exist?(@@file_name)
48
68
  manga_from_file = YAML.load(File.open(@@file_name, 'r').read)
49
69
  end
50
70
 
51
71
  if manga_from_file and (manga_from_file.chapters.length > 0)
52
- frst = (manga.chapters_list[bgn][1] ==
72
+ frst = (manga.chapters_list[bgn][:name] ==
53
73
  manga_from_file.chapters.first.name)
54
- lst = (manga.chapters_list[nd][1] ==
74
+ lst = (manga.chapters_list[nd][:name] ==
55
75
  manga_from_file.chapters.last.name)
76
+ # check if this is the right temp file
56
77
  manga = manga_from_file if (frst and lst)
57
78
  else
58
79
  manga.chapters_list[bgn..nd].each_index do |i|
@@ -70,9 +91,12 @@ module Mangdown
70
91
  Dir.mkdir(manga.name) unless Dir.exist?(manga.name)
71
92
  Dir.chdir(manga.name)
72
93
 
94
+ manga_start_dir = Dir.pwd
73
95
  manga.chapters.each do |chap|
74
- # puts "DL - #{chap.name}.."
75
- no_time_out {chap.download}
96
+ no_time_out do
97
+ Dir.chdir(manga_start_dir)
98
+ chap.download
99
+ end
76
100
  end
77
101
 
78
102
  File.delete(@@file_name)
@@ -80,6 +104,9 @@ module Mangdown
80
104
  end
81
105
 
82
106
  def check_file_or_dir_name(name)
107
+
108
+ # slice the last number in the file or directory name,
109
+ # which will be either the page number or the chapter number
83
110
  num = name.slice(/(\d+)(\.jpg)*\Z/, 1)
84
111
 
85
112
  if num
@@ -94,18 +121,19 @@ module Mangdown
94
121
  end
95
122
 
96
123
  def check_dir(dir)
97
- Dir.glob(dir + '/*').each do |d|
98
- next if d.include?('.cbz')
99
- yield(d)
124
+ Dir.glob(dir + '/*').each do |file_name|
125
+ #do block on each file name, but skip .cbz files
126
+ next if file_name.include?('.cbz')
127
+ yield(file_name)
100
128
  end
101
129
  end
102
130
 
103
131
  def validate_file_or_dir_names(dir)
104
- check_dir(dir) do |e|
105
- f = check_file_or_dir_name(e)
132
+ check_dir(dir) do |file_name|
133
+ checked_name = check_file_or_dir_name(file_name)
106
134
 
107
- unless f == e
108
- File.rename(e, f)
135
+ unless file_name == checked_name
136
+ File.rename(file_name, checked_name)
109
137
  end
110
138
  end
111
139
  end
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Mangdown
4
- @@uri = 'http://www.mangareader.net/bleach/537'
5
- @@chapter_name = 'Bleach 537'
4
+ @@chapter_hash = MDHash.new
5
+ @@chapter_hash[:uri] = 'http://www.mangareader.net/bleach/537'
6
+ @@chapter_hash[:name] = 'Bleach 537'
6
7
 
7
- chapter = MRChapter.new( @@uri, @@chapter_name )
8
+ chapter = MRChapter.new(@@chapter_hash)
8
9
  chapter.download
9
10
 
10
11
  STUB_PATH = File.expand_path('../../objects/chapter.yml', __FILE__)
@@ -21,7 +22,7 @@ module Mangdown
21
22
  context "when chapter is initialized" do
22
23
  # sanity check, not necessary
23
24
  it "should have the right chapter uri" do
24
- expect(@chapter.uri).to eq(@@uri)
25
+ expect(@chapter.uri).to eq(@@chapter_hash[:uri])
25
26
  end
26
27
 
27
28
  it "should get pages when initialized" do
@@ -37,6 +38,19 @@ module Mangdown
37
38
  expect(@chapter.pages.last.filename).to eq(
38
39
  'Bleach 537 - Page 21.jpg')
39
40
  end
41
+
42
+ context "as a MFChapter" do
43
+ it "should have pages" do
44
+ hash = MDHash.new
45
+ hash[:uri] =
46
+ 'http://mangafox.me/manga/kitsune_no_yomeiri/v01/c001/1.html'
47
+ hash[:name] = 'Kitsune no Yomeiri 1'
48
+
49
+ chapter = MFChapter.new(hash)
50
+
51
+ expect(chapter.pages).not_to be_empty
52
+ end
53
+ end
40
54
  end
41
55
 
42
56
  # Move these to Tools spec
@@ -61,13 +75,15 @@ module Mangdown
61
75
  context "when chapter is downloaded" do
62
76
  it "should have a sub directory in the current directory" do
63
77
  dir = Dir.pwd
64
- expect(Dir.glob(dir + '/*' )).to include(dir + '/' +
65
- @chapter.name)
78
+ chapter_path = dir + '/' + @chapter.name
79
+
80
+ expect(Dir.glob(dir + '/*' )).to include(chapter_path)
66
81
  end
67
82
 
68
83
  it "should download all it's pages" do
69
84
  dir = Dir.pwd + '/' + @chapter.name
70
85
  # expect(dir).to include("mangdown/#{@chapter.name}")
86
+
71
87
  pages_in_dir = Dir.glob(dir + '/*.jpg').length
72
88
  expect(pages_in_dir).to eq(@chapter.pages.length)
73
89
  #@chapter.pages.each do |page|
@@ -4,10 +4,17 @@ module M
4
4
 
5
5
  describe "commands" do
6
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)
7
+ hash = MDHash.new
8
+ hash[:uri] = 'http://www.mangareader.net/6-no-trigger'
9
+ hash[:name] = '6 no Trigger'
10
+ @manga = Manga.new(hash)
11
+
12
+ hash = MDHash.new
13
+ hash[:uri] = 'http://mangafox.me/manga/naruto/'
14
+ hash[:name] = 'Naruto'
15
+ @mf_manga = Manga.new(hash)
16
+
17
+ M.download(@manga, 1, 3)
11
18
  M.cbz("./#{@manga.name}")
12
19
  end
13
20
 
@@ -21,8 +28,29 @@ module M
21
28
  expect(m.length).to be > 1
22
29
  end
23
30
 
31
+ it "should find a manga from MF" do
32
+ m = M.find('naruto')
33
+ mangafox_hash_found = m.find {|hash| hash[:uri] =~ /mangafox/}
34
+ expect(mangafox_hash_found).not_to be_nil
35
+ end
36
+
37
+ #for sanity
38
+ it "should create a list of MDHash" do
39
+ expect(@mf_manga.chapters_list[10]).to be_kind_of(MDHash)
40
+ end
41
+
42
+ it "should create MFChapter for mf manga" do
43
+ @mf_manga.get_chapter(10)
44
+ expect(@mf_manga.chapters.first).to be_kind_of(MFChapter)
45
+ end
46
+
47
+ it "should download a manga from MF" do
48
+ dir = Dir.pwd
49
+ M.download(@mf_manga, 500, 501)
50
+ expect(Dir.glob(dir + "/#{@mf_manga.name}/*").length).to eq(2)
51
+ end
52
+
24
53
  it "should download a manga with the download command" do
25
- puts Dir.pwd
26
54
  chps = Dir.glob("#{Dir.pwd}/#{@manga.name}/*/")
27
55
  expect(chps.length).to eq(3)
28
56
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper.rb'
2
+
3
+ module Mangdown
4
+ describe MangaList do
5
+ before do
6
+ @manga_list = MangaList.new(
7
+ 'http://www.mangareader.net/alphabetical')
8
+ end
9
+
10
+ subject {@manga_list}
11
+
12
+ it "should not have an empty manga list" do
13
+ expect(subject.mangas).to_not be_empty
14
+ end
15
+ end
16
+ end
17
+
@@ -1,12 +1,15 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  module Mangdown
4
- @@m_uri = 'http://www.mangareader.net/94/bleach.html'
5
- @@manga_name = 'Bleach'
4
+ @@manga_hash = MDHash.new
5
+ @@manga_hash[:uri] = 'http://www.mangareader.net/94/bleach.html'
6
+ @@manga_hash[:name] = 'Bleach'
6
7
 
7
- manga = Manga.new( @@m_uri, @@manga_name )
8
+ manga = Manga.new(@@manga_hash)
8
9
 
9
- MANGA_STUB_PATH = File.expand_path('../../objects/manga.yml', __FILE__)
10
+ MANGA_STUB_PATH = File.expand_path('../../objects/manga.yml',
11
+ __FILE__)
12
+
10
13
  File.open(MANGA_STUB_PATH, 'w+') do |file|
11
14
  file.write(manga.to_yaml)
12
15
  end
@@ -16,17 +19,27 @@ module Mangdown
16
19
  before(:each) do
17
20
  print '@'
18
21
  @manga = YAML.load(File.open(Mangdown::MANGA_STUB_PATH, 'r').read)
19
- @manga.get_doc(@@m_uri)
22
+ #@manga.get_doc(@@manga_hash[:uri])
20
23
  end
21
24
 
22
25
  context "When a manga is initialized" do
23
- it "should have chapters" do
26
+ it "should not have chapters" do
24
27
  expect(@manga.chapters).to be_empty
25
28
  end
26
29
 
27
30
  it "should have chapters listed in chapters_list" do
28
31
  expect(@manga.chapters_list).not_to be_empty
29
32
  end
33
+
34
+ context "as a MangaFox manga" do
35
+ it "should have chapters" do
36
+ hash = MDHash.new
37
+ hash[:uri] = 'http://mangafox.me/manga/masca_the_beginning/'
38
+ hash[:name] = 'Masca: The Beginning'
39
+ manga = Manga.new(hash)
40
+ expect(manga.chapters_list).not_to be_empty
41
+ end
42
+ end
30
43
  end
31
44
 
32
45
  context "with Bleach manga" do
@@ -35,21 +48,22 @@ module Mangdown
35
48
  end
36
49
 
37
50
  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'])
51
+ expect(@manga.chapters_list.first).to eq({
52
+ uri:'http://www.mangareader.net/94-8-1/bleach/chapter-1.html',
53
+ name: 'Bleach 1'})
41
54
  end
42
55
 
43
56
  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'])
57
+ expect(@manga.chapters_list[464]).to eq({
58
+ uri: 'http://www.mangareader.net/bleach/465',
59
+ name: 'Bleach 465'})
47
60
  end
48
61
  end
49
62
 
50
63
  context "when a chapter is retrieved" do
51
64
  before(:all) do
52
- @manga2 = YAML.load(File.open(Mangdown::MANGA_STUB_PATH, 'r').read)
65
+ @manga2 = YAML.load(File.open(
66
+ Mangdown::MANGA_STUB_PATH, 'r').read)
53
67
  @manga2.get_chapter(0)
54
68
  @mchapter = @manga2.chapters_list[0]
55
69
  end
@@ -59,12 +73,12 @@ module Mangdown
59
73
  end
60
74
 
61
75
  it "should have chapter 1 in chapters" do
62
- expect(@manga2.chapters[0].name).to eq(@mchapter[1])
76
+ expect(@manga2.chapters[0].name).to eq(@mchapter[:name])
63
77
  end
64
78
 
65
79
  it "should have the right chapter sub class" do
66
80
  klass = Chapter
67
- if @mchapter[0].include?('mangareader')
81
+ if @mchapter[:uri].include?('mangareader')
68
82
  klass = MRChapter
69
83
  end
70
84
 
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ module Mangdown
4
+
5
+ describe MDHash do
6
+ before(:all) do
7
+ @hash = MDHash.new
8
+ @hash[:uri] = 'http://www.mangareader.net/103/one-piece.html'
9
+ @hash[:name] = 'One Piece'
10
+ end
11
+
12
+ it "should get a manga object from get_manga" do
13
+ expect(@hash.get_manga).to be_kind_of(Manga)
14
+ end
15
+ end
16
+ end
@@ -4,11 +4,16 @@ module Mangdown
4
4
  describe Page do
5
5
  before(:all) do
6
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 )
7
+ @page_hash = MDHash.new
8
+ @page_hash[:uri] =
9
+ 'http://i25.mangareader.net/bleach/537/bleach-4149721.jpg'
10
+ @page_hash[:name] = "Bleach 537 - Page 1"
11
+
12
+ @page = Page.new(@page_hash)
10
13
  @page.download
11
- PAGE_STUB_PATH = File.expand_path('../../objects/page.yml', __FILE__)
14
+ PAGE_STUB_PATH = File.expand_path('../../objects/page.yml',
15
+ __FILE__)
16
+
12
17
  File.open(PAGE_STUB_PATH, 'w+') do |file|
13
18
  file.write(@page.to_yaml)
14
19
  end
@@ -2,7 +2,9 @@ require 'rspec'
2
2
  require 'yaml'
3
3
  require_relative '../lib/mangdown'
4
4
 
5
- dirs = ['../../Bleach 537', '../../6 NO TRIGGER']
5
+ M.clean_up
6
+
7
+ dirs = ['../../Bleach 537', '../../6 no Trigger', '../../Naruto']
6
8
 
7
9
  dirs.each do |d|
8
10
  dir = File.expand_path(d, __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jphager2
@@ -23,13 +23,16 @@ files:
23
23
  - lib/mangdown/chapter.rb
24
24
  - lib/mangdown/commands.rb
25
25
  - lib/mangdown/manga.rb
26
+ - lib/mangdown/manga_list.rb
26
27
  - lib/mangdown/mangdown_hash.rb
27
28
  - lib/mangdown/page.rb
28
29
  - lib/mangdown/popular.rb
29
30
  - lib/mangdown/tools.rb
30
31
  - spec/mangdown/chapter_spec.rb
31
32
  - spec/mangdown/commands_spec.rb
33
+ - spec/mangdown/manga_list_spec.rb
32
34
  - spec/mangdown/manga_spec.rb
35
+ - spec/mangdown/mangdown_hash_spec.rb
33
36
  - spec/mangdown/page_spec.rb
34
37
  - spec/mangdown/popular_spec.rb
35
38
  - spec/objects/make_chapter.rb