Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/redgifs.py (Python)

Code before:
        }
    }, {
        'url': 'https://thumbs2.redgifs.com/SqueakyHelplessWisent-mobile.mp4#t=0',
        'info_dict': {
            'id': 'squeakyhelplesswisent',
            'ext': 'mp4',
            'title': 'Hotwife Legs Thick',
            'timestamp': 1636287915,
            'upload_date': '20211107',
            'uploader': 'ignored52',
            'duration': 16,
            'view_count': int,
            'like_count': int,
            'categories': list,
            'age_limit': 18,
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url).lower()

        video_info = self._download_json(
            'https://api.redgifs.com/v2/gifs/%s' % video_id,
            video_id, 'Downloading video info')
        if 'error' in video_info:
            raise ExtractorError('RedGifs said: ' + video_info['error'], expected=True)

        gif = video_info['gif']
        urls = gif['urls']

        # redgifs do not have title
        title = ' '.join(gif.get('tags')) or 'RedGifs'
        timestamp = int_or_none(gif.get('createDate'))
        uploader = gif.get('userName')
        view_count = int_or_none(gif.get('views'))
        like_count = int_or_none(gif.get('likes'))
        age_limit = 18

        orig_width = int_or_none(gif.get('width'))
        orig_height = int_or_none(gif.get('height'))

        duration = int_or_none(gif.get('duration'))

        categories = gif.get('tags') or []

        FORMATS = ('gif', 'sd', 'hd')
        quality = qualities(FORMATS)

        formats = []
        for format_id in FORMATS:
            video_url = urls.get(format_id)

Review comment (refactor):
Dont use +

```suggestion
            raise ExtractorError(f'RedGifs said: {video_info["error"]}, expected=True)
```
or
```py
            raise ExtractorError('RedGifs said: %s' % video_info['error'], expected=True)
```

Code after:
            'like_count': int,
            'categories': list,
            'age_limit': 18,
        }
    }, {
        'url': 'https://thumbs2.redgifs.com/SqueakyHelplessWisent-mobile.mp4#t=0',
        'info_dict': {
            'id': 'squeakyhelplesswisent',
            'ext': 'mp4',
            'title': 'Hotwife Legs Thick',
            'timestamp': 1636287915,
            'upload_date': '20211107',
            'uploader': 'ignored52',
            'duration': 16,
            'view_count': int,
            'like_count': int,
            'categories': list,
            'age_limit': 18,
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url).lower()

        video_info = self._download_json(
            'https://api.redgifs.com/v2/gifs/%s' % video_id,
            video_id, 'Downloading video info')
        if 'error' in video_info:
            raise ExtractorError(f'RedGifs said: {video_info["error"]}', expected=True)

        gif = video_info['gif']
        urls = gif['urls']

        quality = qualities(tuple(self._FORMATS.keys()))

        orig_height = int_or_none(gif.get('height'))
        aspect_ratio = try_get(gif, lambda x: orig_height / x['width'])

        formats = []
        for format_id, height in self._FORMATS.items():
            video_url = urls.get(format_id)
            if not video_url:
                continue
            height = min(orig_height, height or orig_height)
            formats.append({
                'url': video_url,
                'format_id': format_id,
                'width': height * aspect_ratio if aspect_ratio else None,
                'height': height,
                'quality': quality(format_id),
            })