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

Code before:
    scale_thumbnails_to_max_format_width,
)


class AntennaBaseIE(InfoExtractor):
    def _download_and_extract_api_data(self, video_id, netloc, cid=None):
        info = self._download_json(f'{self.http_scheme()}//{netloc}{self._API_PATH}',
                                   video_id, query={'cid': cid or video_id})
        if not info.get('url'):
            raise ExtractorError(f'No source found for {video_id}')

        ext = determine_ext(info['url'])
        if ext == 'm3u8':
            formats, subs = self._extract_m3u8_formats_and_subtitles(info['url'], video_id, 'mp4')
        else:
            formats, subs = [{'url': info['url'], 'format_id': ext}], {}

        thumbnails = scale_thumbnails_to_max_format_width(
            formats, [{'url': info['thumb']}], r'(?<=/imgHandler/)\d+') if info.get('thumb') else []
        return {
            'id': video_id,
            'title': info.get('title'),
            'thumbnails': thumbnails,
            'formats': formats,
            'subtitles': subs,
            '_old_archive_ids': [make_archive_id('Ant1NewsGrWatch', video_id)],
        }


class AntennaGrWatchIE(AntennaBaseIE):
    IE_NAME = 'antenna:watch'
    IE_DESC = 'antenna.gr and ant1news.gr videos'
    _VALID_URL = r'https?://(?P<netloc>(?:www\.)?(?:antenna|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': 'c472d9dd7cd233c63aff2ea42201cda6',
        'info_dict': {
            'id': '1506168',
            'ext': 'mp4',
            'title': 'md5:0ad00fa66ecf8aa233d26ab0dba7514a',
            'description': 'md5:18665af715a6dcfeac1d6153a44f16b0',
            'thumbnail': r're:https://ant1media\.azureedge\.net/imgHandler/\d+/26d46bf6-8158-4f02-b197-7096c714b2de\.jpg',
        },
    }, {
        'url': 'https://www.antenna.gr/watch/1643812/oi-prodotes-epeisodio-01',
        'md5': '8f6f7dd3b1dba4d835ba990e25f31243',
        'info_dict': {
            'id': '1643812',
            'ext': 'mp4',

Review comment (refactor):
Don't add this to the base class, or else all subclassed extractors will match `Ant1NewsGrWatch` entries in the download archive. Add it to `AntennaGrWatchIE` only

Code after:
    scale_thumbnails_to_max_format_width,
)


class AntennaBaseIE(InfoExtractor):
    def _download_and_extract_api_data(self, video_id, netloc, cid=None):
        info = self._download_json(f'{self.http_scheme()}//{netloc}{self._API_PATH}',
                                   video_id, query={'cid': cid or video_id})
        if not info.get('url'):
            raise ExtractorError(f'No source found for {video_id}')

        ext = determine_ext(info['url'])
        if ext == 'm3u8':
            formats, subs = self._extract_m3u8_formats_and_subtitles(info['url'], video_id, 'mp4')
        else:
            formats, subs = [{'url': info['url'], 'format_id': ext}], {}

        thumbnails = scale_thumbnails_to_max_format_width(
            formats, [{'url': info['thumb']}], r'(?<=/imgHandler/)\d+') if info.get('thumb') else []
        return {
            'id': video_id,
            'title': info.get('title'),
            'thumbnails': thumbnails,
            'formats': formats,
            'subtitles': subs,
        }


class AntennaGrWatchIE(AntennaBaseIE):
    IE_NAME = 'antenna:watch'
    IE_DESC = 'antenna.gr and ant1news.gr videos'
    _VALID_URL = r'https?://(?P<netloc>(?:www\.)?(?:antenna|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': 'c472d9dd7cd233c63aff2ea42201cda6',
        'info_dict': {
            'id': '1506168',
            'ext': 'mp4',
            'title': 'md5:0ad00fa66ecf8aa233d26ab0dba7514a',
            'description': 'md5:18665af715a6dcfeac1d6153a44f16b0',
            'thumbnail': r're:https://ant1media\.azureedge\.net/imgHandler/\d+/26d46bf6-8158-4f02-b197-7096c714b2de\.jpg',
        },
    }, {
        'url': 'https://www.antenna.gr/watch/1643812/oi-prodotes-epeisodio-01',
        'md5': '8f6f7dd3b1dba4d835ba990e25f31243',
        'info_dict': {
            'id': '1643812',
            'ext': 'mp4',
            'format_id': 'mp4',