nhentai-api 0.3 → 1.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 +32 -151
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d63124d136363e121f01218322464cde8ea037e567b73246ffdc56fde309dd0
|
4
|
+
data.tar.gz: 34796062c118c4db00bac99648af7a7be3f23d2fc5e85751e82929486235fbae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b690c41f13b19bf979c3d21ef001a4ed6d26975fe214b22c1eac0364130d9d1ba006cc4a5af6beec518c8e20cb90749bc830de2e965072699cae406c6bb5a77a
|
7
|
+
data.tar.gz: 687c9c8b048e0d16bc848111d3b6cde52339cad52b8bbcd8f235b5a6e597cdd439b6a06d15dd06f77547dc9adcba5cdb0daaaef708783d06bdbebfd21babbd29
|
data/lib/nhentai-api.rb
CHANGED
@@ -1,155 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
"
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
res = client.body.match(%r{https://t.*.nhentai.net/galleries/#{media_id}/#{page}t\.(.{3})"})
|
36
|
-
|
37
|
-
"https://i.nhentai.net/galleries/#{media_id}/#{page}.#{res[1]}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def pages
|
41
|
-
(1..count_pages).map { |page| page(page) }
|
42
|
-
end
|
43
|
-
|
44
|
-
def thumbnail(page = 1)
|
45
|
-
res = client.body.match(%r{https://t.*.nhentai.net/galleries/#{media_id}/(#{page}t\..{3})"})
|
46
|
-
|
47
|
-
"https://t.nhentai.net/galleries/#{media_id}/#{res[1]}"
|
48
|
-
end
|
49
|
-
|
50
|
-
def thumbnails
|
51
|
-
(1..count_pages).map { |page| thumbnail(page) }
|
52
|
-
end
|
53
|
-
|
54
|
-
def count_favorites
|
55
|
-
regex = %r{<span>Favorite <span class="nobold">.(\d+).<\/span><\/span>}
|
56
|
-
|
57
|
-
client.body.match(regex)[1].to_i
|
58
|
-
end
|
59
|
-
|
60
|
-
def upload_date
|
61
|
-
Time.iso8601(client.body.match(/<time .+ datetime="(.*?)"/)[1])
|
3
|
+
%w[net/http ostruct time json].each { |e| require e }
|
4
|
+
%w[doujinshi search key].each { |e| require_relative e }
|
5
|
+
|
6
|
+
SORT = {
|
7
|
+
today: 'popular-today',
|
8
|
+
week: 'popular-week',
|
9
|
+
all_time: 'popular'
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
IMAGE_EXTENSION = {
|
13
|
+
'j' => 'jpg',
|
14
|
+
'p' => 'png',
|
15
|
+
'g' => 'gif'
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
SINGULAR_TAG = {
|
19
|
+
'tags' => 'tag',
|
20
|
+
'parodies' => 'parody',
|
21
|
+
'characters' => 'character',
|
22
|
+
'artists' => 'artist',
|
23
|
+
'groups' => 'group',
|
24
|
+
'languages' => 'language',
|
25
|
+
'categories' => 'category'
|
26
|
+
}.freeze
|
27
|
+
|
28
|
+
def parse_tiles(res)
|
29
|
+
res.map do |line|
|
30
|
+
id = line.match(%r{/g/(\d+)/})[1]
|
31
|
+
name = line.match(/<div class="caption">(.+)/)[1].strip
|
32
|
+
url = "/g/#{id}"
|
33
|
+
|
34
|
+
OpenStruct.new(id: id, name: name, url: url)
|
62
35
|
end
|
63
|
-
|
64
|
-
%w[tags parodies characters artists groups languages categories].each do |method|
|
65
|
-
define_method method do
|
66
|
-
return instance_variable_get("@#{method}") if instance_variable_defined?("@#{method}")
|
67
|
-
|
68
|
-
res = client.body.match(%r{#{method.capitalize}:\s*<span class="tags">(.+)<\/span>})
|
69
|
-
return [] if res.nil?
|
70
|
-
|
71
|
-
instance_variable_set("@#{method}", parsing_informations(res[1]))
|
72
|
-
end
|
73
|
-
|
74
|
-
define_method "count_#{method}" do
|
75
|
-
send(method).size
|
76
|
-
end
|
77
|
-
|
78
|
-
define_method "#{method}?" do
|
79
|
-
!send(method).empty?
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def parsing_informations(res)
|
86
|
-
res.split(%r{<a(.+?)<\/a>}).reject(&:empty?).map do |line|
|
87
|
-
id = parse_id(line)
|
88
|
-
name = parse_name(line)
|
89
|
-
count = parse_count(line)
|
90
|
-
url = parse_url(line)
|
91
|
-
|
92
|
-
OpenStruct.new(id: id, name: name, count: count, url: url)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def parse_id(line)
|
97
|
-
line.match(/tag-(\d+)/)[1]
|
98
|
-
end
|
99
|
-
|
100
|
-
def parse_name(line)
|
101
|
-
line.match(/class="name">(.+?)</)[1].strip
|
102
|
-
end
|
103
|
-
|
104
|
-
def parse_count(line)
|
105
|
-
count = line.match(/class="count">(\d+.)</)[1]
|
106
|
-
|
107
|
-
count[-1] == 'K' ? count.to_i * 1000 : count.to_i
|
108
|
-
end
|
109
|
-
|
110
|
-
def parse_url(line)
|
111
|
-
line.match(/href=\"(.+?)\"/)[1]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
%w[tag parody character artist group language category].each do |class_name|
|
116
|
-
c = Class.new do
|
117
|
-
def self.count(keyword)
|
118
|
-
class_name = name.split('::').last.downcase
|
119
|
-
keyword = keyword.tr(' ', '-')
|
120
|
-
@client = Net::HTTP.get_response(URI("https://nhentai.net/#{class_name}/#{keyword}/"))
|
121
|
-
return unless exists?
|
122
|
-
|
123
|
-
@client.body.match(%r{<a.*class="count">(.*)<\/span><\/a>})[1].to_i
|
124
|
-
end
|
125
|
-
|
126
|
-
def self.listing(keyword, sort = 1, page = 1)
|
127
|
-
class_name = name.split('::').last.downcase
|
128
|
-
keyword = keyword.tr(' ', '-')
|
129
|
-
sort = sort == 1 ? '' : 'popular'
|
130
|
-
@client = Net::HTTP.get_response(URI("https://nhentai.net/#{class_name}/#{keyword}/#{sort}?page=#{page}"))
|
131
|
-
return unless exists?
|
132
|
-
|
133
|
-
res = @client.body.split(%r{<div class="gallery".+?>(.*?)<\/div>}).select { |line| line.include?('<a href="/g/') }
|
134
|
-
parse_tags(res)
|
135
|
-
end
|
136
|
-
|
137
|
-
private
|
138
|
-
|
139
|
-
def self.exists?
|
140
|
-
@client.code == '200'
|
141
|
-
end
|
142
|
-
|
143
|
-
def self.parse_tags(res)
|
144
|
-
res.map do |line|
|
145
|
-
id = line.match(%r{/g/(\d+)/})[1]
|
146
|
-
name = line.match(/<div class="caption">(.+)/)[1].strip
|
147
|
-
url = "/g/#{id}"
|
148
|
-
|
149
|
-
OpenStruct.new(id: id, name: name, url: url)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
Kernel.const_set(class_name.capitalize, c)
|
155
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nhentai-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gael Roussel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: nhentai-api is a basic and easy to use API for nhentai.net
|
14
14
|
email: gaelroussel@protonmail.com
|
@@ -22,6 +22,9 @@ licenses:
|
|
22
22
|
- MIT
|
23
23
|
metadata:
|
24
24
|
source_code_uri: https://github.com/Mraiih/nhentai-api
|
25
|
+
changelog_uri: https://github.com/Mraiih/nhentai-api/blob/master/CHANGELOG.md
|
26
|
+
documentation_uri: https://github.com/Mraiih/nhentai-api/wiki/Documentation
|
27
|
+
funding_uri: https://ko-fi.com/mraiih
|
25
28
|
post_install_message:
|
26
29
|
rdoc_options: []
|
27
30
|
require_paths:
|