From 2e56f6216d193eff8a6a0d90bcc201c0f9d122c4 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 12 Nov 2019 14:11:52 -0500 Subject: [PATCH] Unchanged file update --- src/utils/scraper.py | 92 ++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/utils/scraper.py b/src/utils/scraper.py index 70f1068..20cb5bd 100644 --- a/src/utils/scraper.py +++ b/src/utils/scraper.py @@ -45,35 +45,35 @@ async def query_kheina(url): content = await u.fetch('https://kheina.com', params={'url': url}, text=True) for e in ('"', '''): - content = content.replace(e, '') - content = re.sub('', '', content) + content = content.replace(e, '') + content = re.sub('', '', content) - soup = BeautifulSoup(content, 'html5lib') + soup = BeautifulSoup(content, 'html5lib') - if soup.find('data', id='error'): - return False + 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) + 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 + similarity = int(float(iqdbdata[0]['similarity'])) + if similarity < 55: + return False - for e in results: - if iqdbdata[0]['iqdbid'] in e: - match = e - break + 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' - } + 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 @@ -86,27 +86,27 @@ 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}, - json=True) + json=True) - if content['header'].get('message', '') in ( - 'Access to specified file was denied... ;_;', - 'Problem with remote server...', - 'image dimensions too small...'): - raise exc.ImageError + if content['header'].get('message', '') in ( + 'Access to specified file was denied... ;_;', + 'Problem with remote server...', + 'image dimensions too small...'): + raise exc.ImageError - match = content['results'][0] + match = content['results'][0] - similarity = int(float(match['header']['similarity'])) - if similarity < 55: - return False + similarity = int(float(match['header']['similarity'])) + 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 + source = match['data']['ext_urls'][0] + for e in match['data']['ext_urls']: + if 'e621' in e: + source = e + break - artist = 'Unknown' + artist = 'Unknown' for e in ( 'author_name', 'member_name', @@ -115,13 +115,13 @@ async def query_saucenao(url): artist = match['data'][e] break - result = { - 'source': source, - 'artist': artist, - 'thumbnail': match['header']['thumbnail'], - 'similarity': str(similarity), - 'database': 'SauceNAO' - } + result = { + 'source': source, + 'artist': artist, + 'thumbnail': match['header']['thumbnail'], + 'similarity': str(similarity), + 'database': 'SauceNAO' + } return result