Refactor class
This commit is contained in:
parent
e1a4ac063c
commit
3c6e9f6ccf
|
@ -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}')
|
||||
|
|
Loading…
Reference in a new issue