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

Code before:
        'origin': 'https://www.tennistv.com',
        'referer': 'https://www.tennistv.com/',
        'content-Type': 'application/x-www-form-urlencoded'
    }

    def _login(self):

        BASE_URL = 'https://sso.tennistv.com/auth/realms/TennisTV/protocol/openid-connect/auth'

        cookies = self._get_cookies('https://www.tennistv.com/')
        username, password = self._get_login_info()

        if username and password:

            login_form = {
                'username': username,
                'password': password,
                'submitAction': 'Log In'
            }

            login_page = self._download_webpage(update_url_query(BASE_URL, {'client_id': 'tennis-tv-web',
                                                'redirect_uri': 'https://tennistv.com',
                                                                            'response_mode': 'fragment',
                                                                            'response_type': 'code',
                                                                            'scope': 'openid'}),
                                                '')
            post_url = self._html_search_regex(r'action=["\'](.+?)["\']\s+?method=["\']post["\']', login_page, None)

            temp_page = self._download_webpage(post_url, None, 'Sending login data', 'Unable to send login data',
                                               data=urlencode_postdata(login_form), headers=self.headers)

            if 'Your username or password was incorrect' in temp_page:
                raise ExtractorError('Your username or password was incorrect', expected=True)

            _, handle = self._download_webpage_handle(update_url_query(BASE_URL, {'client_id': 'tennis-tv-web',
                                                                                  'redirect_uri': 'https://www.tennistv.com/resources/v1.1.10/html/silent-check-sso.html',
                                                                                  'state': random_uuidv4(),
                                                                                  'response_mode': 'fragment',
                                                                                  'response_type': 'code',
                                                                                  'scope': 'openid',
                                                                                  'nonce': random_uuidv4(),
                                                                                  'prompt': 'none'}), '',
                                                      headers=self.headers)

            self.token_util(None, {
                'code': compat_urlparse.parse_qs(handle.geturl()).get('code')[-1],  # There can be multiple, always use the last one
                'grant_type': 'authorization_code',
                'client_id': 'tennis-tv-web',
                'redirect_uri': 'https://www.tennistv.com/resources/v1.1.10/html/silent-check-sso.html'
            })
            return

Review comment (suggestion):
```suggestion
            login_page = self._download_webpage(BASE_URL, None, query={
                'client_id': 'tennis-tv-web',
                'redirect_uri': 'https://tennistv.com',
                'response_mode': 'fragment',
                'response_type': 'code',
                'scope': 'openid'
            }))
```
etc

Code after:
    _NETRC_MACHINE = 'tennistv'

    access_token, refresh_token = None, None
    _PARTNER_ID = 3001482
    _FORMAT_URL = 'https://open.http.mp.streamamg.com/p/{partner}/sp/{partner}00/playManifest/entryId/{entry}/format/applehttp/protocol/https/a.m3u8?ks={session}'
    _AUTH_BASE_URL = 'https://sso.tennistv.com/auth/realms/TennisTV/protocol/openid-connect'
    _HEADERS = {
        'origin': 'https://www.tennistv.com',
        'referer': 'https://www.tennistv.com/',
        'content-Type': 'application/x-www-form-urlencoded'
    }

    def _perform_login(self, username, password):
        login_page = self._download_webpage(
            f'{self._AUTH_BASE_URL}/auth', None, 'Downloading login page',
            query={
                'client_id': 'tennis-tv-web',
                'redirect_uri': 'https://tennistv.com',
                'response_mode': 'fragment',
                'response_type': 'code',
                'scope': 'openid'
            })

        post_url = self._html_search_regex(r'action=["\']([^"\']+?)["\']\s+method=["\']post["\']', login_page, 'login POST url')
        temp_page = self._download_webpage(
            post_url, None, 'Sending login data', 'Unable to send login data',
            headers=self._HEADERS, data=urlencode_postdata({
                'username': username,
                'password': password,
                'submitAction': 'Log In'
            }))
        if 'Your username or password was incorrect' in temp_page:
            raise ExtractorError('Your username or password was incorrect', expected=True)

        handle = self._request_webpage(
            f'{self._AUTH_BASE_URL}/auth', None, 'Logging in', headers=self._HEADERS,
            query={
                'client_id': 'tennis-tv-web',
                'redirect_uri': 'https://www.tennistv.com/resources/v1.1.10/html/silent-check-sso.html',
                'state': random_uuidv4(),
                'response_mode': 'fragment',
                'response_type': 'code',
                'scope': 'openid',
                'nonce': random_uuidv4(),
                'prompt': 'none'
            })

        self.get_token(None, {
            'code': urllib.parse.parse_qs(handle.geturl())['code'][-1],
            'grant_type': 'authorization_code',
            'client_id': 'tennis-tv-web',