1
0
Fork 0
mirror of synced 2024-06-13 15:54:37 +12:00

(bug) redgifs: fix could not read page source

This commit is contained in:
Ali Parlakci 2021-04-28 11:30:26 +03:00 committed by Serene
parent 7fcbf623a0
commit e1a4ac063c

View file

@ -27,23 +27,20 @@ class Redgifs(GifDeliveryNetwork):
except AttributeError:
raise SiteDownloaderError(f'Could not extract Redgifs ID from {url}')
url = 'https://redgifs.com/watch/' + redgif_id
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)'
' Chrome/67.0.3396.87 Safari/537.36 OPR/54.0.2952.64',
'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',
}
page = Redgifs.retrieve_url(url, headers=headers)
soup = BeautifulSoup(page.text, 'html.parser')
content = soup.find('script', attrs={'data-react-helmet': 'true', 'type': 'application/ld+json'})
content = Redgifs.retrieve_url(url, headers=headers)
if content is None:
raise SiteDownloaderError('Could not read the page source')
try:
out = json.loads(content.contents[0])['video']['contentUrl']
out = content.json()["gfyItem"]["mp4Url"]
except (IndexError, KeyError, AttributeError):
raise SiteDownloaderError('Failed to find JSON data in page')
except json.JSONDecodeError as e: