nhentai-api 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/lib/nhentai-api.rb +188 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c1d2af5a707f481936b165eaab28e468171bd8cca14bbf9f789e0584b963bd0
|
4
|
+
data.tar.gz: 32b78d952a702970a62a4b5bc482ee813b601cc382f47af494aa22a44ab4be1d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 485117e02f52c68efcbcef1bf08350094bd306a11b1a59e3a9ed62ccab09f94f77c1e3602be5301e4b5757ad5ae850db69c0a6abf7fc8a448acae5365a39f31c
|
7
|
+
data.tar.gz: 8511d9744a7fac17c944028d62381ed953711b17e63ab2c4b6316b5f1439a1bd1522145677f1ac0bdb65df408f455e613f857c7fa836eacfec4b095bafa65856
|
data/lib/nhentai-api.rb
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class Tag
|
4
|
+
attr_reader :id, :name, :count, :url
|
5
|
+
|
6
|
+
def initialize(id, name, count, url)
|
7
|
+
@id = id
|
8
|
+
@name = name
|
9
|
+
@count = count
|
10
|
+
@url = url
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Doujinshi
|
15
|
+
attr_reader :id, :client, :media_id, :count_pages
|
16
|
+
|
17
|
+
def initialize(id)
|
18
|
+
@id = id
|
19
|
+
@client = Net::HTTP.get_response(URI("https://nhentai.net/g/#{@id}/"))
|
20
|
+
@media_id = @client.body.match(%r{\/([0-9]+)\/cover.jpg})[1]
|
21
|
+
@count_pages = @client.body.match(/([0-9]+) pages/)[1].to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def exists?
|
25
|
+
@client.code == 200
|
26
|
+
end
|
27
|
+
|
28
|
+
def title
|
29
|
+
@client.body.match(%r{<div id="info">\s+<h1>(.+)<\/h1>})[1]
|
30
|
+
end
|
31
|
+
|
32
|
+
def cover
|
33
|
+
"https://t.nhentai.net/galleries/#{@media_id}/cover.jpg"
|
34
|
+
end
|
35
|
+
|
36
|
+
def page(page = 1)
|
37
|
+
res = @client.body.match(%r{https://t.nhentai.net/galleries/#{@media_id}/#{page}t\.(.{3})"})
|
38
|
+
|
39
|
+
"https://i.nhentai.net/galleries/#{@media_id}/#{page}.#{res[1]}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def pages
|
43
|
+
(1..@count_pages).map { |page| page(page) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def thumbnail(page = 1)
|
47
|
+
res = @client.body.match(%r{https://t.nhentai.net/galleries/#{@media_id}/(#{page}t\..{3})"})
|
48
|
+
|
49
|
+
"https://t.nhentai.net/galleries/#{@media_id}/#{res[1]}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def thumbnails
|
53
|
+
(1..@count_pages).map { |page| thumbnail(page) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def num_favorites
|
57
|
+
regex = %r{<span>Favorite <span class="nobold">.(\d+).<\/span><\/span>}
|
58
|
+
|
59
|
+
@client.body.match(regex)[1].to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
def upload_date
|
63
|
+
Time.parse(@client.body.match(/datetime="(.+)"/)[1])
|
64
|
+
end
|
65
|
+
|
66
|
+
def parse_tags(res)
|
67
|
+
res.split(%r{<a(.+?)<\/a>}).reject(&:empty?).map do |line|
|
68
|
+
id = line.match(/tag-(\d+)/)[1]
|
69
|
+
name = line.match(/">(.+?)</)[1].strip
|
70
|
+
count = line.match(/\((.+?)\)</)[1].tr(',', '').to_i
|
71
|
+
url = line.match(/href=\"(.+?)\"/)[1]
|
72
|
+
|
73
|
+
Tag.new(id, name, count, url)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def tags
|
78
|
+
res = @client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>})
|
79
|
+
|
80
|
+
parse_tags(res[1])
|
81
|
+
end
|
82
|
+
|
83
|
+
def count_tags
|
84
|
+
res = @client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>})
|
85
|
+
|
86
|
+
res.nil? ? 0 : parse_tags(res[1]).count
|
87
|
+
end
|
88
|
+
|
89
|
+
def tags?
|
90
|
+
!@client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>}).nil?
|
91
|
+
end
|
92
|
+
|
93
|
+
def parodies
|
94
|
+
res = @client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>})
|
95
|
+
|
96
|
+
parse_tags(res[1])
|
97
|
+
end
|
98
|
+
|
99
|
+
def count_parodies
|
100
|
+
res = @client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>})
|
101
|
+
|
102
|
+
res.nil? ? 0 : parse_tags(res[1]).count
|
103
|
+
end
|
104
|
+
|
105
|
+
def parodies?
|
106
|
+
!@client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>}).nil?
|
107
|
+
end
|
108
|
+
|
109
|
+
def characters
|
110
|
+
res = @client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>})
|
111
|
+
|
112
|
+
parse_tags(res[1])
|
113
|
+
end
|
114
|
+
|
115
|
+
def count_characters
|
116
|
+
res = @client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>})
|
117
|
+
|
118
|
+
res.nil? ? 0 : parse_tags(res[1]).count
|
119
|
+
end
|
120
|
+
|
121
|
+
def characters?
|
122
|
+
!@client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>}).nil?
|
123
|
+
end
|
124
|
+
|
125
|
+
def artists
|
126
|
+
res = @client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>})
|
127
|
+
|
128
|
+
parse_tags(res[1])
|
129
|
+
end
|
130
|
+
|
131
|
+
def count_artists
|
132
|
+
res = @client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>})
|
133
|
+
|
134
|
+
res.nil? ? 0 : parse_tags(res[1]).count
|
135
|
+
end
|
136
|
+
|
137
|
+
def artists?
|
138
|
+
!@client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>}).nil?
|
139
|
+
end
|
140
|
+
|
141
|
+
def groups
|
142
|
+
res = @client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>})
|
143
|
+
|
144
|
+
parse_tags(res[1])
|
145
|
+
end
|
146
|
+
|
147
|
+
def count_groups
|
148
|
+
res = @client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>})
|
149
|
+
|
150
|
+
res.nil? ? 0 : parse_tags(res[1]).count
|
151
|
+
end
|
152
|
+
|
153
|
+
def groups?
|
154
|
+
!@client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>}).nil?
|
155
|
+
end
|
156
|
+
|
157
|
+
def languages
|
158
|
+
res = @client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>})
|
159
|
+
|
160
|
+
parse_tags(res[1])
|
161
|
+
end
|
162
|
+
|
163
|
+
def count_languages
|
164
|
+
res = @client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>})
|
165
|
+
|
166
|
+
res.nil? ? 0 : parse_tags(res[1]).count
|
167
|
+
end
|
168
|
+
|
169
|
+
def languages?
|
170
|
+
!@client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>}).nil?
|
171
|
+
end
|
172
|
+
|
173
|
+
def categories
|
174
|
+
res = @client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>})
|
175
|
+
|
176
|
+
parse_tags(res[1])
|
177
|
+
end
|
178
|
+
|
179
|
+
def count_categories
|
180
|
+
res = @client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>})
|
181
|
+
|
182
|
+
res.nil? ? 0 : parse_tags(res[1]).count
|
183
|
+
end
|
184
|
+
|
185
|
+
def categories?
|
186
|
+
!@client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>}).nil?
|
187
|
+
end
|
188
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nhentai-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gael Roussel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: nhentai-api is a basic and easy to use API for nhentai.net
|
14
|
+
email: groussel42@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/nhentai-api.rb
|
20
|
+
homepage: https://rubygems.org/gems/nhentai-api
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.0.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: nhentai-api is a basic and easy to use API for nhentai.net
|
43
|
+
test_files: []
|