ClarityCafe / Sagiri

Simple, lightweight, and easy to use SauceNAO API wrapper for Node.JS.
MIT License
97 stars 13 forks source link

Passed options aren't considered in results #56

Closed digiAlchem closed 5 years ago

digiAlchem commented 5 years ago

Please describe the problem you are having in as much detail as possible: When passing options to new Sagiri(), they are not being considered by the returned results.

For example, if I set numRes to 5, the returned data contains 6 results. Running console.log on sagiri returns the following:

e {
  key: 'MY-API-KEY',
  numRes: 5,
  testMode: false,
  dbMask: null,
  dbMaskI: null,
  getRating: true,
  shortLimiter: e { uses: 0 },
  longLimiter: e { uses: 0 } }

I am using Sagiri inside a Discord.js-based bot, running on a Raspberry Pi Zero W.

Include a reproducible code sample here, if possible:

const Sagiri = module.parent.require('sagiri');
const { saucenaoToken } = module.parent.require('./botConfig.json');
const sagiri = new Sagiri(saucenaoToken, {
  getRating: true,
  numRes: 5
});

console.log(sagiri);

sagiri.getSauce(imageUrl)
.then((sauceList) => {
  console.log(sauceList);
});

Further details:

Ovyerus commented 5 years ago

Could be a problem on SauceNAO's end. Will take a look.

sr229 commented 5 years ago

I don't think this is a SauceNAO problem, looks like this works on 1.5.4. Can you rollback to sagiri@1.5.4 and see if that works @digiAlchem?

digiAlchem commented 5 years ago

@sr229 Apologies I just noticed that I forgot to mention this; the getRatings flag isn't working in 2.0.1 either. I'm just being returned 'UNKNOWN' all the time.

So in 1.5.4, I'm getting ratings returned in a range from -1 to 3, by the looks of it. However, the resultset is still always 6 long regardless of passed in numRes value.

[ { url:
     'https://www.pixiv.net/member_illust.php?mode=medium&illust_id=32045445',
    site: 'Pixiv',
    index: '5',
    similarity: 94.63,
    thumbnail:
     'https://img1.saucenao.com/res/pixiv/3204/32045445_s.jpg?auth=7hiT6fTI_6smYq3qtYBL4A&exp=1565943244',
    rating: 1,
    original: { header: [Object], data: [Object] } },
  { url: 'https://yande.re/post/show/233703',
    site: 'Yande.re',
    index: '12',
    similarity: 94.6,
    thumbnail:
     'https://img3.saucenao.com/booru/3/6/36eebe10d0ac01ca995e7db7891a7720_1.jpg',
    rating: -1,
    original: { header: [Object], data: [Object] } },
  { url:
     'https://www.pixiv.net/member_illust.php?mode=medium&illust_id=63395366',
    site: 'Pixiv',
    index: '5',
    similarity: 93.44,
    thumbnail:
     'https://img1.saucenao.com/res/pixiv/6339/63395366_p0_master1200.jpg?auth=w7fMcohaKFdEEuazIuSH3A&exp=1565943244',
    rating: 1,
    original: { header: [Object], data: [Object] } },
  { url: 'https://seiga.nicovideo.jp/seiga/im2653505',
    site: 'Nico Nico Seiga',
    index: '8',
    similarity: 93.4,
    thumbnail:
     'https://img1.saucenao.com/res/seiga_illust/265/2653505.jpg?auth=pmB1ls-2Jb2kcDhA5zW5GQ&exp=1565943244',
    rating: 0,
    original: { header: [Object], data: [Object] } },
  { url:
     'https://www.pixiv.net/member_illust.php?mode=medium&illust_id=60901939',
    site: 'Pixiv',
    index: '5',
    similarity: 90.8,
    thumbnail:
     'https://img1.saucenao.com/res/pixiv/6090/60901939_p0_master1200.jpg?auth=Buj77JXrnvzYcZZ8GOYmAw&exp=1565943244',
    rating: 1,
    original: { header: [Object], data: [Object] } },
  { url:
     'https://www.pixiv.net/member_illust.php?mode=medium&illust_id=68190326',
    site: 'Pixiv',
    index: '5',
    similarity: 59.98,
    thumbnail:
     'https://img1.saucenao.com/res/pixiv/6819/manga/68190326_p2.jpg?auth=-YJJvfZW_nRlG_GJsa3iKA&exp=1565943244',
    rating: 1,
    original: { header: [Object], data: [Object] } } ]
