From 1e9272f7aede164c9b9a2a2416762956be833bb1 Mon Sep 17 00:00:00 2001 From: xXmeme-machineXx <52387080+xXmeme-machineXx@users.noreply.github.com> Date: Wed, 22 Dec 2021 02:21:04 -0600 Subject: [PATCH] Fix gfycat, for links redirected to redgifs (#25555) Fixes #25555, #26631, #27543, #28330 --- youtube_dl/extractor/gfycat.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/gfycat.py b/youtube_dl/extractor/gfycat.py index 18a30fe67..fc6fea537 100644 --- a/youtube_dl/extractor/gfycat.py +++ b/youtube_dl/extractor/gfycat.py @@ -8,6 +8,9 @@ from ..utils import ( qualities, ExtractorError, ) +from ..compat import ( + compat_urlparse, +) class GfycatIE(InfoExtractor): @@ -63,15 +66,21 @@ class GfycatIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) - + response = self._request_webpage(url, video_id) + final_url = response.geturl() # follow redirects + hostname = compat_urlparse.urlparse(final_url).netloc + if hostname == 'www.redgifs.com': + api_endpoint = 'https://api.redgifs.com/v1/gifs/%s' % video_id.lower() + else: + api_endpoint = 'https://api.gfycat.com/v1/gfycats/%s' % video_id gfy = self._download_json( - 'https://api.gfycat.com/v1/gfycats/%s' % video_id, + api_endpoint, video_id, 'Downloading video info') if 'error' in gfy: raise ExtractorError('Gfycat said: ' + gfy['error'], expected=True) gfy = gfy['gfyItem'] - title = gfy.get('title') or gfy['gfyName'] + title = gfy.get('title') or gfy.get('gifName') or gfy['gfyName'] description = gfy.get('description') timestamp = int_or_none(gfy.get('createDate')) uploader = gfy.get('userName')