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

Code before:
        '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()
                raise ExtractorError(error['error_description'], expected=True)
            raise

        formats = []
        subtitles = {}
        for source in traverse_obj(video_data, ('sources', lambda _, v: url_or_none(v['src']))):
            src_url = source['src']
            src_type = source.get('type')
            if src_type in ('application/vnd.apple.mpegurl', 'application/hls+legacy', 'application/hls+hevc'):
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    src_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
            elif src_type in ('application/dash+xml', 'application/dash+hevc'):
                fmts, subs = self._extract_mpd_formats_and_subtitles(
                    src_url, video_id, mpd_id='dash', fatal=False)
            else:
                continue
            formats.extend(fmts)

Review comment (suggestion):
```suggestion
        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)
```

Code after:
    }]
    _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

        formats = []
        subtitles = {}
        for source in traverse_obj(video_data, ('sources', lambda _, v: url_or_none(v['src']))):
            src_url = source['src']
            src_type = source.get('type')
            if src_type in ('application/vnd.apple.mpegurl', 'application/hls+legacy', 'application/hls+hevc'):
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    src_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
            elif src_type in ('application/dash+xml', 'application/dash+hevc'):
                fmts, subs = self._extract_mpd_formats_and_subtitles(
                    src_url, video_id, mpd_id='dash', fatal=False)
            else:
                continue
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        return {