1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-11-01 13:02:38 +00:00

Add kheina reverse image search

This commit is contained in:
Myned 2022-02-21 13:43:53 -06:00
parent 5850bb7449
commit df0866b424
No known key found for this signature in database
GPG key ID: 33790F979F7A28B8
2 changed files with 25 additions and 28 deletions

View file

@ -93,10 +93,11 @@ async def _reverse(context, urls, *, selector=None):
return
pages = [(hikari.Embed(
title=match['artist'], url=match['source'], color=context.get_guild().get_my_member().get_top_role().color)
title=match['artist'], url=match['url'], color=context.get_guild().get_my_member().get_top_role().color)
.set_author(name=f'{match["similarity"]}% Match')
.set_image(match['thumbnail'])
.set_footer(match['index'])) if match else f'**No match found for:**\n{urls[index]}' for index, match in enumerate(matches)]
.set_footer(match['source']))
if match else f'**No match found.**\n{urls[index]}' for index, match in enumerate(matches)]
if len(pages) > 1:
selector = components.Selector(

View file

@ -11,21 +11,7 @@ sauce = pysaucenao.SauceNao(api_key=c.config['saucenao'], priority=(29, 40, 41))
async def reverse(urls):
matches = []
for url in urls:
saucenao = await _saucenao(url)
kheina = None
if saucenao:
matches.append(saucenao)
else:
pass
if not saucenao and not kheina:
matches.append(None)
return matches
return [await _saucenao(url) or await _kheina(url) for url in urls]
async def _saucenao(url):
try:
@ -37,21 +23,31 @@ async def _saucenao(url):
except pysaucenao.InvalidImageException:
raise pysaucenao.InvalidImageException(url)
if results:
return {
'source': results[0].url,
'artist': results[0].author_name or 'unknown',
'url': results[0].url,
'artist': ', '.join(results[0].authors) or 'Unknown',
'thumbnail': results[0].thumbnail,
'similarity': int(results[0].similarity),
'index': tldextract.extract(results[0].index).domain}
return
'similarity': round(results[0].similarity),
'source': tldextract.extract(results[0].index).domain
} if results else None
async def _kheina(url):
pass
content = await _post('https://api.kheina.com/v1/search', {'url': url})
async def _fetch(url):
if content['results'][0]['similarity'] < 50:
return None
return {
'url': content['results'][0]['sources'][0]['source'],
'artist': content['results'][0]['sources'][0]['artist'] or 'Unknown',
'thumbnail': f'https://cdn.kheina.com/file/kheinacom/{content["results"][0]["sources"][0]["sha1"]}.jpg',
'similarity': round(content['results'][0]['similarity']),
'source': tldextract.extract(content['results'][0]['sources'][0]['source']).domain
}
async def _post(url, data):
async with aiohttp.ClientSession() as session:
async with session.get(url, headers={'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}) as response:
async with session.post(url, data=data, headers={'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}) as response:
return await response.json() if response.status == 200 else None