mrmanga 0.2.0 → 0.3.0

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: 2d23b801dd6ae6826240c876de94c29bdcda7162
4
- data.tar.gz: f4f27f1f5e9764905077a6deeb8c5faa99cb1e24
3
+ metadata.gz: e33e9eac4da9f4876817148f7e86a7bbfde98b98
4
+ data.tar.gz: '07975718124aca4d535f13425dd68b61ef98fa70'
5
5
  SHA512:
6
- metadata.gz: 4d001b7af719bde9ff4f6d479863d3c3d10e8303bada5206b5cc1a2e34be2144f89cfb39cb680444099181fd0ab135ffd7e03ac09a040cc37042b9c0afcd31c8
7
- data.tar.gz: 1e7c693c8193af02f27b04f9026e6836228a617efaf41606f848031c3b7593e4c871e3249f9997619c33a4ff7ec071fb4a58c972ee3a4f78fb5eaf0cfead0d96
6
+ metadata.gz: f271f43d5ad2beb5cd1a822d21f704aea46b9faf80827d6b7ca3ef7a213fa222b210663371e2d161b28dd9ec5535eef911bc0c597b6f64c678daa2952324c7ae
7
+ data.tar.gz: c03ab4a2efd9816b96a8b069ec0ac9b4da67c4956d5f46bacb21428445e98fb5499cd99fac423ea776733a7955ebea520d0c825b5819ae66f2f0ce801288512d
data/README.md CHANGED
@@ -1,16 +1,54 @@
1
1
  # mrmanga
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/mrmanga.svg)](https://badge.fury.io/rb/mrmanga)
4
+ [![Gem](https://img.shields.io/gem/dtv/mrmanga.svg)]()
5
+ [![Gemnasium](https://img.shields.io/gemnasium/4ndv/mrmanga.svg)]()
6
+
3
7
  #### Aka mintmanga/readmanga downloader
4
8
 
5
- ## Installation
9
+ ## Features
10
+
11
+ * mintmanga and readmanga support
12
+ * Automatic PDF creation with correct metadata (Title, Author, Keywords)
13
+ * Outlines in PDF (chapters/pages)
14
+ * Multithreaded download
15
+ * Download only specified volumes
16
+
17
+ ## Linux/Mac Installation
6
18
 
7
19
  $ gem install mrmanga
8
20
 
21
+ Requires Ruby 2.3+, ImageMagick (or GraphicsMagick), libxml2 (for nokogiri)
22
+
23
+ ## Windows Installation
24
+
25
+ Download and install ruby 2.4 from here: https://rubyinstaller.org/downloads/
26
+
27
+ **DONT UNCHECK ANY CHECKBOXES!**
28
+
29
+ After installation, you will be asked to install devtools, just press enter in this screen and wait.
30
+
31
+ Download and install ImageMagick from here: http://imagemagick.org/script/download.php
32
+
33
+ Open CMD and enter this command:
34
+
35
+ ```bash
36
+ $ gem install mrmanga --no-ri
37
+ ```
38
+
39
+ Now you can use it in any folder where you want to store your downloads, just simply type `mrmanga` in console and follow the instructions.
40
+
9
41
  ## Usage
10
42
 
11
43
  $ mrmanga
12
44
 
13
- And follow the instructions
45
+ And follow the instructions. By default, it will download to the folder where you runned it.
46
+
47
+ ## Future and TODOs
48
+
49
+ * EPUB generation (GEPUB) with cover selection
50
+ * More usable CLI
51
+ * Non-interactive mode
14
52
 
15
53
  ## Development
16
54
 
@@ -1,5 +1,17 @@
1
1
  module Mrmanga
2
2
  class CLI
3
+ def parse_volumes_range(string)
4
+ return 'all' if string == 'all'
5
+
6
+ if /^\d+-\d+$/ =~ string
7
+ # 13-37 syntax
8
+ a = string.split('-')
9
+ return (a[0]..a[1]).to_a
10
+ end
11
+
12
+ string.tr(' ', '').split(',').map(&:to_i)
13
+ end
14
+
3
15
  def interactive_shell
4
16
  require 'highline/import'
5
17
 
@@ -13,7 +25,30 @@ module Mrmanga
13
25
  q.validate = regex
14
26
  end
15
27
 
16
- create_pdfs = agree 'Create pdfs for volumes? (Y/n)'
28
+ # TODO: Ask for volumes to download
29
+
30
+ puts "Just press Enter to download all the volumes, or specity volumes using this: 1-5 or this: 1, 2, 3, 4, 5 (or 1,2,3,4,5) syntaxes. Also you can download one volume by entering it's number (like this: 1)"
31
+
32
+ volumes = ask('Which volumes should i download? ') { |q| q.default = 'all' }
33
+
34
+ volumes = parse_volumes_range(volumes)
35
+
36
+ puts "Will download these volumes: #{volumes.join(', ')}" if volumes != 'all'
37
+
38
+ downloader_settings = {
39
+ threads: ask('How many threads should i use to download? (6) ', Integer) { |q| q.default = 6 },
40
+ volumes: volumes
41
+ }
42
+
43
+ create_pdfs = agree('Create pdfs for volumes?') { |q| q.default = 'yes' }
44
+
45
+ pdf_settings = {
46
+ disable_outline_pages: false
47
+ }
48
+
49
+ if create_pdfs
50
+ pdf_settings[:disable_outline_pages] = !agree('Add pages in PDF outline?') { |q| q.default = 'no' }
51
+ end
17
52
 
18
53
  say 'Parsing manga info'
19
54
 
@@ -21,16 +56,14 @@ module Mrmanga
21
56
 
22
57
  say 'Parsed, downloading'
23
58
 
24
- dl = Mrmanga::Downloader.new(manga)
59
+ dl = Mrmanga::Downloader.new(manga, downloader_settings)
25
60
 
26
61
  manga.volumes.each do |vol, _|
27
- puts "Downloading volume #{vol}"
28
-
29
62
  volume = dl.download_volume(vol)
30
63
 
31
- if create_pdfs
64
+ if create_pdfs && volume
32
65
  puts "Rendering pdf of Vol.#{volume[:volume]}"
33
- Mrmanga::PdfRenderer.new(manga, volume[:volume], volume[:pages])
66
+ Mrmanga::PdfRenderer.new(manga, volume[:volume], volume[:pages], pdf_settings)
34
67
  end
35
68
  end
36
69
  end
@@ -1,18 +1,30 @@
1
1
  require 'down'
2
2
  require 'fileutils'
3
3
  require 'parallel'
4
+ require 'progressbar'
4
5
 
5
6
  module Mrmanga
6
7
  class Downloader
7
- def initialize(manga)
8
+ def initialize(manga, settings)
8
9
  @manga = manga
9
10
 
11
+ @settings = settings
12
+
10
13
  @name = @manga.info[:info][:name]
11
14
 
12
15
  raise "Folder '#{@name}' already exists" if File.directory?(@name)
13
16
  end
14
17
 
15
18
  def download_volume(volume)
19
+ if @settings[:volumes] != 'all'
20
+ unless @settings[:volumes].include?(volume)
21
+ puts "Skipping Vol. #{volume}"
22
+ return false
23
+ end
24
+ end
25
+
26
+ puts "Downloading volume #{volume}"
27
+
16
28
  prefix = "#{@name}/vol#{volume}"
17
29
 
18
30
  parser = Mrmanga::Parser.new
@@ -22,13 +34,17 @@ module Mrmanga
22
34
  downloaded = {}
23
35
 
24
36
  @manga.volumes[volume].each do |volch|
25
- puts "Downloading vol.#{volch[0]} ch.#{volch[1]}"
26
37
  pages = parser.get_chapter_pages(@manga, volch[0], volch[1])
27
38
 
28
- Parallel.each_with_index(pages, in_threads: 6) do |page, index|
29
- puts "Downloading page #{index + 1}"
39
+ progress = ProgressBar.create(title: "Downloading vol.#{volch[0]} ch.#{volch[1]}", total: pages.count)
40
+
41
+ Parallel.each_with_index(pages, in_threads: @settings[:threads]) do |page, index|
42
+ progress.increment
30
43
 
31
44
  temp = Down.download(page[:link], open_timeout: 20, read_timeout: 20)
45
+
46
+ temp.close # Windows needs this
47
+
32
48
  ext = File.extname(temp.path)
33
49
 
34
50
  new_path = File.join(prefix, "#{volch[0]} - #{volch[1]} - #{index + 1}#{ext}")
@@ -39,6 +55,8 @@ module Mrmanga
39
55
  end
40
56
 
41
57
  downloaded[volch[1]] = pages
58
+
59
+ progress.finish
42
60
  end
43
61
 
44
62
  {
@@ -14,6 +14,10 @@ module Mrmanga
14
14
  @info[:metadata] = metadata
15
15
  end
16
16
 
17
+ def add_original_chapters(orig_ch)
18
+ @info[:original_chapters] = orig_ch
19
+ end
20
+
17
21
  def volumes
18
22
  @info[:volch].group_by(&:first)
19
23
  end
@@ -21,7 +21,9 @@ module Mrmanga
21
21
 
22
22
  noko_first = Nokogiri::HTML(Faraday.get("http://#{parsed[:site]}#{first_link}?mature=1").body)
23
23
 
24
- volch = noko_first.css('#chapterSelectorSelect > option').map { |el| el.attr('value') }
24
+ volch_with_orig = noko_first.css('#chapterSelectorSelect > option').map { |el| [el.attr('value'), el.text] }
25
+
26
+ volch = volch_with_orig.map(&:first)
25
27
 
26
28
  regex_volch = /^\/[\w]+\/vol(\d+)\/(\d+).*$/
27
29
 
@@ -30,13 +32,22 @@ module Mrmanga
30
32
 
31
33
  raise "Wrong url: #{vl}" unless match
32
34
 
33
- match.to_a.drop(1)
35
+ match.to_a.drop(1).map(&:to_i)
34
36
  end
35
37
 
36
38
  volch.reverse!
37
39
 
40
+ orig_names = {}
41
+
42
+ volch.each do |item|
43
+ orig_names[item[0]] = {} unless orig_names.key?(item[0])
44
+
45
+ orig_names[item[0]][item[1]] = volch_with_orig.pop.last
46
+ end
47
+
38
48
  manga = Mrmanga::Manga.new
39
49
 
50
+ manga.add_original_chapters(orig_names)
40
51
  manga.add_info(
41
52
  site: parsed[:site],
42
53
  name: parsed[:name]
@@ -3,7 +3,7 @@ require 'mini_magick'
3
3
 
4
4
  module Mrmanga
5
5
  class PdfRenderer
6
- def initialize(manga, volume, chapters)
6
+ def initialize(manga, volume, chapters, settings)
7
7
  info = manga.info[:metadata].clone
8
8
 
9
9
  title = info[:Title]
@@ -18,7 +18,6 @@ module Mrmanga
18
18
 
19
19
  chapters.each do |ch, pages|
20
20
  puts "Chapter #{ch}"
21
-
22
21
  outline_map[ch] = []
23
22
 
24
23
  pages.each do |page|
@@ -45,15 +44,29 @@ module Mrmanga
45
44
  section info[:Title]
46
45
 
47
46
  outline_map.each do |chapter, pages|
48
- section "Chapter #{chapter}", destination: pages.first do
49
- pages.each do |page_number|
50
- page title: "Page #{page_number}", destination: page_number
47
+ section manga.info[:original_chapters][volume][chapter], destination: pages.first do
48
+ unless settings[:disable_outline_pages]
49
+ pages.each do |page_number|
50
+ page title: "Page #{page_number}", destination: page_number
51
+ end
51
52
  end
52
53
  end
53
54
  end
54
55
  end
55
56
 
56
- doc.render_file "#{manga.info[:info][:name]}/#{title} Vol. #{volume}.pdf"
57
+ # Normalize filename (may contain inappropriate chars)
58
+
59
+ # Removing non-word chars
60
+ title.gsub!(/[^[[[:word:]]| |.]+]/, '')
61
+ # Stripping spaces, dots, underscores, dashes from start and end
62
+ title.gsub!(/^[\.|_| |-]+/, '')
63
+ title.gsub!(/[\.|_| |-]+$/, '')
64
+
65
+ filename = "#{manga.info[:info][:name]}/#{title} Vol. #{volume}.pdf"
66
+
67
+ doc.render_file filename
68
+
69
+ puts "Rendered to #{filename}"
57
70
  end
58
71
  end
59
72
  end
@@ -1,3 +1,3 @@
1
1
  module Mrmanga
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'down', '~> 4.0'
29
29
  spec.add_dependency 'parallel', '~> 1.11'
30
30
  spec.add_dependency 'mini_magick', '~> 4.8'
31
+ spec.add_dependency 'progressbar', '~> 1.8'
31
32
 
32
33
  spec.add_development_dependency 'bundler', '~> 1.15'
33
34
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mrmanga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Viktorov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-21 00:00:00.000000000 Z
11
+ date: 2017-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '4.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: progressbar
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.8'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.8'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: bundler
113
127
  requirement: !ruby/object:Gem::Requirement