manga_read_man 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/README.md +120 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/manga_read_man.rb +10 -0
- data/lib/manga_read_man/manga.rb +90 -0
- data/lib/manga_read_man/version.rb +3 -0
- data/manga_read_man.gemspec +27 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a20b687d311932793d40227b204e98dabf3ee328
|
4
|
+
data.tar.gz: 8e4605e7ce5f340f35c63df9a293204322b890e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bfd573239085c4626840cec427351278c21796f6fb57201eeadb2725db564320f94b16f7c1b840070d1cfcbe41a32a2111ece6f4200bde8003d3c11daa20181
|
7
|
+
data.tar.gz: 0596af3de8e5188239b0a3eb59f868a309dde6a03db610ef2babf0759ed8926f67b014954a548da5e42a20b2723f24049bcab49e8cb2cb71511a5b02cdae25e0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# MangaReadMan
|
2
|
+
|
3
|
+
MangaReadMan is a Ruby library for extracting image urls from mangareader ( http://www.mangareader.net ).
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'manga_read_man'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install manga_read_man
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```rb
|
25
|
+
# syntax: MangaReadMan.image_urls(title, chapter)
|
26
|
+
|
27
|
+
# one chapter
|
28
|
+
MangaReadMan.image_urls('one-piece', 3)
|
29
|
+
=>[
|
30
|
+
{ 3=>[
|
31
|
+
"http://i9.mangareader.net/one-piece/3/one-piece-1668214.jpg",
|
32
|
+
"http://i1.mangareader.net/one-piece/3/one-piece-1668215.jpg",
|
33
|
+
"http://i5.mangareader.net/one-piece/3/one-piece-1668216.jpg",
|
34
|
+
...
|
35
|
+
]
|
36
|
+
}
|
37
|
+
]
|
38
|
+
|
39
|
+
# range chapter
|
40
|
+
MangaReadMan.image_urls('one-piece', 5..7)
|
41
|
+
=>[
|
42
|
+
{ 5=>[
|
43
|
+
"http://i5.mangareader.net/one-piece/5/one-piece-2420145.jpg",
|
44
|
+
"http://i7.mangareader.net/one-piece/5/one-piece-2420147.jpg",
|
45
|
+
"http://i3.mangareader.net/one-piece/5/one-piece-2420149.jpg",
|
46
|
+
...
|
47
|
+
]
|
48
|
+
},
|
49
|
+
{ 6=>[
|
50
|
+
"http://i2.mangareader.net/one-piece/6/one-piece-2420187.jpg",
|
51
|
+
"http://i4.mangareader.net/one-piece/6/one-piece-2420189.jpg",
|
52
|
+
"http://i6.mangareader.net/one-piece/6/one-piece-2420191.jpg",
|
53
|
+
...
|
54
|
+
]
|
55
|
+
},
|
56
|
+
{ 7=>[
|
57
|
+
"http://i7.mangareader.net/one-piece/7/one-piece-2420231.jpg",
|
58
|
+
"http://i7.mangareader.net/one-piece/7/one-piece-2420233.jpg",
|
59
|
+
"http://i5.mangareader.net/one-piece/7/one-piece-2420235.jpg",
|
60
|
+
...
|
61
|
+
]
|
62
|
+
}
|
63
|
+
]
|
64
|
+
|
65
|
+
# all chapter
|
66
|
+
MangaReadMan.image_urls('one-piece')
|
67
|
+
=>[
|
68
|
+
{ 1=>[
|
69
|
+
"http://i9.mangareader.net/one-piece/1/one-piece-1668160.jpg",
|
70
|
+
"http://i5.mangareader.net/one-piece/1/one-piece-1668161.jpg",
|
71
|
+
"http://i3.mangareader.net/one-piece/1/one-piece-1668162.jpg",
|
72
|
+
...
|
73
|
+
]
|
74
|
+
},
|
75
|
+
{ 2=>[
|
76
|
+
"http://i9.mangareader.net/one-piece/2/one-piece-2420099.jpg",
|
77
|
+
"http://i7.mangareader.net/one-piece/2/one-piece-2420101.jpg",
|
78
|
+
"http://i5.mangareader.net/one-piece/2/one-piece-2420103.jpg",
|
79
|
+
...
|
80
|
+
]
|
81
|
+
},
|
82
|
+
{ 3=>[
|
83
|
+
"http://i9.mangareader.net/one-piece/3/one-piece-1668214.jpg",
|
84
|
+
"http://i1.mangareader.net/one-piece/3/one-piece-1668215.jpg",
|
85
|
+
"http://i5.mangareader.net/one-piece/3/one-piece-1668216.jpg",
|
86
|
+
...
|
87
|
+
]
|
88
|
+
},
|
89
|
+
{ 4=>[
|
90
|
+
"http://i1.mangareader.net/one-piece/4/one-piece-1668229.jpg",
|
91
|
+
"http://i3.mangareader.net/one-piece/4/one-piece-1668231.jpg",
|
92
|
+
"http://i5.mangareader.net/one-piece/4/one-piece-1668233.jpg",
|
93
|
+
...
|
94
|
+
]
|
95
|
+
},
|
96
|
+
{ 5=>[
|
97
|
+
"http://i5.mangareader.net/one-piece/5/one-piece-2420145.jpg",
|
98
|
+
"http://i7.mangareader.net/one-piece/5/one-piece-2420147.jpg",
|
99
|
+
"http://i3.mangareader.net/one-piece/5/one-piece-2420149.jpg",
|
100
|
+
...
|
101
|
+
]
|
102
|
+
},
|
103
|
+
...
|
104
|
+
]
|
105
|
+
|
106
|
+
```
|
107
|
+
|
108
|
+
## Development
|
109
|
+
|
110
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
111
|
+
|
112
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
113
|
+
|
114
|
+
## Contributing
|
115
|
+
|
116
|
+
1. Fork it ( https://github.com/KoKumagai/manga_read_man/fork )
|
117
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
118
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
119
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
120
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "manga_read_man"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'anemone'
|
3
|
+
|
4
|
+
module MangaReadMan
|
5
|
+
|
6
|
+
class Manga
|
7
|
+
class TitleError < StandardError; end
|
8
|
+
class ChapterError < StandardError; end
|
9
|
+
|
10
|
+
def initialize(title, chapters)
|
11
|
+
@title = parse_title!(title)
|
12
|
+
@chapters = parse_chapters!(@title, chapters)
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
image_urls_of_each_chapter = []
|
17
|
+
@chapters.each do |chapter|
|
18
|
+
image_urls_of_each_chapter << {chapter => image_urls(@title, chapter)}
|
19
|
+
end
|
20
|
+
image_urls_of_each_chapter
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def parse_title!(title)
|
25
|
+
response = Net::HTTP.get_response(URI.parse(title_url(title)))
|
26
|
+
raise TitleError.new('invalid title: not found') if response.code == '404'
|
27
|
+
title
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_chapters!(title, chapters)
|
31
|
+
chapters = build_chapters!(title, chapters)
|
32
|
+
|
33
|
+
if !(chapters.first.is_a?(Integer) && chapters.last.is_a?(Integer))
|
34
|
+
raise ChapterError.new('invalid chapter: should be integer')
|
35
|
+
elsif !(chapters.first <= chapters.last)
|
36
|
+
raise ChapterError.new('invalid chapter: should be first <= last')
|
37
|
+
elsif !(1 <= chapters.first)
|
38
|
+
raise ChapterError.new('invalid chapter: should be 1 <= first')
|
39
|
+
elsif !(chapters.last <= max_chapter(title))
|
40
|
+
raise ChapterError.new('invalid chapter: should be last <= max chapter')
|
41
|
+
end
|
42
|
+
chapters
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_chapters!(title, chapters)
|
46
|
+
return Range.new(1, max_chapter(title)) if chapters.nil?
|
47
|
+
|
48
|
+
case chapters
|
49
|
+
when Range; chapters
|
50
|
+
when Integer; Range.new(chapters, chapters)
|
51
|
+
else raise ChapterError.new('invalid chapter: should be range, integer or nil')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def image_urls(title, chapter)
|
56
|
+
target_url = title_url(title) + "/#{chapter}/1"
|
57
|
+
skip_pattern = /\/.+-.+-1\/#{title}\/chapter-#{chapter}\.html/
|
58
|
+
focus_pattern = /\/#{title}\/#{chapter}\/.+|\/.+\/#{title}\/chapter-#{chapter}\.html/
|
59
|
+
urls = []
|
60
|
+
|
61
|
+
Anemone.crawl(target_url) do |anemone|
|
62
|
+
anemone.skip_links_like(skip_pattern)
|
63
|
+
|
64
|
+
anemone.focus_crawl do |page|
|
65
|
+
page.links.keep_if { |link| link.to_s.match(focus_pattern) }
|
66
|
+
end
|
67
|
+
|
68
|
+
anemone.on_every_page do |page|
|
69
|
+
image = page.doc.xpath('//img[@id="img"]')
|
70
|
+
urls << image.attribute('src').value unless image.empty?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
urls
|
74
|
+
end
|
75
|
+
|
76
|
+
def title_url(title)
|
77
|
+
MangaReadMan::BASE_URL + title
|
78
|
+
end
|
79
|
+
|
80
|
+
def max_chapter(title)
|
81
|
+
max = 0
|
82
|
+
doc = Nokogiri::HTML(open(title_url(title)))
|
83
|
+
doc.xpath('//div[@id="chapterlist"]/table/tr/td/a').each do |node|
|
84
|
+
href = node.attribute('href').value
|
85
|
+
max = href.split(/\//).last
|
86
|
+
end
|
87
|
+
max.to_i
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'manga_read_man/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "manga_read_man"
|
8
|
+
spec.version = MangaReadMan::VERSION
|
9
|
+
spec.authors = ["Ko Kumagai"]
|
10
|
+
spec.email = ["ko.kumagai.ko@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Get image urls from mangareader(http://www.mangareader.net)}
|
13
|
+
spec.description = %q{Get image urls from mangareader(http://www.mangareader.net)}
|
14
|
+
spec.homepage = "https://github.com/KoKumagai/manga_read_man"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "nokogiri"
|
22
|
+
spec.add_dependency "anemone"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: manga_read_man
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ko Kumagai
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: anemone
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Get image urls from mangareader(http://www.mangareader.net)
|
84
|
+
email:
|
85
|
+
- ko.kumagai.ko@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/manga_read_man.rb
|
99
|
+
- lib/manga_read_man/manga.rb
|
100
|
+
- lib/manga_read_man/version.rb
|
101
|
+
- manga_read_man.gemspec
|
102
|
+
homepage: https://github.com/KoKumagai/manga_read_man
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.5.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Get image urls from mangareader(http://www.mangareader.net)
|
125
|
+
test_files: []
|