1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-25 14:47:29 +00:00

Merge branch 'dev'

This commit is contained in:
Myned 2019-09-24 20:05:38 -04:00
commit 048dbb28ff
No known key found for this signature in database
GPG key ID: BC58C09870A63E59

View file

@ -40,7 +40,7 @@ from utils import utils as u
# return False # return False
async def get_kheina(url): async def query_kheina(url):
content = await u.fetch('https://kheina.com', params={'url': url}, text=True) content = await u.fetch('https://kheina.com', params={'url': url}, text=True)
content = content.replace('"', 'quot;').replace(''', 'apos;') content = content.replace('"', 'quot;').replace(''', 'apos;')
@ -66,29 +66,28 @@ async def get_kheina(url):
return result return result
async def get_saucenao(url): async def query_saucenao(url):
content = await u.fetch( content = await u.fetch(
'https://saucenao.com/search.php', 'https://saucenao.com/search.php',
params={'url': url, 'api_key': u.config['saucenao_api'], 'output_type': 2}, params={'url': url, 'api_key': u.config['saucenao_api'], 'output_type': 2},
json=True) json=True)
results = content['results'][0] match = content['results'][0]
for i in range(len(content['results'])):
if 'e621' in content['results'][i]['header']['index_name']:
results = content['results'][i]
if 'author_name' in results['data']: if 'author_name' in match['data']:
artist = 'author_name' artist = 'author_name'
elif 'member_name' in results['data']: elif 'member_name' in match['data']:
artist = 'member_name' artist = 'member_name'
else: elif 'creator' in match['data']:
artist = 'creator' artist = 'creator'
else:
artist = 'imdb_id'
result = { result = {
'source': results['data']['ext_urls'][0], 'source': match['data']['ext_urls'][0],
'artist': results['data'][artist], 'artist': match['data'][artist],
'thumbnail': results['header']['thumbnail'], 'thumbnail': match['header']['thumbnail'],
'similarity': str(int(float(results['header']['similarity']))), 'similarity': str(int(float(match['header']['similarity']))),
'database': 'SauceNAO' 'database': 'SauceNAO'
} }
@ -102,9 +101,9 @@ async def get_post(url):
if filesize > 8192 * 1024: if filesize > 8192 * 1024:
raise exc.SizeError(size(filesize, system=alternative)) raise exc.SizeError(size(filesize, system=alternative))
result = await get_kheina(url) result = await query_kheina(url)
if int(result['similarity']) < 55: if int(result['similarity']) < 55:
result = await get_saucenao(url) result = await query_saucenao(url)
if int(result['similarity']) < 55: if int(result['similarity']) < 55:
raise exc.MatchError(re.search('\\/([^\\/]+)$', url).group(1)) raise exc.MatchError(re.search('\\/([^\\/]+)$', url).group(1))