1
0
Fork 0
mirror of synced 2024-06-10 22:34:40 +12:00

Refactor class

This commit is contained in:
Serene-Arc 2021-04-28 18:37:49 +10:00 committed by Serene
parent e1a4ac063c
commit 3c6e9f6ccf

View file

@ -27,21 +27,19 @@ class Redgifs(GifDeliveryNetwork):
except AttributeError:
raise SiteDownloaderError(f'Could not extract Redgifs ID from {url}')
url = f'https://api.redgifs.com/v1/gfycats/{redgif_id}'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' \
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/90.0.4430.93 Safari/537.36',
}
content = Redgifs.retrieve_url(url, headers=headers)
content = Redgifs.retrieve_url(f'https://api.redgifs.com/v1/gfycats/{redgif_id}', headers=headers)
if content is None:
raise SiteDownloaderError('Could not read the page source')
try:
out = content.json()["gfyItem"]["mp4Url"]
except (IndexError, KeyError, AttributeError):
out = json.loads(content.text)['gfyItem']['mp4Url']
except (KeyError, AttributeError):
raise SiteDownloaderError('Failed to find JSON data in page')
except json.JSONDecodeError as e:
raise SiteDownloaderError(f'Received data was not valid JSON: {e}')