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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0eeabd1173684b550b4cdf72608c175b4391510
4
- data.tar.gz: 65dc5fd208fbea67661742c9783f52faaa12aaeb
3
+ metadata.gz: 3601e69092554b4994957c59e79fde24ed0b5014
4
+ data.tar.gz: eab931deff079ce8f0aa89636c3ba089733b6faa
5
5
  SHA512:
6
- metadata.gz: ce29debf06fb2c5b16ff66f133c8cd0ef2bc8a2f6de9b234d7d37647a214f4e7011d9a0432965b12983381f219cc2d233e253a609fcc0ed7281c03aef7cbb854
7
- data.tar.gz: f389ae7aaab05d16ac7669cf1a98f8b7ec358ee5c71a6871a5d5c0aadfe1e5022dd4615ca8061fa9ecf2efd0391fc824ca94832912c860386ec57b93d25c76d0
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.
@@ -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
+ ==============================================================================
@@ -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
@@ -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
@@ -1,131 +1,59 @@
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
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
@@ -1,45 +1,57 @@
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
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