From e51c5615d8c23ee76272e9f7f31eb023eaa9b2fd Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 24 Sep 2019 20:03:06 -0400 Subject: [PATCH 1/2] Change semantics to clarify action --- src/utils/scraper.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/scraper.py b/src/utils/scraper.py index e9590a0..4bb1952 100644 --- a/src/utils/scraper.py +++ b/src/utils/scraper.py @@ -40,7 +40,7 @@ from utils import utils as u # 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 = content.replace('"', 'quot;').replace(''', 'apos;') @@ -66,7 +66,7 @@ async def get_kheina(url): return result -async def get_saucenao(url): +async def query_saucenao(url): content = await u.fetch( 'https://saucenao.com/search.php', params={'url': url, 'api_key': u.config['saucenao_api'], 'output_type': 2}, @@ -102,9 +102,9 @@ async def get_post(url): if filesize > 8192 * 1024: raise exc.SizeError(size(filesize, system=alternative)) - result = await get_kheina(url) + result = await query_kheina(url) if int(result['similarity']) < 55: - result = await get_saucenao(url) + result = await query_saucenao(url) if int(result['similarity']) < 55: raise exc.MatchError(re.search('\\/([^\\/]+)$', url).group(1)) From 884f101ad4c75649c24ca177bbb21db4f1dd7927 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 24 Sep 2019 20:05:18 -0400 Subject: [PATCH 2/2] Remove preference for e621, change wording to match other uses --- src/utils/scraper.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/utils/scraper.py b/src/utils/scraper.py index 4bb1952..ac3fb7c 100644 --- a/src/utils/scraper.py +++ b/src/utils/scraper.py @@ -72,23 +72,22 @@ async def query_saucenao(url): params={'url': url, 'api_key': u.config['saucenao_api'], 'output_type': 2}, json=True) - results = content['results'][0] - for i in range(len(content['results'])): - if 'e621' in content['results'][i]['header']['index_name']: - results = content['results'][i] + match = content['results'][0] - if 'author_name' in results['data']: + if 'author_name' in match['data']: artist = 'author_name' - elif 'member_name' in results['data']: + elif 'member_name' in match['data']: artist = 'member_name' - else: + elif 'creator' in match['data']: artist = 'creator' + else: + artist = 'imdb_id' result = { - 'source': results['data']['ext_urls'][0], - 'artist': results['data'][artist], - 'thumbnail': results['header']['thumbnail'], - 'similarity': str(int(float(results['header']['similarity']))), + 'source': match['data']['ext_urls'][0], + 'artist': match['data'][artist], + 'thumbnail': match['header']['thumbnail'], + 'similarity': str(int(float(match['header']['similarity']))), 'database': 'SauceNAO' }