Refactor class
This commit is contained in:
@@ -27,21 +27,19 @@ class Redgifs(GifDeliveryNetwork):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise SiteDownloaderError(f'Could not extract Redgifs ID from {url}')
|
raise SiteDownloaderError(f'Could not extract Redgifs ID from {url}')
|
||||||
|
|
||||||
url = f'https://api.redgifs.com/v1/gfycats/{redgif_id}'
|
|
||||||
|
|
||||||
headers = {
|
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',
|
'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:
|
if content is None:
|
||||||
raise SiteDownloaderError('Could not read the page source')
|
raise SiteDownloaderError('Could not read the page source')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
out = content.json()["gfyItem"]["mp4Url"]
|
out = json.loads(content.text)['gfyItem']['mp4Url']
|
||||||
except (IndexError, KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
raise SiteDownloaderError('Failed to find JSON data in page')
|
raise SiteDownloaderError('Failed to find JSON data in page')
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
raise SiteDownloaderError(f'Received data was not valid JSON: {e}')
|
raise SiteDownloaderError(f'Received data was not valid JSON: {e}')
|
||||||
|
|||||||
Reference in New Issue
Block a user