rthai6 / saucenaopy

SauceNAO API wrapper for Python
https://pypi.org/project/saucenaopy/
MIT License
0 stars 3 forks source link

Result with lower than minimum_similarity showed up in check_file #2

Closed Juliusfrank11 closed 5 years ago

Juliusfrank11 commented 5 years ago

Hello,

I have a discord bot that automatically detects if an image came from e621 using your module. It appears I have found a bug where the check_file method will return results that are lower in similarity than what is specified as minimum_similarity in the SauceNao object. Specifically, it detected this image as being from e621 because it is 52% similar to this image, even through I specified a minimum_similarity of 80.

Here is my code:


import urllib
from http.cookiejar import CookieJar
import re
from PIL import Image
from saucenao import SauceNao
import io
import logging
import os
import requests

def findURL(string):
    url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\), ]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', string) 
    return url

cj = CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17')]
url = 'https://cdn.discordapp.com/attachments/163278389355085824/562491889429905418/1554177548471.png'
response = requests.get(url)
img = Image.open(io.BytesIO(response.content))
# the sauceNAO module requires that the image be saved
img.save('check.png')
saucenao = SauceNao(directory=os.getcwd(), databases=999, minimum_similarity=80, combine_api_types=False, api_key='',
                    exclude_categories='', move_to_categories=False,  use_author_as_category=False,
                    output_type=SauceNao.API_HTML_TYPE, start_file='', log_level=logging.ERROR,
                    title_minimum_similarity=90)
filtered_results = saucenao.check_image(file_name='check.png',output_type=SauceNao.API_HTML_TYPE)
if "e621.net" in filtered_results: # check if it's furry stuff
    print('furry shit')
    os.remove('check.png')```
Juliusfrank11 commented 5 years ago

It appears I was using a different saucenao module. My apologizes