Merge pull request #689 from Soulsuck24/development
This commit is contained in:
commit
5300758b3b
1 changed files with 12 additions and 7 deletions
|
@ -28,7 +28,12 @@ class Redgifs(BaseDownloader):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise SiteDownloaderError(f'Could not extract Redgifs ID from {url}')
|
raise SiteDownloaderError(f'Could not extract Redgifs ID from {url}')
|
||||||
|
|
||||||
content = Redgifs.retrieve_url(f'https://api.redgifs.com/v1/gifs/{redgif_id}')
|
auth_token = json.loads(Redgifs.retrieve_url('https://api.redgifs.com/v2/auth/temporary').text)['token']
|
||||||
|
headers = {
|
||||||
|
'Authorization': f'Bearer {auth_token}',
|
||||||
|
}
|
||||||
|
|
||||||
|
content = Redgifs.retrieve_url(f'https://api.redgifs.com/v2/gifs/{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')
|
||||||
|
@ -40,16 +45,16 @@ class Redgifs(BaseDownloader):
|
||||||
|
|
||||||
out = set()
|
out = set()
|
||||||
try:
|
try:
|
||||||
if response_json['gfyItem']['type'] == 1: # type 1 is a video
|
if response_json['gif']['type'] == 1: # type 1 is a video
|
||||||
out.add(response_json['gfyItem']['mp4Url'])
|
out.add(response_json['gif']['urls']['hd'])
|
||||||
elif response_json['gfyItem']['type'] == 2: # type 2 is an image
|
elif response_json['gif']['type'] == 2: # type 2 is an image
|
||||||
if 'gallery' in response_json['gfyItem']:
|
if response_json['gif']['gallery']:
|
||||||
content = Redgifs.retrieve_url(
|
content = Redgifs.retrieve_url(
|
||||||
f'https://api.redgifs.com/v2/gallery/{response_json["gfyItem"]["gallery"]}')
|
f'https://api.redgifs.com/v2/gallery/{response_json["gif"]["gallery"]}')
|
||||||
response_json = json.loads(content.text)
|
response_json = json.loads(content.text)
|
||||||
out = {p['urls']['hd'] for p in response_json['gifs']}
|
out = {p['urls']['hd'] for p in response_json['gifs']}
|
||||||
else:
|
else:
|
||||||
out.add(response_json['gfyItem']['content_urls']['large']['url'])
|
out.add(response_json['gif']['urls']['hd'])
|
||||||
else:
|
else:
|
||||||
raise KeyError
|
raise KeyError
|
||||||
except (KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
|
|
Loading…
Reference in a new issue