Ovyerus commented 5 years ago

Dunno why you're getting -1, shouldn't've happened. And whether you get a rating or not depends on the website. Some have a thing on the page which actually gives a rating (Danbooru, Pixiv, and some of the other Danbooru-like boards do this), so it'll often have unknown if it's from a site we don't know how to get the rating from. It's also incomplete last I know so we still need to finish it up.

As for number of results, I have had experiences with other sites in the past giving wrong number of results, so it could be just SauceNAO giving you the wrong number and us not verifying the length. I'll do some testing and maybe add an extra thing that shrinks the list if it's over your given length.

sr229 commented 5 years ago

We'll also inform the SauceNAO developer about this if this is a SauceNAO-wide issue with ratings.

Ovyerus commented 5 years ago

Ratings is only done by us, SauceNAO has no relation with it.

digiAlchem commented 5 years ago

Dunno why you're getting -1, shouldn't've happened. And whether you get a rating or not depends on the website. Some have a thing on the page which actually gives a rating (Danbooru, Pixiv, and some of the other Danbooru-like boards do this), so it'll often have unknown if it's from a site we don't know how to get the rating from. It's also incomplete last I know so we still need to finish it up.

As for number of results, I have had experiences with other sites in the past giving wrong number of results, so it could be just SauceNAO giving you the wrong number and us not verifying the length. I'll do some testing and maybe add an extra thing that shrinks the list if it's over your given length.

If it helps, I was still getting UNKNOWN ratings from sites like yande.re and Gelbooru where those ratings are present on the page.

Ovyerus commented 5 years ago

Interesting

sr229 commented 5 years ago

Any update for this @Ovyerus?

sr229 commented 5 years ago

@Ovyerus there's no activity on this. Any update?

Ovyerus commented 5 years ago

Been busy with some other stuff recently.

Ovyerus commented 5 years ago

Will work on this in the coming weeks or so alongside some other changes I'm bringing to the library, as school is finally winding down and stuff.

Was poking around in the SauceNAO console for some other stuff and I noticed this find

Might be an error in us passing the numres field at times, so it falls back to this instead. Might pay to add some logging features that log request body and some other stuff.

sr229 commented 5 years ago

I think we fixed this on current tree?

Ovyerus commented 5 years ago

The ratings issue was most likely caused by poor porting during the move to 2.0, and has been fixed in 2.0.3.

The number of results should hopefully have been fixed with the release of 3.0, as that has been rewritten from the ground up. If you find it still happens, run again with DEBUG=sagiri environment variable to enable logging, and we'll see if we can look into it if it does persist and can be reproduced.

js-egton commented 5 years ago
SyntaxError:` Unexpected token < in JSON at position 3str"                       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                        <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        <title>SauceNAO Error</title>
                        <link rel="stylesheet" href="css/saucenao-new.css" media="screen" type="text/css" />
                        </head><body><br />
                        You need an Image! <a href="/index.php">...GO BACK TO START...</a> <br /><br /><br /><br />If an image was provided, it may not be loading properly, or may not be in an acceptable format... The image must be: gif, jpg, png, bmp, svg, or webp... <br /> Try another, or convert your image first.</body></html>"
    at JSON.parse (<anonymous>)
    at ClientRequest.h.request (/home/pi/bots/node/discord/node_modules/bent/src/nodejs.js:105:24)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

@Ovyerus Getting the above error when trying to do a search with an image URL; happens with both await and .then() syntax (I use the latter).

My code looks like this:

const sagiri = module.parent.require('sagiri');
const { saucenaoToken } = module.parent.require('./botConfig.json');
const sagiriClient = sagiri(saucenaoToken);

...

sagiriClient(imageUrl)
.then((sauceList) => {
    ....
});

Running console.log(sagiriClient) confirms that it's a loaded function.

Would you like me to open another issue for this, or am I being a dumb? For reference, the image I'm using is this Danbooru link, which I know has a Pixiv match and the SauceNAO site finds it successfully.

https://danbooru.donmai.us/data/sample/__link_the_legend_of_zelda_and_1_more_drawn_by_pretty_purin720__sample-64ed3fd651fe4e1ca141383a4b7b0b4c.jpg

Ovyerus commented 5 years ago

Log imageUrl to make sure it is actually entirely a url, and open another issue as this is separate.

js-egton commented 5 years ago

It's definitely a URL, the Sagiri debug catches it properly. Will do, thanks!

(Also I just realised I've posted comments from the wrong Github account, sorry if that caused confusion!)