manga_fetch 0.0.0 → 0.2.0

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: 57196b36b8540e47a645ca3251a74fbf26f89c58
4
- data.tar.gz: 5e06b108569aa706c252938303467366e8c6b8c2
3
+ metadata.gz: 870395ce4d4c86cedf154f07a78ba30ed2adc37c
4
+ data.tar.gz: f16ff576f1ae7e24645ebd86a5d9599c79d0bb7c
5
5
  SHA512:
6
- metadata.gz: ed589e1983c8c02a88df428595cf4a373a50bcf514db589de3508e054e704321b3ff87ca3741d21db9c07a17843578ea90e486130f24a93beba4cde42a2d43fc
7
- data.tar.gz: 1b3f7e0f38991ae9e83f852b830e7a8cf52b4d6370eebdd1df1d0041bb1049c9846675e1e6d7072b486d8cfe8e97b2f4b358129c4dd1f84397af074371aea67c
6
+ metadata.gz: fa7be02326bc288750835ab04115464a6d5cf8fd5420dbda45281b79a149ae7b738e021d515f32b4bd0951c0e7883c30a25229c07ff3e3ca99ce5d7c8142eeb0
7
+ data.tar.gz: 3c6aff3e36cd2e026f29b9aafe61fb91470e0a24d01657eed18ccf9c9973f94cf9402c0d481dcba17aa4a93dbe4db9c804e5c507fe75dc585338af6c84faa416
checksums.yaml.gz.sig CHANGED
Binary file
data/bin/manga_fetch CHANGED
@@ -7,5 +7,8 @@ $verbose = true
7
7
  m = ARGV[1].match(/\A(\d+)\.\.(\d+)\Z/)
8
8
  nums = m[1].to_i .. m[2].to_i
9
9
 
10
- list = MangaFetch.fetch(name: ARGV[0], num: nums)
10
+ list = MangaFetch.fetch(name: ARGV[0], num: nums).flatten.sort
11
+
12
+ puts
11
13
  puts list
14
+ list.each{|image| MangaFetch.download_image(src: image)}
@@ -0,0 +1,12 @@
1
+ module MangaFetch::Downloader
2
+ extend self
3
+
4
+ def download_image(src: nil, prefix: "/tmp")
5
+ image = @agent.get src
6
+ path = File.expand_path image.uri.to_s.split("/")[-3..-1].join("/"), prefix
7
+ Dir.mkdir File.expand_path image.uri.to_s.split("/")[-3..-3].join("/"), prefix rescue nil
8
+ Dir.mkdir File.expand_path image.uri.to_s.split("/")[-3..-2].join("/"), prefix rescue nil
9
+ File.write path, image.body
10
+ STDERR.puts "File [".blue + path.yellow + "] saved"
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ module MangaFetch::Fetcher
2
+ extend self
3
+
4
+ # Fetch some pages form the manga named like `name`
5
+ def fetch(name: "berserk", num: nil)
6
+ init_agent("http://www.mangareader.net/#{name}")
7
+
8
+ images = if num.is_a? Fixnum
9
+ [ fetch_one(num) ]
10
+ elsif num.is_a? Enumerable
11
+ fetch_list(num)
12
+ end
13
+ end
14
+
15
+ def init_agent(url)
16
+ @agent = Mechanize.new
17
+ @agent.get url
18
+ @main = @agent.page
19
+ end
20
+
21
+ def fetch_one(num: 1)
22
+ link = "#{@main.uri.to_s}/#{num}"
23
+ STDERR.puts "Fetching Tome [".blue + "#{num}".yellow + "]".blue if $verbose
24
+ first_page = @agent.get(link)
25
+
26
+ last_page_num = first_page.at("#selectpage").text.split.last.to_i
27
+ (1..last_page_num).map do |i|
28
+ STDERR.puts "Fetching Tome [".blue + "#{num}".yellow + "] Image [".blue + "#{i} / #{last_page_num}".yellow + "]".blue if $verbose
29
+ current_page = @agent.get "#{first_page.uri.to_s}/#{i}"
30
+ image = current_page.at("#img")[:src]
31
+ STDERR.puts "-> ".blue + image.red if $verbose
32
+ image
33
+ end
34
+
35
+ end
36
+
37
+ def fetch_list(nums)
38
+ ones = []
39
+ nums.map{|num| ones << fetch_one(num: 1) } # , threads: 4
40
+ ones
41
+ end
42
+ end
data/lib/manga_fetch.rb CHANGED
@@ -2,42 +2,13 @@ require "mechanize"
2
2
  require "colorize"
