diff --git a/src/utils/scraper.py b/src/utils/scraper.py index 99780d7..3f6539c 100644 --- a/src/utils/scraper.py +++ b/src/utils/scraper.py @@ -47,13 +47,20 @@ async def query_kheina(url): if similarity < 55: return None - source = re.search('\\d+$', content['results'][0]['sources'][0]['source']).group(0) - export = await u.fetch(f'https://faexport.spangle.org.uk/submission/{source}.json', json=True) + if tld.extract(content['results'][0]['sources'][0]['source']).domain == 'furaffinity': + submission = re.search('\\d+$', content['results'][0]['sources'][0]['source']).group(0) + try: + export = await u.fetch(f'https://faexport.spangle.org.uk/submission/{submission}.json', json=True) + thumbnail = export['full'] + except AssertionError: + thumbnail = '' + else: + thumbnail = '' result = { 'source': content['results'][0]['sources'][0]['source'], 'artist': content['results'][0]['sources'][0]['artist'], - 'thumbnail': '' if isinstance(export, int) and export != 200 else export['full'], + 'thumbnail': thumbnail, 'similarity': str(similarity), 'database': tld.extract(content['results'][0]['sources'][0]['source']).domain } diff --git a/src/utils/utils.py b/src/utils/utils.py index f9ab5ea..17e20a8 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -91,9 +91,9 @@ async def fetch(url, *, post={}, response=False, text=False, json=False): if post: async with asession.post(url, data=post, headers={ 'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r: - if r.status != 200: - return r.status - elif response: + assert r.status == 200 + + if response: return r elif text: return await r.text()