nhentai-api 0.1.3 → 0.2.0
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 +161 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8056e30327e8ad7dd214acbd23a73b0898bda87daf17fbcdc0ec1bb3b3fb5084
|
4
|
+
data.tar.gz: a7d647dadb32275444c83a734113555969e4d55e17269002c1c3874b24c49b60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 262a7875d02e1e0ae90042d5e2cc23a01a7c16dba4ed807e43fdab2054f2ef2ac01a8400340f9ada475d0e46a4a5c97e36cfe894d6cf44b3bd81cc32d6aa3d77
|
7
|
+
data.tar.gz: 995ee6712f274ff77d9ce8baf557d26f0d333afcdb2cc6c2d007fdc13461056a0c22fe131f608ae19ec26c3cfb2c8c8a8e7ec30df40c676abb1181ee5f7b37ea
|
data/lib/nhentai-api.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'time'
|
3
3
|
|
4
|
-
class
|
4
|
+
class Info
|
5
5
|
attr_reader :id, :name, :count, :url
|
6
6
|
|
7
7
|
def initialize(id, name, count, url)
|
@@ -18,8 +18,10 @@ class Doujinshi
|
|
18
18
|
def initialize(id)
|
19
19
|
@id = id
|
20
20
|
@client = Net::HTTP.get_response(URI("https://nhentai.net/g/#{@id}/"))
|
21
|
-
|
22
|
-
|
21
|
+
if self.exists?
|
22
|
+
@media_id = @client.body.match(%r{\/([0-9]+)\/cover.jpg})[1]
|
23
|
+
@count_pages = @client.body.match(/([0-9]+) pages/)[1].to_i
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
#
|
@@ -31,7 +33,7 @@ class Doujinshi
|
|
31
33
|
# doujinshi.exists? #=> true
|
32
34
|
#
|
33
35
|
def exists?
|
34
|
-
@client.code == 200
|
36
|
+
@client.code == '200'
|
35
37
|
end
|
36
38
|
|
37
39
|
#
|
@@ -183,6 +185,7 @@ class Doujinshi
|
|
183
185
|
#
|
184
186
|
# Give all parodies of a doujinshi
|
185
187
|
#
|
188
|
+
# @since 0.1.0
|
186
189
|
# @see Doujinshi#tags
|
187
190
|
#
|
188
191
|
def parodies
|
@@ -194,6 +197,7 @@ class Doujinshi
|
|
194
197
|
#
|
195
198
|
# Give a counter of parodies
|
196
199
|
#
|
200
|
+
# @since 0.1.0
|
197
201
|
# @see Doujinshi#count_tags
|
198
202
|
#
|
199
203
|
def count_parodies
|
@@ -205,6 +209,7 @@ class Doujinshi
|
|
205
209
|
#
|
206
210
|
# Check if a particular doujinshi have some parodies
|
207
211
|
#
|
212
|
+
# @since 0.1.0
|
208
213
|
# @see Doujinshi#tags?
|
209
214
|
#
|
210
215
|
def parodies?
|
@@ -214,6 +219,7 @@ class Doujinshi
|
|
214
219
|
#
|
215
220
|
# Give all characters of a doujinshi
|
216
221
|
#
|
222
|
+
# @since 0.1.0
|
217
223
|
# @see Doujinshi#tags
|
218
224
|
#
|
219
225
|
def characters
|
@@ -225,6 +231,7 @@ class Doujinshi
|
|
225
231
|
#
|
226
232
|
# Give a counter of characters
|
227
233
|
#
|
234
|
+
# @since 0.1.0
|
228
235
|
# @see Doujinshi#count_tags
|
229
236
|
#
|
230
237
|
def count_characters
|
@@ -236,6 +243,7 @@ class Doujinshi
|
|
236
243
|
#
|
237
244
|
# Check if a particular doujinshi have some characters
|
238
245
|
#
|
246
|
+
# @since 0.1.0
|
239
247
|
# @see Doujinshi#tags?
|
240
248
|
#
|
241
249
|
def characters?
|
@@ -245,6 +253,7 @@ class Doujinshi
|
|
245
253
|
#
|
246
254
|
# Give all artists of a doujinshi
|
247
255
|
#
|
256
|
+
# @since 0.1.0
|
248
257
|
# @see Doujinshi#tags
|
249
258
|
#
|
250
259
|
def artists
|
@@ -256,6 +265,7 @@ class Doujinshi
|
|
256
265
|
#
|
257
266
|
# Give a counter of artists
|
258
267
|
#
|
268
|
+
# @since 0.1.0
|
259
269
|
# @see Doujinshi#count_tags
|
260
270
|
#
|
261
271
|
def count_artists
|
@@ -267,6 +277,7 @@ class Doujinshi
|
|
267
277
|
#
|
268
278
|
# Check if a particular doujinshi have some artists
|
269
279
|
#
|
280
|
+
# @since 0.1.0
|
270
281
|
# @see Doujinshi#tags?
|
271
282
|
#
|
272
283
|
def artists?
|
@@ -276,6 +287,7 @@ class Doujinshi
|
|
276
287
|
#
|
277
288
|
# Give all groups of a doujinshi
|
278
289
|
#
|
290
|
+
# @since 0.1.0
|
279
291
|
# @see Doujinshi#tags
|
280
292
|
#
|
281
293
|
def groups
|
@@ -287,6 +299,7 @@ class Doujinshi
|
|
287
299
|
#
|
288
300
|
# Give a counter of groups
|
289
301
|
#
|
302
|
+
# @since 0.1.0
|
290
303
|
# @see Doujinshi#count_tags
|
291
304
|
#
|
292
305
|
def count_groups
|
@@ -298,6 +311,7 @@ class Doujinshi
|
|
298
311
|
#
|
299
312
|
# Check if a particular doujinshi have some groups
|
300
313
|
#
|
314
|
+
# @since 0.1.0
|
301
315
|
# @see Doujinshi#tags?
|
302
316
|
#
|
303
317
|
def groups?
|
@@ -307,6 +321,7 @@ class Doujinshi
|
|
307
321
|
#
|
308
322
|
# Give all languages of a doujinshi
|
309
323
|
#
|
324
|
+
# @since 0.1.0
|
310
325
|
# @see Doujinshi#tags
|
311
326
|
#
|
312
327
|
def languages
|
@@ -318,6 +333,7 @@ class Doujinshi
|
|
318
333
|
#
|
319
334
|
# Give a counter of languages
|
320
335
|
#
|
336
|
+
# @since 0.1.0
|
321
337
|
# @see Doujinshi#count_tags
|
322
338
|
#
|
323
339
|
def count_languages
|
@@ -329,6 +345,7 @@ class Doujinshi
|
|
329
345
|
#
|
330
346
|
# Check if a particular doujinshi have some languages
|
331
347
|
#
|
348
|
+
# @since 0.1.0
|
332
349
|
# @see Doujinshi#tags?
|
333
350
|
#
|
334
351
|
def languages?
|
@@ -338,6 +355,7 @@ class Doujinshi
|
|
338
355
|
#
|
339
356
|
# Give all categories of a doujinshi
|
340
357
|
#
|
358
|
+
# @since 0.1.0
|
341
359
|
# @see Doujinshi#tags
|
342
360
|
#
|
343
361
|
def categories
|
@@ -349,6 +367,7 @@ class Doujinshi
|
|
349
367
|
#
|
350
368
|
# Give a counter of categories
|
351
369
|
#
|
370
|
+
# @since 0.1.0
|
352
371
|
# @see Doujinshi#count_tags
|
353
372
|
#
|
354
373
|
def count_categories
|
@@ -360,6 +379,7 @@ class Doujinshi
|
|
360
379
|
#
|
361
380
|
# Check if a particular doujinshi have some categories
|
362
381
|
#
|
382
|
+
# @since 0.1.0
|
363
383
|
# @see Doujinshi#tags?
|
364
384
|
#
|
365
385
|
def categories?
|
@@ -379,7 +399,143 @@ class Doujinshi
|
|
379
399
|
count = line.match(/\((.+?)\)</)[1].tr(',', '').to_i
|
380
400
|
url = line.match(/href=\"(.+?)\"/)[1]
|
381
401
|
|
382
|
-
|
402
|
+
Info.new(id, name, count, url)
|
383
403
|
end
|
384
404
|
end
|
385
405
|
end
|
406
|
+
|
407
|
+
class Tag
|
408
|
+
#
|
409
|
+
# List all doujinshi of the page of a given tag
|
410
|
+
#
|
411
|
+
# @param [String] keyword of the research
|
412
|
+
# @param [Integer] sort optional, 1 is sorting by time, 2 is by popularity
|
413
|
+
# @param [Integer] page each page can return 25 doujinshi
|
414
|
+
# @return [Array] array of Info
|
415
|
+
# @since 0.2.0
|
416
|
+
#
|
417
|
+
def self.listing(keyword, sort = 1, page = 1)
|
418
|
+
keyword.tr!(' ', '-')
|
419
|
+
sort = sort == 1 ? '' : 'popular'
|
420
|
+
client = Net::HTTP.get_response(URI("https://nhentai.net/tag/#{keyword}/#{sort}?page=#{page}"))
|
421
|
+
res = client.body.split(%r{<div class="gallery".+?>(.+)</div>}).select { |line| line.include?('<a href="/g/') }
|
422
|
+
|
423
|
+
parse_tags(res)
|
424
|
+
end
|
425
|
+
|
426
|
+
#
|
427
|
+
# @private
|
428
|
+
#
|
429
|
+
def self.parse_tags(res)
|
430
|
+
res.map do |line|
|
431
|
+
id = line.match(%r{/g/(\d+)/})[1]
|
432
|
+
name = line.match(%r{<div class="caption">(.+)</div>})[1].strip
|
433
|
+
count = 1
|
434
|
+
url = "/g/#{id}"
|
435
|
+
|
436
|
+
Info.new(id, name, count, url)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
class Parody < Tag
|
442
|
+
#
|
443
|
+
# List all doujinshi of the page of a given parody
|
444
|
+
#
|
445
|
+
# @since 0.2.0
|
446
|
+
# @see Tag#listing
|
447
|
+
#
|
448
|
+
def self.listing(keyword, sort = 1, page = 1)
|
449
|
+
keyword.tr!(' ', '-')
|
450
|
+
sort = sort == 1 ? '' : 'popular'
|
451
|
+
client = Net::HTTP.get_response(URI("https://nhentai.net/parody/#{keyword}/#{sort}?page=#{page}"))
|
452
|
+
res = client.body.split(%r{<div class="gallery".+?>(.+)</div>}).select { |line| line.include?('<a href="/g/') }
|
453
|
+
|
454
|
+
parse_tags(res)
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
class Character < Tag
|
459
|
+
#
|
460
|
+
# List all doujinshi of the page of a given character
|
461
|
+
#
|
462
|
+
# @since 0.2.0
|
463
|
+
# @see Tag#listing
|
464
|
+
#
|
465
|
+
def self.listing(keyword, sort = 1, page = 1)
|
466
|
+
keyword.tr!(' ', '-')
|
467
|
+
sort = sort == 1 ? '' : 'popular'
|
468
|
+
client = Net::HTTP.get_response(URI("https://nhentai.net/character/#{keyword}/#{sort}?page=#{page}"))
|
469
|
+
res = client.body.split(%r{<div class="gallery".+?>(.+)</div>}).select { |line| line.include?('<a href="/g/') }
|
470
|
+
|
471
|
+
parse_tags(res)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
class Artist < Tag
|
476
|
+
#
|
477
|
+
# List all doujinshi of the page of a given artists
|
478
|
+
#
|
479
|
+
# @since 0.2.0
|
480
|
+
# @see Tag#listing
|
481
|
+
#
|
482
|
+
def self.listing(keyword, sort = 1, page = 1)
|
483
|
+
keyword.tr!(' ', '-')
|
484
|
+
sort = sort == 1 ? '' : 'popular'
|
485
|
+
client = Net::HTTP.get_response(URI("https://nhentai.net/artist/#{keyword}/#{sort}?page=#{page}"))
|
486
|
+
res = client.body.split(%r{<div class="gallery".+?>(.+)</div>}).select { |line| line.include?('<a href="/g/') }
|
487
|
+
|
488
|
+
parse_tags(res)
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
class Group < Tag
|
493
|
+
#
|
494
|
+
# List all doujinshi of the page of a given group
|
495
|
+
#
|
496
|
+
# @since 0.2.0
|
497
|
+
# @see Tag#listing
|
498
|
+
#
|
499
|
+
def self.listing(keyword, sort = 1, page = 1)
|
500
|
+
keyword.tr!(' ', '-')
|
501
|
+
sort = sort == 1 ? '' : 'popular'
|
502
|
+
client = Net::HTTP.get_response(URI("https://nhentai.net/group/#{keyword}/#{sort}?page=#{page}"))
|
503
|
+
res = client.body.split(%r{<div class="gallery".+?>(.+)</div>}).select { |line| line.include?('<a href="/g/') }
|
504
|
+
|
505
|
+
parse_tags(res)
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
class Language < Tag
|
510
|
+
#
|
511
|
+
# List all doujinshi of the page of a given language
|
512
|
+
#
|
513
|
+
# @since 0.2.0
|
514
|
+
# @see Tag#listing
|
515
|
+
#
|
516
|
+
def self.listing(keyword, sort = 1, page = 1)
|
517
|
+
keyword.tr!(' ', '-')
|
518
|
+
sort = sort == 1 ? '' : 'popular'
|
519
|
+
client = Net::HTTP.get_response(URI("https://nhentai.net/language/#{keyword}/#{sort}?page=#{page}"))
|
520
|
+
res = client.body.split(%r{<div class="gallery".+?>(.+)</div>}).select { |line| line.include?('<a href="/g/') }
|
521
|
+
|
522
|
+
parse_tags(res)
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
class Category < Tag
|
527
|
+
#
|
528
|
+
# List all doujinshi of the page of a given category
|
529
|
+
#
|
530
|
+
# @since 0.2.0
|
531
|
+
# @see Tag#listing
|
532
|
+
#
|
533
|
+
def self.listing(keyword, sort = 1, page = 1)
|
534
|
+
keyword.tr!(' ', '-')
|
535
|
+
sort = sort == 1 ? '' : 'popular'
|
536
|
+
client = Net::HTTP.get_response(URI("https://nhentai.net/category/#{keyword}/#{sort}?page=#{page}"))
|
537
|
+
res = client.body.split(%r{<div class="gallery".+?>(.+)</div>}).select { |line| line.include?('<a href="/g/') }
|
538
|
+
|
539
|
+
parse_tags(res)
|
540
|
+
end
|
541
|
+
end
|