3
3
 
4
4
  module MangaFetch
5
- extend self
6
-
7
- # Fetch some pages form the manga named like `name`
8
- def fetch(name: "berserk", num: nil)
9
- init_agent("http://www.mangareader.net/#{name}")
10
-
11
- images = if num.is_a? Fixnum
12
- [ fetch_one(num) ]
13
- elsif num.is_a? Enumerable
14
- fetch_list(num)
15
- end
16
- end
17
-
18
- def init_agent(url)
19
- @agent = Mechanize.new
20
- @agent.get url
21
- @main = @agent.page
22
- end
23
-
24
- def fetch_one(num)
25
- # links = @main.search("#listing td a").map{|e| e[:href]}
26
- # link = links.find{|e| e.split("/").last == num.to_s}
27
- link = "#{@main.uri.to_s}/#{num}"
28
- STDERR.puts "Fetching Tome [".blue + "#{num}".yellow + "]".blue if $verbose
29
- first_page = @agent.get(link)
5
+ end
30
6
 
31
- last_page_num = first_page.at("#selectpage").text.split.last.to_i
32
- (1..last_page_num).map do |i|
33
- STDERR.puts "Fetching Image [".blue + "#{i} / #{last_page_num}".yellow + "]".blue if $verbose
34
- current_page = @agent.get "#{first_page.uri.to_s}/#{i}"
35
- image = current_page.at("#img")[:src]
36
- STDERR.puts "-> ".blue + image.red if $verbose
37
- end
38
- end
7
+ require_relative "manga_fetch/downloader"
8
+ require_relative "manga_fetch/fetcher"
39
9
 
40
- def fetch_list(nums)
41
- nums.map{|num| fetch_one(num)}
42
- end
10
+ module MangaFetch
11
+ include Downloader
12
+ include Fetcher
13
+ extend self
43
14
  end
data.tar.gz.sig CHANGED
@@ -1 +1,3 @@
1
- ��4����a�U����[���.(��9��5n��b�����%�XԹ̻V�0�=+��œ���9�"�W�L��3�)#/.h�a/�F=�TX�_�� *�0g��>�Yt7|���fb�x^������5Ye�c�t ��L1�*�̯���Ԟ8�����6��k(�A�%�:���qv�Y?a�%L�����`Q w��u�� ^%�+�q*�;�Ml-���RF��Y��}^�,�ׇIt1��;P��Ϣ�"
1
+ �=쳄A�W�t?Q�`��1-�,~���r��)n���<+����5�*��}�
2
+ |��ìx��������# VA���+}0 o�))~�ʧږA�X�򧪓8�|��T�~�**5fd��%��y����<�˞�X��E��v*^N�?Ć��|l��aŢ~��W�l��Fz���Uc�#mj� �J
3
+ �R�F��=�8�L'/:��R�J9L�s���=[;����Mg��K�r�]��?�Y3�4FB9��n_C#�
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manga_fetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Poulet
@@ -93,7 +93,7 @@ dependencies:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: 2.7.5
96
- description: manga_fetch is a gem to download a manga
96
+ description: add multi-thread and advanced features (download, opt parsing, ...)
97
97
  email: arthur.poulet@mailoo.org
98
98
  executables:
99
99
  - manga_fetch
@@ -105,6 +105,8 @@ files:
105
105
  - README.md
106
106
  - bin/manga_fetch
107
107
  - lib/manga_fetch.rb
108
+ - lib/manga_fetch/downloader.rb
109
+ - lib/manga_fetch/fetcher.rb
108
110
  homepage: http://rubygems.org/gems/manga_fetch
109
111
  licenses:
110
112
  - WTFPL
metadata.gz.sig CHANGED
Binary file