nhentai-api 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nhentai-api.rb +210 -15
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8dd0b6a81d6a3cb6ca3b9ad1327d4753d60fa0a742692f23ef297cf190f1422
|
4
|
+
data.tar.gz: 8f145277e1338775784dd3b297cd747a67ca2257df8012d0353d81993eff338d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 388c4685aaabad1a83f7c150f6a11ebbe2f626d249ef8e355773862e33e5f47ceec707f29fff6fca3bf1e9104ac9a07e4e4d1a9d11de9c8f4a566b4a60c1dea8
|
7
|
+
data.tar.gz: bbbcc5bec9476f012ce8a1c6721f7405063bfcc4bab58ddb03f1ff51dbcb8cb3cf5d5f1f7180e4229632654205f1c906a9d3d7cf3592cc144ebd82a532cca49f
|
data/lib/nhentai-api.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'time'
|
3
|
-
require 'pp'
|
4
3
|
|
5
4
|
class Tag
|
6
5
|
attr_reader :id, :name, :count, :url
|
@@ -14,177 +13,373 @@ class Tag
|
|
14
13
|
end
|
15
14
|
|
16
15
|
class Doujinshi
|
17
|
-
attr_reader :id, :client, :media_id, :
|
16
|
+
attr_reader :id, :client, :media_id, :count_pages
|
18
17
|
|
19
18
|
def initialize(id)
|
20
19
|
@id = id
|
21
20
|
@client = Net::HTTP.get_response(URI("https://nhentai.net/g/#{@id}/"))
|
22
21
|
@media_id = @client.body.match(%r{\/([0-9]+)\/cover.jpg})[1]
|
23
|
-
@
|
22
|
+
@count_pages = @client.body.match(/([0-9]+) pages/)[1].to_i
|
24
23
|
end
|
25
24
|
|
25
|
+
#
|
26
|
+
# Check if a doujinshi with the given id exist
|
27
|
+
#
|
28
|
+
# @return [Bool] true if the doujinshi exist, otherwise false
|
29
|
+
# @since 0.1.0
|
30
|
+
# @example
|
31
|
+
# doujinshi.exists? #=> true
|
32
|
+
#
|
26
33
|
def exists?
|
27
34
|
@client.code == 200
|
28
35
|
end
|
29
36
|
|
37
|
+
#
|
38
|
+
# Give the title of a doujinshi
|
39
|
+
#
|
40
|
+
# @return [String] the title of a given doujinshi
|
41
|
+
# @since 0.1.0
|
42
|
+
# @example
|
43
|
+
# doujinshi.title #=> '[Illumination. (Ogadenmon)] Android no Ecchi na Yatsu | Horny Androids (NieR:Automata) [English] =TLL + mrwayne= [Digital]'
|
44
|
+
#
|
30
45
|
def title
|
31
46
|
@client.body.match(%r{<div id="info">\s+<h1>(.+)<\/h1>})[1]
|
32
47
|
end
|
33
48
|
|
49
|
+
#
|
50
|
+
# Give the cover's URL of a doujinshi
|
51
|
+
#
|
52
|
+
# @return [String] the cover's URL of a given doujinshi
|
53
|
+
# @since 0.1.0
|
54
|
+
# @example
|
55
|
+
# doujinshi.cover #=> 'https://t.nhentai.net/galleries/1170172/cover.jpg'
|
56
|
+
#
|
34
57
|
def cover
|
35
58
|
"https://t.nhentai.net/galleries/#{@media_id}/cover.jpg"
|
36
59
|
end
|
37
60
|
|
61
|
+
#
|
62
|
+
# Give the URL of a given page of a doujinshi
|
63
|
+
#
|
64
|
+
# @param [Integer] page a particular page of a doujinshi
|
65
|
+
# @return [String] the URL of a given page of a doujinshi
|
66
|
+
# @since 0.1.0
|
67
|
+
# @example
|
68
|
+
# doujinshi.get_page #=> 'https://i.nhentai.net/galleries/1170172/1.jpg'
|
69
|
+
# doujinshi.get_page(10) #=> 'https://i.nhentai.net/galleries/1170172/10.jpg'
|
70
|
+
#
|
38
71
|
def page(page = 1)
|
39
72
|
res = @client.body.match(%r{https://t.nhentai.net/galleries/#{@media_id}/#{page}t\.(.{3})"})
|
40
73
|
|
41
74
|
"https://i.nhentai.net/galleries/#{@media_id}/#{page}.#{res[1]}"
|
42
75
|
end
|
43
76
|
|
77
|
+
#
|
78
|
+
# Give the URL of a all pages of a doujinshi
|
79
|
+
#
|
80
|
+
# @return [Array] array pages' URL
|
81
|
+
# @since 0.1.0
|
82
|
+
# @example
|
83
|
+
# doujinshi.pages #=> ['https://i.nhentai.net/galleries/1170172/1.jpg', ..., 'https://i.nhentai.net/galleries/1170172/31.jpg']
|
84
|
+
#
|
44
85
|
def pages
|
45
86
|
(1..@count_pages).map { |page| page(page) }
|
46
87
|
end
|
47
88
|
|
89
|
+
#
|
90
|
+
# Give the thumbnail's URL of a given page of a doujinshi
|
91
|
+
#
|
92
|
+
# @param [Integer] page a particular page of a doujinshi
|
93
|
+
# @return [String] the thumbnail's URL of a given page of a doujinshi
|
94
|
+
# @since 0.1.0
|
95
|
+
# @example
|
96
|
+
# doujinshi.get_thumbnail #=> 'https://t.nhentai.net/galleries/1170172/1t.jpg'
|
97
|
+
# doujinshi.get_thumbnail(10) #=> 'https://t.nhentai.net/galleries/1170172/10t.jpg'
|
98
|
+
#
|
48
99
|
def thumbnail(page = 1)
|
49
100
|
res = @client.body.match(%r{https://t.nhentai.net/galleries/#{@media_id}/(#{page}t\..{3})"})
|
50
101
|
|
51
102
|
"https://t.nhentai.net/galleries/#{@media_id}/#{res[1]}"
|
52
103
|
end
|
53
104
|
|
105
|
+
#
|
106
|
+
# Give the URL of a all thumbnails of a doujinshi
|
107
|
+
#
|
108
|
+
# @return [Array] an array thumbnails' URL
|
109
|
+
# @since 0.1.0
|
110
|
+
# @example
|
111
|
+
# doujinshi.thumbnails #=> ['https://t.nhentai.net/galleries/1170172/1t.jpg',..., 'https://t.nhentai.net/galleries/1170172/31t.jpg']
|
112
|
+
#
|
54
113
|
def thumbnails
|
55
114
|
(1..@count_pages).map { |page| thumbnail(page) }
|
56
115
|
end
|
57
116
|
|
58
|
-
|
117
|
+
#
|
118
|
+
# Give the number of favorites on a doujinshi
|
119
|
+
#
|
120
|
+
# @return [Integer] a counter of favorites on a given doujinshi
|
121
|
+
# @since 0.1.0
|
122
|
+
# @example
|
123
|
+
# doujinshi.num_favorites #=> 13326
|
124
|
+
#
|
125
|
+
def count_favorites
|
59
126
|
regex = %r{<span>Favorite <span class="nobold">.(\d+).<\/span><\/span>}
|
60
127
|
|
61
128
|
@client.body.match(regex)[1].to_i
|
62
129
|
end
|
63
130
|
|
131
|
+
#
|
132
|
+
# Give the upload date of a doujinshi
|
133
|
+
#
|
134
|
+
# @return [Integer] the upload date of a given doujinshi
|
135
|
+
# @since 0.1.0
|
136
|
+
# @example
|
137
|
+
# doujinshi.upload_date #=> 2018-01-17 15:56:16 +0000
|
138
|
+
#
|
64
139
|
def upload_date
|
65
140
|
Time.iso8601(@client.body.match(/datetime="(.+)"/)[1])
|
66
141
|
end
|
67
142
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
143
|
+
#
|
144
|
+
# Give all tags of a doujinshi
|
145
|
+
#
|
146
|
+
# @return [Array] of Tag class of a given doujinshi
|
147
|
+
# @since 0.1.0
|
148
|
+
# @example
|
149
|
+
# doujinshi.tags
|
150
|
+
#
|
79
151
|
def tags
|
80
152
|
res = @client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>})
|
81
153
|
|
82
154
|
parse_tags(res[1])
|
83
155
|
end
|
84
156
|
|
157
|
+
#
|
158
|
+
# Give a counter of tags
|
159
|
+
#
|
160
|
+
# @return [Integer] of tags
|
161
|
+
# @since 0.1.0
|
162
|
+
# @example
|
163
|
+
# doujinshi.count_tags #=> 9
|
164
|
+
#
|
85
165
|
def count_tags
|
86
166
|
res = @client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>})
|
87
167
|
|
88
168
|
res.nil? ? 0 : parse_tags(res[1]).length
|
89
169
|
end
|
90
170
|
|
171
|
+
#
|
172
|
+
# Check if a particular doujinshi have some tags
|
173
|
+
#
|
174
|
+
# @return [Bool] true if the doujinshi have tags, otherwise false
|
175
|
+
# @since 0.1.0
|
176
|
+
# @example
|
177
|
+
# doujinshi.tags? #=> true
|
178
|
+
#
|
91
179
|
def tags?
|
92
180
|
!@client.body.match(%r{Tags:\s*<span class="tags">(.+)<\/span>}).nil?
|
93
181
|
end
|
94
182
|
|
183
|
+
#
|
184
|
+
# Give all parodies of a doujinshi
|
185
|
+
#
|
186
|
+
# @see Doujinshi#tags
|
187
|
+
#
|
95
188
|
def parodies
|
96
189
|
res = @client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>})
|
97
190
|
|
98
191
|
parse_tags(res[1])
|
99
192
|
end
|
100
193
|
|
194
|
+
#
|
195
|
+
# Give a counter of parodies
|
196
|
+
#
|
197
|
+
# @see Doujinshi#count_tags
|
198
|
+
#
|
101
199
|
def count_parodies
|
102
200
|
res = @client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>})
|
103
201
|
|
104
202
|
res.nil? ? 0 : parse_tags(res[1]).length
|
105
203
|
end
|
106
204
|
|
205
|
+
#
|
206
|
+
# Check if a particular doujinshi have some parodies
|
207
|
+
#
|
208
|
+
# @see Doujinshi#tags?
|
209
|
+
#
|
107
210
|
def parodies?
|
108
211
|
!@client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>}).nil?
|
109
212
|
end
|
110
213
|
|
214
|
+
#
|
215
|
+
# Give all characters of a doujinshi
|
216
|
+
#
|
217
|
+
# @see Doujinshi#tags
|
218
|
+
#
|
111
219
|
def characters
|
112
220
|
res = @client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>})
|
113
221
|
|
114
222
|
parse_tags(res[1])
|
115
223
|
end
|
116
224
|
|
225
|
+
#
|
226
|
+
# Give a counter of characters
|
227
|
+
#
|
228
|
+
# @see Doujinshi#count_tags
|
229
|
+
#
|
117
230
|
def count_characters
|
118
231
|
res = @client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>})
|
119
232
|
|
120
233
|
res.nil? ? 0 : parse_tags(res[1]).length
|
121
234
|
end
|
122
235
|
|
236
|
+
#
|
237
|
+
# Check if a particular doujinshi have some characters
|
238
|
+
#
|
239
|
+
# @see Doujinshi#tags?
|
240
|
+
#
|
123
241
|
def characters?
|
124
242
|
!@client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>}).nil?
|
125
243
|
end
|
126
244
|
|
245
|
+
#
|
246
|
+
# Give all artists of a doujinshi
|
247
|
+
#
|
248
|
+
# @see Doujinshi#tags
|
249
|
+
#
|
127
250
|
def artists
|
128
251
|
res = @client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>})
|
129
252
|
|
130
253
|
parse_tags(res[1])
|
131
254
|
end
|
132
255
|
|
256
|
+
#
|
257
|
+
# Give a counter of artists
|
258
|
+
#
|
259
|
+
# @see Doujinshi#count_tags
|
260
|
+
#
|
133
261
|
def count_artists
|
134
262
|
res = @client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>})
|
135
263
|
|
136
264
|
res.nil? ? 0 : parse_tags(res[1]).length
|
137
265
|
end
|
138
266
|
|
267
|
+
#
|
268
|
+
# Check if a particular doujinshi have some artists
|
269
|
+
#
|
270
|
+
# @see Doujinshi#tags?
|
271
|
+
#
|
139
272
|
def artists?
|
140
273
|
!@client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>}).nil?
|
141
274
|
end
|
142
275
|
|
276
|
+
#
|
277
|
+
# Give all groups of a doujinshi
|
278
|
+
#
|
279
|
+
# @see Doujinshi#tags
|
280
|
+
#
|
143
281
|
def groups
|
144
282
|
res = @client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>})
|
145
283
|
|
146
284
|
parse_tags(res[1])
|
147
285
|
end
|
148
286
|
|
287
|
+
#
|
288
|
+
# Give a counter of groups
|
289
|
+
#
|
290
|
+
# @see Doujinshi#count_tags
|
291
|
+
#
|
149
292
|
def count_groups
|
150
293
|
res = @client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>})
|
151
294
|
|
152
295
|
res.nil? ? 0 : parse_tags(res[1]).length
|
153
296
|
end
|
154
297
|
|
298
|
+
#
|
299
|
+
# Check if a particular doujinshi have some groups
|
300
|
+
#
|
301
|
+
# @see Doujinshi#tags?
|
302
|
+
#
|
155
303
|
def groups?
|
156
304
|
!@client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>}).nil?
|
157
305
|
end
|
158
306
|
|
307
|
+
#
|
308
|
+
# Give all languages of a doujinshi
|
309
|
+
#
|
310
|
+
# @see Doujinshi#tags
|
311
|
+
#
|
159
312
|
def languages
|
160
313
|
res = @client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>})
|
161
314
|
|
162
315
|
parse_tags(res[1])
|
163
316
|
end
|
164
317
|
|
318
|
+
#
|
319
|
+
# Give a counter of languages
|
320
|
+
#
|
321
|
+
# @see Doujinshi#count_tags
|
322
|
+
#
|
165
323
|
def count_languages
|
166
324
|
res = @client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>})
|
167
325
|
|
168
326
|
res.nil? ? 0 : parse_tags(res[1]).length
|
169
327
|
end
|
170
328
|
|
329
|
+
#
|
330
|
+
# Check if a particular doujinshi have some languages
|
331
|
+
#
|
332
|
+
# @see Doujinshi#tags?
|
333
|
+
#
|
171
334
|
def languages?
|
172
335
|
!@client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>}).nil?
|
173
336
|
end
|
174
337
|
|
338
|
+
#
|
339
|
+
# Give all categories of a doujinshi
|
340
|
+
#
|
341
|
+
# @see Doujinshi#tags
|
342
|
+
#
|
175
343
|
def categories
|
176
344
|
res = @client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>})
|
177
345
|
|
178
346
|
parse_tags(res[1])
|
179
347
|
end
|
180
348
|
|
349
|
+
#
|
350
|
+
# Give a counter of categories
|
351
|
+
#
|
352
|
+
# @see Doujinshi#count_tags
|
353
|
+
#
|
181
354
|
def count_categories
|
182
355
|
res = @client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>})
|
183
356
|
|
184
357
|
res.nil? ? 0 : parse_tags(res[1]).length
|
185
358
|
end
|
186
359
|
|
360
|
+
#
|
361
|
+
# Check if a particular doujinshi have some categories
|
362
|
+
#
|
363
|
+
# @see Doujinshi#tags?
|
364
|
+
#
|
187
365
|
def categories?
|
188
366
|
!@client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>}).nil?
|
189
367
|
end
|
368
|
+
|
369
|
+
#
|
370
|
+
# @private
|
371
|
+
#
|
372
|
+
|
373
|
+
private
|
374
|
+
|
375
|
+
def parse_tags(res)
|
376
|
+
res.split(%r{<a(.+?)<\/a>}).reject(&:empty?).map do |line|
|
377
|
+
id = line.match(/tag-(\d+)/)[1]
|
378
|
+
name = line.match(/">(.+?)</)[1].strip
|
379
|
+
count = line.match(/\((.+?)\)</)[1].tr(',', '').to_i
|
380
|
+
url = line.match(/href=\"(.+?)\"/)[1]
|
381
|
+
|
382
|
+
Tag.new(id, name, count, url)
|
383
|
+
end
|
384
|
+
end
|
190
385
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nhentai-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gael Roussel
|
@@ -21,6 +21,7 @@ homepage: https://rubygems.org/gems/nhentai-api
|
|
21
21
|
licenses:
|
22
22
|
- MIT
|
23
23
|
metadata:
|
24
|
+
documentation_uri: https://www.rubydoc.info/github/groussel42/nhentai-api
|
24
25
|
source_code_uri: https://github.com/groussel42/nhentai-api
|
25
26
|
post_install_message:
|
26
27
|
rdoc_options: []
|