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

Merge branch 'dev'

This commit is contained in:
Myned 2019-11-12 14:11:59 -05:00
commit 44d98cec0d
No known key found for this signature in database
GPG key ID: BC58C09870A63E59

View file

@ -41,86 +41,93 @@ from utils import utils as u
async def query_kheina(url): async def query_kheina(url):
content = await u.fetch('https://kheina.com', params={'url': url}, text=True) try:
content = await u.fetch('https://kheina.com', params={'url': url}, text=True)
for e in ('"', '''): for e in ('"', '''):
content = content.replace(e, '') content = content.replace(e, '')
content = re.sub('<a href="/cdn-cgi/l/email-protection".+</a>', '', content) content = re.sub('<a href="/cdn-cgi/l/email-protection".+</a>', '', content)
soup = BeautifulSoup(content, 'html5lib') soup = BeautifulSoup(content, 'html5lib')
if soup.find('data', id='error'): if soup.find('data', id='error'):
return False
results = soup.find('data', id='results').string
results = ast.literal_eval(results)
iqdbdata = soup.find('data', id='iqdbdata').string
iqdbdata = ast.literal_eval(iqdbdata)
similarity = int(float(iqdbdata[0]['similarity']))
if similarity < 55:
return False
for e in results:
if iqdbdata[0]['iqdbid'] in e:
match = e
break
result = {
'source': match[3].replace('\\', ''),
'artist': match[4],
'thumbnail': f'https://f002.backblazeb2.com/file/kheinacom/{match[1]}.jpg',
'similarity': str(similarity),
'database': 'Kheina'
}
return result
except Exception:
return False return False
results = soup.find('data', id='results').string
results = ast.literal_eval(results)
iqdbdata = soup.find('data', id='iqdbdata').string
iqdbdata = ast.literal_eval(iqdbdata)
similarity = int(float(iqdbdata[0]['similarity']))
if similarity < 55:
return False
for e in results:
if iqdbdata[0]['iqdbid'] in e:
match = e
break
result = {
'source': match[3].replace('\\', ''),
'artist': match[4],
'thumbnail': f'https://f002.backblazeb2.com/file/kheinacom/{match[1]}.jpg',
'similarity': str(similarity),
'database': 'Kheina'
}
return result
async def query_saucenao(url): async def query_saucenao(url):
content = await u.fetch( try:
'https://saucenao.com/search.php', content = await u.fetch(
params={'url': url, 'api_key': u.config['saucenao_api'], 'output_type': 2}, 'https://saucenao.com/search.php',
json=True) params={'url': url, 'api_key': u.config['saucenao_api'], 'output_type': 2},
json=True)
if content['header'].get('message', '') in ( if content['header'].get('message', '') in (
'Access to specified file was denied... ;_;', 'Access to specified file was denied... ;_;',
'Problem with remote server...', 'Problem with remote server...',
'image dimensions too small...'): 'image dimensions too small...'):
raise exc.ImageError raise exc.ImageError
match = content['results'][0] match = content['results'][0]
similarity = int(float(match['header']['similarity'])) similarity = int(float(match['header']['similarity']))
if similarity < 55: if similarity < 55:
return False
source = match['data']['ext_urls'][0]
for e in match['data']['ext_urls']:
if 'e621' in e:
source = e
break
artist = 'Unknown'
for e in (
'author_name',
'member_name',
'creator'):
if e in match['data']:
artist = match['data'][e]
break
result = {
'source': source,
'artist': artist,
'thumbnail': match['header']['thumbnail'],
'similarity': str(similarity),
'database': 'SauceNAO'
}
return result
except Exception:
return False return False
source = match['data']['ext_urls'][0]
for e in match['data']['ext_urls']:
if 'e621' in e:
source = e
break
artist = 'Unknown'
for e in (
'author_name',
'member_name',
'creator'
):
if e in match['data']:
artist = match['data'][e]
break
result = {
'source': source,
'artist': artist,
'thumbnail': match['header']['thumbnail'],
'similarity': str(similarity),
'database': 'SauceNAO'
}
return result
async def get_post(url): async def get_post(url):
try: try: