dmanga 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -16
- data/Rakefile +1 -1
- data/dmanga.gemspec +5 -5
- data/exe/dmanga +33 -33
- data/lib/dmanga/mangahost_parser.rb +111 -125
- data/lib/dmanga/options.rb +3 -3
- data/lib/dmanga/site_parser_base.rb +162 -164
- data/lib/dmanga/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: deb29d8a3f37a43319f5ac20271ad721bfe382a1429b86cc7b747125e01a28c6
|
4
|
+
data.tar.gz: 02f59dbbd866dd1fb274653319e2b2a167ed49fea4ee899c8ea7f97cd86644da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 872f61a1d9fbc2cb9a03ef041462e77428bff5a7b7cbe8fb5329c5c3a2b02a0a9b4b97301ea41c53e533691ac30968dc92e0b39f13fa0b2eac63ed54bd9dcd69
|
7
|
+
data.tar.gz: 1f1ea53b5a5aab5f78d06623d3990a7f4ee35e524a33a80a8eef2c8108fe2890a837ba379dd0152093f3d72879b665abd0ec08f70f2023ab98df5f9c95bb9e21
|
data/README.md
CHANGED
@@ -1,26 +1,12 @@
|
|
1
1
|
# DManga
|
2
2
|
|
3
3
|
DManga é um script/programa ruby multiplataforma Window/Linux/Mac
|
4
|
-
para baixar mangas
|
5
|
-
qualquer manga hospedado em mangahost
|
4
|
+
para baixar mangas do site mangahost. Com ele voce pode baixar
|
5
|
+
qualquer manga hospedado em mangahost (site br de hospedagem de
|
6
6
|
manga) de forma automatizada e sem restrição de quantidade. Basta
|
7
7
|
dizer o nome do manga e selecionar os capitulos que deseja baixar
|
8
8
|
e pronto o script fará os downloads do capitulos selecionados.
|
9
9
|
|
10
|
-
#### Atualização
|
11
|
-
|
12
|
-
> - Corrigido erro com download de arachnid, uwakoi (não baixem isso) e outros.
|
13
|
-
|
14
|
-
> **Se acontecer qualquer erro atualize o script/programa (esse erro provalvemente já foi corrigido)**.
|
15
|
-
|
16
|
-
> Para atualizar:
|
17
|
-
|
18
|
-
> `gem update dmanga`
|
19
|
-
|
20
|
-
> E para remover a versão anterior:
|
21
|
-
|
22
|
-
> `gem clean`
|
23
|
-
|
24
10
|
## Instalação
|
25
11
|
|
26
12
|
### Windows
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ desc "change to master branch"
|
|
17
17
|
task :master do system "git checkout master" end
|
18
18
|
|
19
19
|
desc "exec the app"
|
20
|
-
task :exe do system "ruby -Ilib exe/dmanga denki ga honya" end
|
20
|
+
task :exe do system "ruby -Ilib exe/dmanga 'denki ga honya' -v" end
|
21
21
|
|
22
22
|
desc "console with app loaded"
|
23
23
|
task :console do system "bundle exec bin/console" end
|
data/dmanga.gemspec
CHANGED
@@ -31,12 +31,12 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ["lib"]
|
33
33
|
|
34
|
-
spec.add_runtime_dependency "ruby-progressbar","~> 1.
|
34
|
+
spec.add_runtime_dependency "ruby-progressbar","~> 1.9"
|
35
35
|
spec.add_runtime_dependency "addressable","~> 2.5"
|
36
36
|
spec.add_runtime_dependency "rubyzip","~> 1.2"
|
37
37
|
spec.add_runtime_dependency "formatador", "~> 0.2"
|
38
|
-
spec.add_development_dependency "minitest","~> 5.
|
39
|
-
spec.add_development_dependency "webmock", "~> 3.
|
40
|
-
spec.add_development_dependency "rake", "~> 12.
|
41
|
-
spec.add_development_dependency "bundler", "~> 1.
|
38
|
+
spec.add_development_dependency "minitest","~> 5.11"
|
39
|
+
spec.add_development_dependency "webmock", "~> 3.3"
|
40
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
41
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
42
42
|
end
|
data/exe/dmanga
CHANGED
@@ -12,46 +12,46 @@ begin
|
|
12
12
|
mangahost.download
|
13
13
|
DManga::display_feedback "\nTodos os download concluidos"
|
14
14
|
|
15
|
-
rescue URI::InvalidURIError => uri_error
|
16
|
-
|
17
|
-
|
15
|
+
rescue URI::InvalidURIError => uri_error
|
16
|
+
DManga::display_error("Nome do manga não deve conter acentos, cecedilha ou simbolos",
|
17
|
+
uri_error)
|
18
18
|
|
19
|
-
rescue Errno::ECONNRESET => con_error
|
20
|
-
|
21
|
-
|
19
|
+
rescue Errno::ECONNRESET => con_error
|
20
|
+
DManga::display_error("Não foi possivel conectar a internet",
|
21
|
+
con_error)
|
22
22
|
|
23
|
-
rescue OpenURI::HTTPError => http_error
|
24
|
-
|
25
|
-
|
23
|
+
rescue OpenURI::HTTPError => http_error
|
24
|
+
DManga::display_error("Servidor recusando conexao",
|
25
|
+
http_error)
|
26
26
|
|
27
|
-
rescue DManga::MangaNotFoundError => manga_error
|
28
|
-
|
29
|
-
|
27
|
+
rescue DManga::MangaNotFoundError => manga_error
|
28
|
+
DManga::display_warn "\t#{manga_error}"
|
29
|
+
DManga::display_feedback "\tExiting"
|
30
30
|
|
31
|
-
rescue Net::ReadTimeout => timeout_error
|
32
|
-
|
33
|
-
|
31
|
+
rescue Net::ReadTimeout => timeout_error
|
32
|
+
DManga::display_error("Site demorou demais para responder",
|
33
|
+
timeout_error)
|
34
34
|
|
35
|
-
rescue Net::OpenTimeout => timeout_error
|
36
|
-
|
37
|
-
|
35
|
+
rescue Net::OpenTimeout => timeout_error
|
36
|
+
DManga::display_error("Site demorou demais para responder",
|
37
|
+
timeout_error)
|
38
38
|
|
39
|
-
rescue SocketError => sock_error
|
40
|
-
|
41
|
-
|
39
|
+
rescue SocketError => sock_error
|
40
|
+
DManga::display_error("Nao foi possivel conectar a internet",
|
41
|
+
sock_error)
|
42
42
|
|
43
|
-
rescue OpenSSL::SSL::SSLError => ssl_error
|
44
|
-
|
45
|
-
|
43
|
+
rescue OpenSSL::SSL::SSLError => ssl_error
|
44
|
+
DManga::display_error("Não foi possivel conectar a internet",
|
45
|
+
ssl_error)
|
46
46
|
|
47
|
-
rescue Errno::ENETUNREACH => error
|
48
|
-
|
49
|
-
|
47
|
+
rescue Errno::ENETUNREACH => error
|
48
|
+
DManga::display_error("Não foi possivel conectar a internet",
|
49
|
+
error)
|
50
50
|
|
51
|
-
rescue Errno::ENOENT => error
|
52
|
-
|
53
|
-
|
51
|
+
rescue Errno::ENOENT => error
|
52
|
+
DManga::display_error("Diretorio epecificado não existe",
|
53
|
+
error)
|
54
54
|
|
55
|
-
rescue Interrupt
|
56
|
-
|
57
|
-
end
|
55
|
+
rescue Interrupt
|
56
|
+
DManga::display_feedback("\nBye")
|
57
|
+
end
|
@@ -1,136 +1,122 @@
|
|
1
|
-
# require 'dmanga/site_parser_base'
|
2
1
|
require 'dmanga/site_parser_base'
|
3
2
|
require 'dmanga/zip_file_generator'
|
4
|
-
#require 'pry'
|
5
3
|
|
6
4
|
module DManga
|
7
|
-
|
8
|
-
|
9
|
-
# url used to search in the site
|
10
|
-
SEARCH_URL = "https://mangahost.net/find/"
|
11
|
-
|
12
|
-
# regex to extract url of found mangas
|
13
|
-
SEARCH_LINK_REGEX = /entry-title">\s*<a\s*href="(.*)?"\s*title="(.*)"/
|
14
|
-
|
15
|
-
# Regex to extract chapters' url from manga page.
|
16
|
-
# Manga host has two diferent manga pages.
|
17
|
-
# One to medium/short mangas and one to big mangas
|
18
|
-
# /capitulo['"]\stitle=['"]Ler Online\s+-\s+(.*?)['"]\s+href=['"](.*?)['"]/, # for short/medium mangas
|
19
|
-
CHAPTER_LINK_REGEX = [
|
20
|
-
/capitulo.*?Ler\s+Online\s+-\s+(.*?)['"]\s+href=['"](.*?)['"]/, # for short/medium mangas
|
21
|
-
/<a\s+href=['"](.*?)['"]\s+title=['"]Ler\s+Online\s+-\s+(.*?)\s+\[\]/ # for big mangas
|
22
|
-
]
|
23
|
-
|
24
|
-
# regex to extract images' url from chapter page
|
25
|
-
IMG_LINK_REGEX = [/img_\d+['"]\s+src=['"](.*?)['"]/,
|
26
|
-
/url['"]:['"](.*?)['"]\}/]
|
27
|
-
|
28
|
-
def download
|
29
|
-
|
30
|
-
# white space is not allowed in the search url.
|
31
|
-
guess_manga_name = @options.manga.gsub(/\s/, '+') # Replace ' ' by '+'
|
32
|
-
|
33
|
-
search("#{SEARCH_URL}#{guess_manga_name}", SEARCH_LINK_REGEX)
|
34
|
-
|
35
|
-
# puts "executing chapters".green ## DEBUG
|
36
|
-
# Due the organazation of the chapters page the chapters are
|
37
|
-
# extracted in reverse order
|
38
|
-
@chapters = parse(@manga_url, CHAPTER_LINK_REGEX[0]) do |resul, page|
|
39
|
-
|
40
|
-
# use long mangas regex if short mangas regex
|
41
|
-
# returns empty array
|
42
|
-
if resul.empty?
|
43
|
-
# Extract chapters name and url and
|
44
|
-
# swap chapter[0](name) with chapter[1](url)
|
45
|
-
# to conform with result from CHAPTER_LINK_REGEX[0]
|
46
|
-
page.scan(CHAPTER_LINK_REGEX[1]) {|chapter| resul << chapter.rotate}
|
47
|
-
end
|
48
|
-
resul
|
49
|
-
end
|
5
|
+
class MangaHostParser < SiteParserBase
|
50
6
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# prompt user to select chapters to download
|
55
|
-
select_chapters
|
56
|
-
|
57
|
-
# remove simbols that cannot be used in folder's name on windows
|
58
|
-
remove_invalid_simbols(@manga_name)
|
59
|
-
# create manga directory
|
60
|
-
remove_invalid_simbols(@manga_name)
|
61
|
-
create_dir(@manga_name)
|
62
|
-
|
63
|
-
# download selected chapters
|
64
|
-
@chapters.reverse_each do |chapter|
|
65
|
-
imgs_url = parse(chapter[1], IMG_LINK_REGEX[0]) do |resul, page|
|
66
|
-
# use second pattern if the first returns a empty
|
67
|
-
# array
|
68
|
-
# binding.pry # DEBUG
|
69
|
-
if resul.empty?
|
70
|
-
page.scan(IMG_LINK_REGEX[1]) do |img|
|
71
|
-
#resul << img[0].gsub!(%r{\\}, "")
|
72
|
-
resul << img[0]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
resul.each do |img|
|
77
|
-
# some images urls are incorrect and need to be corrected. For exemple:
|
78
|
-
# img.mangahost.net/br/images/img.png.webp => img.mangahost.net/br/mangas_files/img.png
|
79
|
-
img.sub!(/images/, "mangas_files")
|
80
|
-
img.sub!(/\.webp/, "")
|
81
|
-
|
82
|
-
#correct créditos img problem
|
83
|
-
correct_image_uri(img)
|
84
|
-
|
85
|
-
img.gsub!(%r{\\}, "")
|
86
|
-
end
|
87
|
-
resul
|
88
|
-
end
|
89
|
-
|
90
|
-
# create chapter directory relative to manga directory
|
91
|
-
chapter_name = "#{chapter[0]}"
|
92
|
-
# remove simbols that cannot be used in folder's name on windows
|
93
|
-
remove_invalid_simbols chapter_name
|
94
|
-
chapter_dir = "#{@manga_name}/#{chapter_name}"
|
95
|
-
create_dir(chapter_dir)
|
96
|
-
|
97
|
-
DManga::display_feedback "\nBaixando #{chapter_name}"
|
98
|
-
imgs_download(chapter_dir, imgs_url)
|
99
|
-
end
|
100
|
-
end
|
7
|
+
# url used to search in the site
|
8
|
+
# SEARCH_URL = "https://mangahost.net/find/"
|
9
|
+
SEARCH_URL = "https://mangahost.cc/find/"
|
101
10
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
11
|
+
# regex to extract url of found mangas
|
12
|
+
SEARCH_LINK_REGEX = /entry-title">\s*<a\s*href="(.*)?"\s*title="(.*)"/
|
13
|
+
|
14
|
+
# Regex to extract chapters' url from manga page.
|
15
|
+
# Manga host has two diferent manga pages.
|
16
|
+
# One to medium/short mangas and one to big mangas
|
17
|
+
CHAPTER_LINK_REGEX = [
|
18
|
+
/capitulo.*?Ler\s+Online\s+-\s+(.*?)['"]\s+href=['"](.*?)['"]/, # for short/medium mangas
|
19
|
+
/<a\s+href=['"](.*?)['"]\s+title=['"]Ler\s+Online\s+-\s+(.*?)\s+\[\]/ # for big mangas
|
20
|
+
]
|
21
|
+
|
22
|
+
# regex to extract images' url from chapter page
|
23
|
+
IMG_LINK_REGEX = [/img_\d+['"]\s+src=['"](.*?)['"]/,
|
24
|
+
/url['"]:['"](.*?)['"]\}/]
|
25
|
+
|
26
|
+
def download
|
27
|
+
|
28
|
+
# white space is not allowed in the search url.
|
29
|
+
guess_manga_name = @options.manga.gsub(/\s/, '+') # Replace ' ' by '+'
|
30
|
+
|
31
|
+
search("#{SEARCH_URL}#{guess_manga_name}", SEARCH_LINK_REGEX)
|
32
|
+
|
33
|
+
# Due the organazation of the chapters page the chapters are
|
34
|
+
# extracted in reverse order
|
35
|
+
@chapters = parse(@manga_url, CHAPTER_LINK_REGEX[0]) do |resul, page|
|
109
36
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
37
|
+
# use long mangas regex if short mangas regex
|
38
|
+
# returns empty array
|
39
|
+
if resul.empty?
|
40
|
+
# Extract chapters name and url and
|
41
|
+
# swap chapter[0](name) with chapter[1](url)
|
42
|
+
# to conform with result from CHAPTER_LINK_REGEX[0]
|
43
|
+
page.scan(CHAPTER_LINK_REGEX[1]) {|chapter| resul << chapter.rotate}
|
44
|
+
end
|
45
|
+
resul
|
46
|
+
end
|
47
|
+
|
48
|
+
# correct utf-8 errors
|
49
|
+
correct_chapters_name
|
50
|
+
|
51
|
+
# prompt user to select chapters to download
|
52
|
+
select_chapters
|
53
|
+
|
54
|
+
# remove simbols that cannot be used in folder's name on windows
|
55
|
+
remove_invalid_simbols(@manga_name)
|
56
|
+
# create manga directory
|
57
|
+
remove_invalid_simbols(@manga_name)
|
58
|
+
create_dir(@manga_name)
|
59
|
+
|
60
|
+
# download selected chapters
|
61
|
+
@chapters.reverse_each do |chapter|
|
62
|
+
imgs_url = parse(chapter[1], IMG_LINK_REGEX[0]) do |resul, page|
|
63
|
+
# use second pattern if the first returns a empty
|
64
|
+
# array
|
65
|
+
if resul.empty?
|
66
|
+
page.scan(IMG_LINK_REGEX[1]) do |img|
|
67
|
+
resul << img[0]
|
128
68
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
#
|
133
|
-
#
|
69
|
+
end
|
70
|
+
|
71
|
+
resul.each do |img|
|
72
|
+
# some images urls are incorrect and need to be corrected. For exemple:
|
73
|
+
# img.mangahost.net/br/images/img.png.webp => img.mangahost.net/br/mangas_files/img.png
|
74
|
+
img.sub!(/images/, "mangas_files")
|
75
|
+
img.sub!(/\.webp/, "")
|
76
|
+
|
77
|
+
#correct créditos img problem
|
78
|
+
correct_image_uri(img)
|
79
|
+
|
80
|
+
img.gsub!(%r{\\}, "")
|
81
|
+
end
|
82
|
+
resul
|
134
83
|
end
|
84
|
+
|
85
|
+
# create chapter directory relative to manga directory
|
86
|
+
chapter_name = "#{chapter[0]}"
|
87
|
+
# remove simbols that cannot be used in folder's name on windows
|
88
|
+
remove_invalid_simbols chapter_name
|
89
|
+
chapter_dir = "#{@manga_name}/#{chapter_name}"
|
90
|
+
create_dir(chapter_dir)
|
91
|
+
|
92
|
+
DManga::display_feedback "\nBaixando #{chapter_name}"
|
93
|
+
imgs_download(chapter_dir, imgs_url)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
# Due to problems with open-uri and unicode
|
99
|
+
# some chapters' name need to be corrected.
|
100
|
+
# substitute Cap$amptulo for capitulo.
|
101
|
+
def correct_chapters_name
|
102
|
+
@chapters.each {|chapter| chapter[0].sub!(/[cC]ap.*?tulo/, "capitulo")}
|
103
|
+
end
|
104
|
+
|
105
|
+
UNICODE_TABLE = {
|
106
|
+
"\\u00e1" => "\u00e1",
|
107
|
+
"\\u00e9" => "\u00e9",
|
108
|
+
"\\u00ed" => "\u00ed"
|
109
|
+
}
|
110
|
+
|
111
|
+
# Due to problems with open-uri and utf-8
|
112
|
+
# some images uris need to be corrected.
|
113
|
+
# substitute Cru00e9ditos for Créditos.
|
114
|
+
# one url at a time
|
115
|
+
def correct_image_uri(img_uri)
|
116
|
+
result = img_uri.scan(/\\u..../i)
|
117
|
+
result.each do |r|
|
118
|
+
img_uri.sub!(r, UNICODE_TABLE[r.downcase])
|
119
|
+
end
|
135
120
|
end
|
121
|
+
end
|
136
122
|
end
|
data/lib/dmanga/options.rb
CHANGED
@@ -7,7 +7,7 @@ module DManga
|
|
7
7
|
def initialize(argv)
|
8
8
|
@download_dir = DEFAULT_DOWNLOAD_DIR
|
9
9
|
@verbose = false
|
10
|
-
@site = "mangahost.
|
10
|
+
@site = "mangahost.cc"
|
11
11
|
parse(argv)
|
12
12
|
@manga = argv[0]
|
13
13
|
end
|
@@ -23,11 +23,11 @@ module DManga
|
|
23
23
|
exit
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on('-v', '--verbose',
|
26
|
+
opts.on('-v', '--verbose',
|
27
27
|
'Exibe informações da execução do programa.') do
|
28
28
|
@verbose = true
|
29
29
|
end
|
30
|
-
opts.on('-d', '--directory DIRETORIO',
|
30
|
+
opts.on('-d', '--directory DIRETORIO',
|
31
31
|
'O diretorio de destino do download. Padrão é Downloads.') do |path|
|
32
32
|
@download_dir = path
|
33
33
|
end
|
@@ -3,89 +3,87 @@ require 'dmanga/os'
|
|
3
3
|
require 'ruby-progressbar'
|
4
4
|
require 'open-uri'
|
5
5
|
require 'addressable/uri'
|
6
|
-
#require 'pry'
|
7
|
-
# require 'formatador'
|
8
6
|
|
9
7
|
module DManga
|
10
|
-
|
11
|
-
|
8
|
+
class SiteParserBase
|
9
|
+
USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0"
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
attr_accessor :manga_name, :manga_url,
|
12
|
+
:chapters, :verbose
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
def initialize(argv)
|
15
|
+
@options = Options.new(argv)
|
16
|
+
@manga_url = nil
|
17
|
+
# manga_name is also used as manga directory name
|
18
|
+
@manga_name = nil
|
19
|
+
@chapters = nil
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
result = yield(result, page) if block_given?
|
41
|
-
else
|
42
|
-
DManga::display_error("ERRO: Servidor respondeu: #{response.status.inpect}")
|
43
|
-
end
|
22
|
+
# Parse the html and extract links that match the pattern.
|
23
|
+
# Can receive a block.
|
24
|
+
def parse(url, regex)
|
25
|
+
DManga::display_feedback "\nfetching #{url}" if @options.verbose
|
26
|
+
result = []
|
27
|
+
open(url, "User-Agent" => USER_AGENT) do |response|
|
28
|
+
if response.status[1] == "OK"
|
29
|
+
DManga::display_feedback "parsing #{url}" if @options.verbose
|
30
|
+
page = response.read
|
31
|
+
page.scan(regex) do |r| # => try first regex
|
32
|
+
if r.length < 2
|
33
|
+
result << r[0]
|
34
|
+
else
|
35
|
+
result << r
|
44
36
|
end
|
45
|
-
|
37
|
+
end
|
38
|
+
result = yield(result, page) if block_given?
|
39
|
+
else
|
40
|
+
DManga::display_error("ERRO: Servidor respondeu: #{response.status.inpect}")
|
46
41
|
end
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
def search(url, regex)
|
47
|
+
DManga::display_feedback "Iniciando busca em #{@options.site}"
|
48
|
+
search_result = parse(url, regex)
|
49
|
+
select_manga(search_result)
|
50
|
+
end
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
else
|
71
|
-
raise MangaNotFoundError, "manga não encontrado"
|
72
|
-
end
|
73
|
-
raise MangaNotFoundError, "manga não encontrado" if @manga_url.nil?
|
52
|
+
def select_manga(mangas)
|
53
|
+
puts # just a new line for better output
|
54
|
+
unless mangas.empty?
|
55
|
+
mangas.each do |manga|
|
56
|
+
DManga::display_prompt("Você quer baixar #{manga[1]} [s/n]? ")
|
57
|
+
res = $stdin.gets.chomp
|
58
|
+
if res == 's'
|
59
|
+
@manga_url = manga[0]
|
60
|
+
@manga_name = manga[1]
|
61
|
+
break
|
62
|
+
elsif res != 'n'
|
63
|
+
DManga::display_warn("\tOpção invalida")
|
64
|
+
DManga::display_feedback("\tSaindo")
|
65
|
+
exit(true)
|
66
|
+
end
|
74
67
|
end
|
68
|
+
else
|
69
|
+
raise MangaNotFoundError, "manga não encontrado"
|
70
|
+
end
|
71
|
+
raise MangaNotFoundError, "manga não encontrado" if @manga_url.nil?
|
72
|
+
end
|
75
73
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
74
|
+
def select_chapters
|
75
|
+
DManga::display_feedback "\nCapítulos:"
|
76
|
+
@chapters.reverse_each.with_index do |chapter, index|
|
77
|
+
DManga::display_feedback "(#{index + 1})\t#{chapter[0]}"
|
78
|
+
end
|
79
|
+
answer = nil
|
80
|
+
DManga::display_feedback "\n#{@chapters.length} capitulos encontrados\n"
|
81
|
+
loop do
|
82
|
+
DManga::display_prompt("Quais capitulos você quer baixar? ")
|
83
|
+
answer = $stdin.gets.chomp
|
84
|
+
if answer == "o" || answer.empty?
|
85
|
+
DManga::display_feedback(
|
86
|
+
<<-EOS
|
89
87
|
o - exibe opções.
|
90
88
|
c - cancelar.
|
91
89
|
todos - baixar todos os capítulos.
|
@@ -93,107 +91,107 @@ module DManga
|
|
93
91
|
Ex: 0-10 - baixa do 0 ao 10.
|
94
92
|
capNum,capNum,capNum - baixar capitulos selecionados.
|
95
93
|
Ex: 29,499,1 - baixa capitulos 29, 499 e 1.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
# return a progressbar suitable to the user operating system
|
129
|
-
def get_progressbar
|
130
|
-
if DManga::OS.windows?
|
131
|
-
return ProgressBar.create(:title => 'Baixando',
|
132
|
-
:starting_at => 20,
|
133
|
-
:length => 70,
|
134
|
-
:total => nil)
|
135
|
-
else
|
136
|
-
return ProgressBar.create(:title => 'Baixando',
|
137
|
-
:starting_at => 20,
|
138
|
-
:total => nil)
|
139
|
-
end
|
94
|
+
EOS
|
95
|
+
)
|
96
|
+
elsif answer == "c"
|
97
|
+
DManga::display_feedback("Saindo")
|
98
|
+
exit true
|
99
|
+
elsif answer == "todos"
|
100
|
+
DManga::display_feedback "Baixando todos os capítulos" if @options.verbose
|
101
|
+
break
|
102
|
+
elsif answer =~ /(\d+)-(\d+)/
|
103
|
+
b = Integer($2) <= @chapters.length ? Integer($2) * -1 : @chapters.length * -1
|
104
|
+
e = Integer($1) * -1
|
105
|
+
@chapters = @chapters[b..e]
|
106
|
+
DManga::display_feedback "Baixando capítulos do #{$1} ao #{$2}" if @options.verbose
|
107
|
+
break
|
108
|
+
elsif answer =~ /^(\d+,?)+$/
|
109
|
+
answer = answer.split(',')
|
110
|
+
aux = []
|
111
|
+
# downloads are processed in reverse order (to make
|
112
|
+
# it in crescent order)so the answer is reversed too
|
113
|
+
answer.reverse_each do |c|
|
114
|
+
chp = @chapters[Integer(c) * -1]
|
115
|
+
aux << chp unless chp.nil?
|
116
|
+
end
|
117
|
+
@chapters = aux
|
118
|
+
DManga::display_feedback "Baixando capítulos #{answer.to_s}" if @options.verbose
|
119
|
+
break
|
120
|
+
else
|
121
|
+
DManga::display_warn("\tOpção invalida")
|
140
122
|
end
|
123
|
+
end
|
124
|
+
end
|
141
125
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
126
|
+
# return a progressbar suitable to the user operating system
|
127
|
+
def get_progressbar
|
128
|
+
if DManga::OS.windows?
|
129
|
+
return ProgressBar.create(:title => 'Baixando',
|
130
|
+
:starting_at => 20,
|
131
|
+
:length => 70,
|
132
|
+
:total => nil)
|
133
|
+
else
|
134
|
+
return ProgressBar.create(:title => 'Baixando',
|
135
|
+
:starting_at => 20,
|
136
|
+
:total => nil)
|
137
|
+
end
|
138
|
+
end
|
146
139
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
encoded_url = Addressable::URI.encode(url)
|
152
|
-
DManga::display_feedback "\n#{encoded_url}"
|
153
|
-
pbar = get_progressbar
|
154
|
-
open(
|
155
|
-
encoded_url, "User-Agent" => USER_AGENT,
|
156
|
-
:progress_proc => lambda {|s| pbar.increment }
|
157
|
-
) do |response|
|
158
|
-
if response.status[1] == "OK"
|
159
|
-
DManga::display_feedback "Salvando imagem em:'#{img_path}'" if @options.verbose
|
160
|
-
File.open(img_path, "wb") do |img|
|
161
|
-
img.puts response.read
|
162
|
-
end
|
163
|
-
else
|
164
|
-
puts "Error #{reponse.status}"
|
165
|
-
end
|
166
|
-
end
|
167
|
-
puts
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
140
|
+
# download images to path relative to Downloads directory
|
141
|
+
def imgs_download(chp_path, imgs_urls)
|
142
|
+
imgs_urls.each do |url|
|
143
|
+
original_filename = url.slice(/(?u)(\w|[_-])+\.(png|jpg)/i)
|
171
144
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
145
|
+
img_path = [@options.download_dir,
|
146
|
+
chp_path,
|
147
|
+
original_filename].join(File::SEPARATOR)
|
148
|
+
unless File.exist? img_path
|
149
|
+
encoded_url = Addressable::URI.encode(url)
|
150
|
+
DManga::display_feedback "\n#{encoded_url}"
|
151
|
+
pbar = get_progressbar
|
152
|
+
open(
|
153
|
+
encoded_url, "User-Agent" => USER_AGENT,
|
154
|
+
:progress_proc => lambda {|s| pbar.increment }
|
155
|
+
) do |response|
|
156
|
+
if response.status[1] == "OK"
|
157
|
+
DManga::display_feedback "Salvando imagem em:'#{img_path}'" if @options.verbose
|
158
|
+
File.open(img_path, "wb") do |img|
|
159
|
+
img.puts response.read
|
160
|
+
end
|
180
161
|
else
|
181
|
-
|
162
|
+
puts "Error #{reponse.status}"
|
182
163
|
end
|
164
|
+
end
|
165
|
+
puts
|
183
166
|
end
|
167
|
+
end
|
168
|
+
end
|
184
169
|
|
185
|
-
|
186
|
-
|
187
|
-
|
170
|
+
# check if the directory exists and
|
171
|
+
# create a directory relative to downlaod directory
|
172
|
+
def create_dir(relative_path)
|
173
|
+
absolute_path = [@options.download_dir, relative_path].join(File::SEPARATOR)
|
174
|
+
DManga::display_feedback "\nCriando diretorio '#{relative_path}' em '#{@options.download_dir}'" if @options.verbose
|
175
|
+
unless Dir.exist? absolute_path
|
176
|
+
Dir.mkdir(absolute_path)
|
177
|
+
puts if @options.verbose ## just a blank line for prettier output
|
178
|
+
else
|
179
|
+
DManga::display_feedback "'#{relative_path}' directorio ja existe" if @options.verbose
|
180
|
+
end
|
181
|
+
end
|
188
182
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
end
|
183
|
+
#def zip_chapter
|
184
|
+
## TODO
|
185
|
+
#end
|
193
186
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
187
|
+
# Returns the download destination directory
|
188
|
+
def download_dir
|
189
|
+
@options.download_dir
|
190
|
+
end
|
191
|
+
|
192
|
+
def remove_invalid_simbols(name)
|
193
|
+
# windows OS dont accept these simbols in folder name
|
194
|
+
name.gsub!(%r{[/\\:*?"<>|.]}, '_')
|
198
195
|
end
|
196
|
+
end
|
199
197
|
end
|
data/lib/dmanga/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dmanga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Endrew
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-progressbar
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: addressable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,56 +72,56 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '5.
|
75
|
+
version: '5.11'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '5.
|
82
|
+
version: '5.11'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: webmock
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
89
|
+
version: '3.3'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3.
|
96
|
+
version: '3.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '12.
|
103
|
+
version: '12.3'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '12.
|
110
|
+
version: '12.3'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: bundler
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '1.
|
117
|
+
version: '1.16'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '1.
|
124
|
+
version: '1.16'
|
125
125
|
description: Downloads any manga from mangahost.net. You can search and select any
|
126
126
|
chapter or range of chapters
|
127
127
|
email:
|
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
172
|
rubyforge_project:
|
173
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.7.7
|
174
174
|
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Downloads any manga from mangahost.net
|