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

Code before:
class Ant1NewsGrBaseIE(InfoExtractor):
    @staticmethod
    def _scale_thumbnails_to_max_width(formats, thumbnails, url_width_re):
        _keys = ('width', 'height')
        max_dimensions = max(
            [tuple(format.get(k) or 0 for k in _keys) for format in formats],
            default=(0, 0))
        if not max_dimensions[0]:
            return thumbnails
        return [
            merge_dicts(
                {'url': re.sub(url_width_re, str(max_dimensions[0]), thumbnail['url'])},
                dict(zip(_keys, max_dimensions)), thumbnail)
            for thumbnail in thumbnails
        ]

    def _download_and_extract_api_data(self, video_id, netloc, cid=None):
        url = f'{self.http_scheme()}//{netloc}{self._API_PATH}'
        info = self._download_json(url, video_id, query={'cid': cid or video_id})
        try:
            source = info['url']
        except KeyError:
            raise ExtractorError('no source found for %s' % video_id)
        formats, subs = self._extract_m3u8_formats_and_subtitles(
            source, video_id, 'mp4') \
            if determine_ext(source) == 'm3u8' else ([{'url': source}], {})
        self._sort_formats(formats)
        thumbnails = self._scale_thumbnails_to_max_width(
            formats, [{'url': info['thumb']}], r'(?<=/imgHandler/)\d+')
        return {
            'id': video_id,
            'title': info['title'],
            'thumbnails': thumbnails,
            'formats': formats,
            'subtitles': subs,
        }


class Ant1NewsGrWatchIE(Ant1NewsGrBaseIE):
    IE_NAME = 'ant1newsgr:watch'
    IE_DESC = 'ant1news.gr videos'
    _VALID_URL = r'https?://(?P<netloc>(?:www\.)?ant1news\.gr)/watch/(?P<id>\d+)/'
    _API_PATH = '/templates/data/player'

    _TEST = {
        'url': 'https://www.ant1news.gr/watch/1506168/ant1-news-09112021-stis-18-45',
        'md5': '95925e6b32106754235f2417e0d2dfab',
        'info_dict': {
            'id': '1506168',
            'ext': 'mp4',
            'title': 'md5:0ad00fa66ecf8aa233d26ab0dba7514a',

Review comment (refactor):
```suggestion
        formats, subs = (self._extract_m3u8_formats_and_subtitles(source, video_id, 'mp4')
                         if determine_ext(source) == 'm3u8' else ([{'url': source}], {}))
```

Code after:
class Ant1NewsGrBaseIE(InfoExtractor):
    def _download_and_extract_api_data(self, video_id, netloc, cid=None):
        url = f'{self.http_scheme()}//{netloc}{self._API_PATH}'
        info = self._download_json(url, video_id, query={'cid': cid or video_id})
        try:
            source = info['url']
        except KeyError:
            raise ExtractorError('no source found for %s' % video_id)
        formats, subs = (self._extract_m3u8_formats_and_subtitles(source, video_id, 'mp4')
                         if determine_ext(source) == 'm3u8' else ([{'url': source}], {}))
        self._sort_formats(formats)
        thumbnails = scale_thumbnails_to_max_format_width(
            formats, [{'url': info['thumb']}], r'(?<=/imgHandler/)\d+')
        return {
            'id': video_id,
            'title': info.get('title'),
            'thumbnails': thumbnails,
            'formats': formats,
            'subtitles': subs,
        }


class Ant1NewsGrWatchIE(Ant1NewsGrBaseIE):
    IE_NAME = 'ant1newsgr:watch'
    IE_DESC = 'ant1news.gr videos'
    _VALID_URL = r'https?://(?P<netloc>(?:www\.)?ant1news\.gr)/watch/(?P<id>\d+)/'
    _API_PATH = '/templates/data/player'

    _TESTS = [{
        'url': 'https://www.ant1news.gr/watch/1506168/ant1-news-09112021-stis-18-45',
        'md5': '95925e6b32106754235f2417e0d2dfab',
        'info_dict': {
            'id': '1506168',
            'ext': 'mp4',
            'title': 'md5:0ad00fa66ecf8aa233d26ab0dba7514a',
            'description': 'md5:18665af715a6dcfeac1d6153a44f16b0',
            'thumbnail': 'https://ant1media.azureedge.net/imgHandler/640/26d46bf6-8158-4f02-b197-7096c714b2de.jpg',
        },
    }]

    def _real_extract(self, url):
        video_id, netloc = self._match_valid_url(url).group('id', 'netloc')
        webpage = self._download_webpage(url, video_id)
        info = self._download_and_extract_api_data(video_id, netloc)
        info['description'] = self._og_search_description(webpage)
        return info


class Ant1NewsGrArticleIE(Ant1NewsGrBaseIE):
    IE_NAME = 'ant1newsgr:article'
    IE_DESC = 'ant1news.gr articles'