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

Code before:
            'channel': 'Flooxer',
            'duration': 1196,
            'thumbnail': 'https://imagenes.atresplayer.com/atp/clipping/cmsimages01/2025/02/14/17CF90D3-FE67-40C5-A941-7825B3E13992/1920x1080.jpg',
            'tags': ['Juvenil', 'Terror', 'Piel de gallina', 'Te sigo', 'Un break', 'Del tirón'],
            'series': 'BIARA: Proyecto Lázarus',
            'season': 'Temporada 1',
            'season_number': 1,
            'episode': 'Episode 3',
            'episode_number': 3,
            'timestamp': 1743095191.333,
            'upload_date': '20250327',
        },
    }, {
        'url': 'https://www.atresplayer.com/lasexta/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_5ad08edf986b2855ed47adc4/',
        'only_matching': True,
    }, {
        'url': 'https://www.atresplayer.com/antena3/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_5ad51046986b2886722ccdea/',
        'only_matching': True,
    }]
    _API_BASE = 'https://api.atresplayer.com/'

    def _perform_login(self, username, password):
        try:
            self._download_webpage(
                'https://account.atresplayer.com/auth/v1/login', None,
                'Logging in', data=urlencode_postdata({
                    'username': username,
                    'password': password,
                }))
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 400:
                raise ExtractorError('Invalid username and/or password', expected=True)
            raise

    def _real_extract(self, url):
        display_id, video_id = self._match_valid_url(url).groups()

        url_data = self._download_json(
            self._API_BASE + 'client/v1/url', video_id,
            note='Downloading API Endpoint Data',
            query={'href': urllib.parse.urlparse(url).path})

        metadata = self._download_json(url_data['href'], video_id)

        try:
            video_data = self._download_json(metadata['urlVideo'], video_id, note='Downloading video data')
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 403:
                error = self._parse_json(e.cause.response.read(), None)
                if error.get('error') == 'required_registered':
                    self.raise_login_required()

Review comment (bug):
```suggestion
                'Logging in', 'Failed to log in', data=urlencode_postdata({
```

Code after:
            'duration': 1196,
            'thumbnail': 'https://imagenes.atresplayer.com/atp/clipping/cmsimages01/2025/02/14/17CF90D3-FE67-40C5-A941-7825B3E13992/1920x1080.jpg',
            'tags': ['Juvenil', 'Terror', 'Piel de gallina', 'Te sigo', 'Un break', 'Del tirón'],
            'series': 'BIARA: Proyecto Lázarus',
            'season': 'Temporada 1',
            'season_number': 1,
            'episode': 'Episode 3',
            'episode_number': 3,
            'timestamp': 1743095191,
            'upload_date': '20250327',
        },
    }, {
        'url': 'https://www.atresplayer.com/lasexta/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_5ad08edf986b2855ed47adc4/',
        'only_matching': True,
    }, {
        'url': 'https://www.atresplayer.com/antena3/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_5ad51046986b2886722ccdea/',
        'only_matching': True,
    }]
    _API_BASE = 'https://api.atresplayer.com/'

    def _perform_login(self, username, password):
        try:
            self._download_webpage(
                'https://account.atresplayer.com/auth/v1/login', None,
                'Logging in', 'Failed to log in', data=urlencode_postdata({
                    'username': username,
                    'password': password,
                }))
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 400:
                raise ExtractorError('Invalid username and/or password', expected=True)
            raise

    def _real_extract(self, url):
        display_id, video_id = self._match_valid_url(url).groups()

        metadata_url = self._download_json(
            self._API_BASE + 'client/v1/url', video_id, 'Downloading API endpoint data',
            query={'href': urllib.parse.urlparse(url).path})['href']
        metadata = self._download_json(metadata_url, video_id)

        try:
            video_data = self._download_json(metadata['urlVideo'], video_id, 'Downloading video data')
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 403:
                error = self._parse_json(e.cause.response.read(), None)
                if error.get('error') == 'required_registered':
                    self.raise_login_required()
                raise ExtractorError(error['error_description'], expected=True)
            raise