Mraiih / nhentai-api

nhentai-api is a basic and easy to use API for nhentai.net
https://rubygems.org/gems/nhentai-api
MIT License
10 stars 0 forks source link

Doujinshi constructor is broken #2

Closed lukeovalle closed 4 years ago

lukeovalle commented 4 years ago

It fails with any ID i've tried

irb(main):003:0> Doujinshi.new 177013
Traceback (most recent call last):
        6: from /usr/bin/irb:23:in `<main>'
        5: from /usr/bin/irb:23:in `load'
        4: from /usr/lib64/ruby/gems/2.7.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>'
        3: from (irb):3
        2: from (irb):3:in `new'
        1: from /usr/lib64/ruby/gems/2.7.0/gems/nhentai-api-0.2.1/lib/nhentai-api.rb:23:in `initialize'
NoMethodError (undefined method `[]' for nil:NilClass)

i think it can be fixed by changing the regexp in line 23 from
@count_pages = @client.body.match(/([0-9]+) pages/)[1].to_i to
@count_pages = @client.body.match(/([0-9]+)\+pages/)[1].to_i

Mraiih commented 4 years ago

Hi,

Seems like nhentai changed a bit their design, so that break lots of things, but thanks for being aware!

Your fix is a bit incorrect since the number in the link don't match with the real number of page Example with 316579:

Pages: <span class="tags"><a class="tag" href="/search/?q=pages%3A%3E32+pages%3A%3C48"><span class="name">40</span></a></span></div><div class="tag-container field-name">

It will take '32' but the real number of pages is 40.

A correct fix can be @client.body.match(/Pages:\s*.*>([0-9]+)</)[1].to_i (or maybe better, I'm far away from being a pro a Regex)

I'll change for code to match with the new design this week end

lukeovalle commented 4 years ago

Hi, and sorry for the delay

I've been playing a little with the code and there are a few other things broken. i've managed to fix the Doujinshi class but the others are still broken...

I'll send a PR with what i've done.

Mraiih commented 4 years ago

Ok so I correct things in the last commit ( 2f93cb1 ) Sorry for the really long delay, got some hard job to do.

I hope everything will go as normal now, and thanks again for the report :)