mangdown 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +20 -20
- data/doc/help.txt +33 -33
- data/lib/mangdown.rb +19 -19
- data/lib/mangdown/cbz.rb +38 -38
- data/lib/mangdown/chapter.rb +59 -131
- data/lib/mangdown/commands.rb +57 -45
- data/lib/mangdown/manga.rb +47 -46
- data/lib/mangdown/mangdown_hash.rb +8 -8
- data/lib/mangdown/page.rb +21 -16
- data/lib/mangdown/popular.rb +63 -52
- data/lib/mangdown/tools.rb +114 -110
- data/spec/mangdown/chapter_spec.rb +82 -120
- data/spec/mangdown/commands_spec.rb +35 -35
- data/spec/mangdown/manga_spec.rb +75 -77
- data/spec/mangdown/page_spec.rb +34 -34
- data/spec/mangdown/popular_spec.rb +67 -67
- data/spec/objects/make_chapter.rb +5 -5
- data/spec/spec_helper.rb +37 -39
- metadata +7 -12
- data/scripts/cbz_dirs.rb +0 -67
- data/scripts/dl_fk_ch.rb +0 -14
- data/scripts/dl_fk_chps.rb +0 -25
- data/scripts/dl_slow.rb +0 -77
- data/scripts/get_all_fk_page.rb +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3601e69092554b4994957c59e79fde24ed0b5014
|
4
|
+
data.tar.gz: eab931deff079ce8f0aa89636c3ba089733b6faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4489b2f82b82f1fcfe40462a28a900eca489bb09ffbf7e482f179d97c1b7e7c6a778c8f8255c5eabb163d10ad33d1aa5da484d759c01bd2aa4357bee3d08f4fc
|
7
|
+
data.tar.gz: 67923d472168c32a8271f428039e9e8aaf726790d17f0a788eaf91bbd7c98162388ab44235199eb7b9d026a98700e6dac1dc6c4347f5f82180e4f34720f7df79
|
data/LICENSE
CHANGED
@@ -1,20 +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.
|
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
CHANGED
@@ -1,33 +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
|
-
==============================================================================
|
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.rb
CHANGED
@@ -1,19 +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
|
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/lib/mangdown/cbz.rb
CHANGED
@@ -1,38 +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
|
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
|
data/lib/mangdown/chapter.rb
CHANGED
@@ -1,131 +1,59 @@
|
|
1
|
-
module Mangdown
|
2
|
-
class Chapter
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
1
|
+
module Mangdown
|
2
|
+
class Chapter
|
3
|
+
|
4
|
+
attr_reader :name, :pages, :uri
|
5
|
+
|
6
|
+
def initialize( uri, name )
|
7
|
+
@uri = uri
|
8
|
+
@name = name
|
9
|
+
@pages = []
|
10
|
+
|
11
|
+
get_pages
|
12
|
+
end
|
13
|
+
|
14
|
+
# download should be in its own module
|
15
|
+
def download
|
16
|
+
start_dir = Dir.pwd
|
17
|
+
|
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
|
+
private
|
27
|
+
def get_pages
|
28
|
+
uri = @uri
|
29
|
+
doc = ::Mangdown::Tools.get_doc(uri)
|
30
|
+
|
31
|
+
get_num_pages(doc).times do
|
32
|
+
page_uri, page_name = get_page(doc)
|
33
|
+
uri = get_next_uri(doc)
|
34
|
+
|
35
|
+
@pages << Page.new( page_uri, page_name )
|
36
|
+
doc = ::Mangdown::Tools.get_doc(uri)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class MRChapter < Chapter
|
42
|
+
private
|
43
|
+
def get_page(doc)
|
44
|
+
image = doc.css('img')[0]
|
45
|
+
[image['src'], image['alt']]
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_next_uri(doc)
|
49
|
+
#root url + the href of the link to the next page
|
50
|
+
::Mangdown::Tools.get_root(@uri) +
|
51
|
+
doc.css('div#imgholder a')[0]['href']
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_num_pages(doc)
|
55
|
+
# the select is a dropdown menu of chapter pages
|
56
|
+
doc.css('select')[1].children.length
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/mangdown/commands.rb
CHANGED
@@ -1,45 +1,57 @@
|
|
1
|
-
module M
|
2
|
-
extend self
|
3
|
-
|
4
|
-
include ::Mangdown
|
5
|
-
extend ::Mangdown::Tools
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
1
|
+
module M
|
2
|
+
extend self
|
3
|
+
|
4
|
+
include ::Mangdown
|
5
|
+
extend ::Mangdown::Tools
|
6
|
+
|
7
|
+
def valid_search?(search)
|
8
|
+
search =~ /\w/
|
9
|
+
end
|
10
|
+
|
11
|
+
#returns a list of hash with :uri and :name of mangas found in @@list
|
12
|
+
def find(search)
|
13
|
+
unless valid_search?(search)
|
14
|
+
puts "Searches must contain letters and numbers.."
|
15
|
+
return []
|
16
|
+
end
|
17
|
+
|
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
|
29
|
+
|
30
|
+
=begin
|
31
|
+
search_result.collect! do |manga|
|
32
|
+
h = MDHash.new
|
33
|
+
h[:uri], h[:name] = manga[:uri], manga[:name]
|
34
|
+
h
|
35
|
+
end
|
36
|
+
=end
|
37
|
+
|
38
|
+
puts "Could not find manga" if search_result.empty?
|
39
|
+
|
40
|
+
search_result
|
41
|
+
end
|
42
|
+
|
43
|
+
def download(manga, first_chapter = 0, last_chapter = -1)
|
44
|
+
chapters = slow_get_chapters(manga, first_chapter, last_chapter)
|
45
|
+
slow_dl_chapters(chapters)
|
46
|
+
end
|
47
|
+
|
48
|
+
def cbz(dir)
|
49
|
+
CBZ.all(dir)
|
50
|
+
end
|
51
|
+
|
52
|
+
def help
|
53
|
+
help_file = File.expand_path('../../doc/help.txt',
|
54
|
+
File.dirname(__FILE__))
|
55
|
+
puts File.open(help_file, 'r').read
|
56
|
+
end
|
57
|
+
end
|