class Doujinshi
Attributes
Public Class Methods
# File lib/nhentai-api.rb, line 18 def initialize(id) @id = id @client = Net::HTTP.get_response(URI("https://nhentai.net/g/#{@id}/")) if self.exists? @media_id = @client.body.match(%r{\/([0-9]+)\/cover})[1] @count_pages = @client.body.match(/Pages:\s*.*>([0-9]+)</)[1].to_i end end
Public Instance Methods
Give all artists of a doujinshi
@since 0.1.0 @see Doujinshi#tags
# File lib/nhentai-api.rb, line 264 def artists res = @client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? parse_tags(res[1]) end
Check if a particular doujinshi have some artists
@since 0.1.0 @see Doujinshi#tags?
# File lib/nhentai-api.rb, line 289 def artists? !@client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>}).nil? end
Give all categories of a doujinshi
@since 0.1.0 @see Doujinshi#tags
# File lib/nhentai-api.rb, line 369 def categories res = @client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? parse_tags(res[1]) end
Check if a particular doujinshi have some categories
@since 0.1.0 @see Doujinshi#tags?
# File lib/nhentai-api.rb, line 394 def categories? !@client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>}).nil? end
Give all characters of a doujinshi
@since 0.1.0 @see Doujinshi#tags
# File lib/nhentai-api.rb, line 229 def characters res = @client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? parse_tags(res[1]) end
Check if a particular doujinshi have some characters
@since 0.1.0 @see Doujinshi#tags?
# File lib/nhentai-api.rb, line 254 def characters? !@client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>}).nil? end
Give a counter of artists
@since 0.1.0 @see Doujinshi#count_tags
# File lib/nhentai-api.rb, line 277 def count_artists res = @client.body.match(%r{Artists:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : parse_tags(res[1]).length end
Give a counter of categories
@since 0.1.0 @see Doujinshi#count_tags
# File lib/nhentai-api.rb, line 382 def count_categories res = @client.body.match(%r{Categories:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : parse_tags(res[1]).length end
Give a counter of characters
@since 0.1.0 @see Doujinshi#count_tags
# File lib/nhentai-api.rb, line 242 def count_characters res = @client.body.match(%r{Characters:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : parse_tags(res[1]).length end
Give the number of favorites on a doujinshi
@return [Integer] a counter of favorites on a given doujinshi @since 0.1.0 @example
doujinshi.num_favorites #=> 13326
# File lib/nhentai-api.rb, line 129 def count_favorites regex = %r{<span>Favorite <span class="nobold">.(\d+).<\/span><\/span>} @client.body.match(regex)[1].to_i end
Give a counter of groups
@since 0.1.0 @see Doujinshi#count_tags
# File lib/nhentai-api.rb, line 312 def count_groups res = @client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : parse_tags(res[1]).length end
Give a counter of languages
@since 0.1.0 @see Doujinshi#count_tags
# File lib/nhentai-api.rb, line 347 def count_languages res = @client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : parse_tags(res[1]).length end
Give a counter of parodies
@since 0.1.0 @see Doujinshi#count_tags
# File lib/nhentai-api.rb, line 207 def count_parodies res = @client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>}) res.nil? ? 0 : parse_tags(res[1]).length end
Give the cover's URL of a doujinshi
@return [String] the cover's URL of a given doujinshi @since 0.1.0 @example
doujinshi.cover #=> 'https://t.nhentai.net/galleries/1170172/cover.jpg'
# File lib/nhentai-api.rb, line 59 def cover res = @client.body.match(%r{https://t.nhentai.net/galleries/#{@media_id}/cover\.(.{3})"}) "https://t.nhentai.net/galleries/#{@media_id}/cover.#{res[1]}" end
Check if a doujinshi with the given id exist
@return [Bool] true if the doujinshi exist, otherwise false @since 0.1.0 @example
doujinshi.exists? #=> true
# File lib/nhentai-api.rb, line 35 def exists? @client.code == '200' end
Give all groups of a doujinshi
@since 0.1.0 @see Doujinshi#tags
# File lib/nhentai-api.rb, line 299 def groups res = @client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? parse_tags(res[1]) end
Check if a particular doujinshi have some groups
@since 0.1.0 @see Doujinshi#tags?
# File lib/nhentai-api.rb, line 324 def groups? !@client.body.match(%r{Groups:\s+<span class="tags">(.+)<\/span>}).nil? end
Give all languages of a doujinshi
@since 0.1.0 @see Doujinshi#tags
# File lib/nhentai-api.rb, line 334 def languages res = @client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? parse_tags(res[1]) end
Check if a particular doujinshi have some languages
@since 0.1.0 @see Doujinshi#tags?
# File lib/nhentai-api.rb, line 359 def languages? !@client.body.match(%r{Languages:\s+<span class="tags">(.+)<\/span>}).nil? end
Give the URL of a given page of a doujinshi
@param [Integer] page a particular page of a doujinshi @return [String] the URL of a given page of a doujinshi @since 0.1.0 @example
doujinshi.get_page #=> 'https://i.nhentai.net/galleries/1170172/1.jpg' doujinshi.get_page(10) #=> 'https://i.nhentai.net/galleries/1170172/10.jpg'
# File lib/nhentai-api.rb, line 75 def page(page = 1) res = @client.body.match(%r{https://t.nhentai.net/galleries/#{@media_id}/#{page}t\.(.{3})"}) "https://i.nhentai.net/galleries/#{@media_id}/#{page}.#{res[1]}" end
Give the URL of a all pages of a doujinshi
@return [Array] array pages' URL @since 0.1.0 @example
doujinshi.pages #=> ['https://i.nhentai.net/galleries/1170172/1.jpg', ..., 'https://i.nhentai.net/galleries/1170172/31.jpg']
# File lib/nhentai-api.rb, line 89 def pages (1..@count_pages).map { |page| page(page) } end
Give all parodies of a doujinshi
@since 0.1.0 @see Doujinshi#tags
# File lib/nhentai-api.rb, line 194 def parodies res = @client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>}) return [] if res.nil? parse_tags(res[1]) end
Check if a particular doujinshi have some parodies
@since 0.1.0 @see Doujinshi#tags?
# File lib/nhentai-api.rb, line 219 def parodies? !@client.body.match(%r{Parodies:\s+<span class="tags">(.+)<\/span>}).nil? end
Give the thumbnail's URL of a given page of a doujinshi
@param [Integer] page a particular page of a doujinshi @return [String] the thumbnail's URL of a given page of a doujinshi @since 0.1.0 @example
doujinshi.get_thumbnail #=> 'https://t.nhentai.net/galleries/1170172/1t.jpg' doujinshi.get_thumbnail(10) #=> 'https://t.nhentai.net/galleries/1170172/10t.jpg'
# File lib/nhentai-api.rb, line 103 def thumbnail(page = 1) res = @client.body.match(%r{https://t.nhentai.net/galleries/#{@media_id}/(#{page}t\..{3})"}) "https://t.nhentai.net/galleries/#{@media_id}/#{res[1]}" end
Give the URL of a all thumbnails of a doujinshi
@return [Array] an array thumbnails' URL @since 0.1.0 @example
doujinshi.thumbnails #=> ['https://t.nhentai.net/galleries/1170172/1t.jpg',..., 'https://t.nhentai.net/galleries/1170172/31t.jpg']
# File lib/nhentai-api.rb, line 117 def thumbnails (1..@count_pages).map { |page| thumbnail(page) } end
Give the title of a doujinshi
@return [String] the title of a given doujinshi @since 0.1.0 @example
doujinshi.title #=> '[Illumination. (Ogadenmon)] Android no Ecchi na Yatsu | Horny Androids (NieR:Automata) [English] =TLL + mrwayne= [Digital]'
# File lib/nhentai-api.rb, line 47 def title @client.body.match(/"pretty">(.*?)</)[1] end
Give the upload date of a doujinshi
@return [Integer] the upload date of a given doujinshi @since 0.1.0 @example
doujinshi.upload_date #=> 2018-01-17 15:56:16 +0000
# File lib/nhentai-api.rb, line 143 def upload_date Time.iso8601(@client.body.match(/<time .+ datetime="(.*?)"/)[1]) end