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

Code before:
        return itertools.islice(_real_comment_extract(contents), 0, max_comments)

    @staticmethod
    def _get_checkok_params():
        return {'contentCheckOk': True, 'racyCheckOk': True}

    @classmethod
    def _generate_player_context(cls, sts=None):
        context = {
            'html5Preference': 'HTML5_PREF_WANTS',
        }
        if sts is not None:
            context['signatureTimestamp'] = sts
        return {
            'playbackContext': {
                'contentPlaybackContext': context,
            },
            **cls._get_checkok_params(),
        }

    def _get_config_po_token(self, client):
        po_token_strs = self._configuration_arg('po_token', [], ie_key=YoutubeIE, casesense=True)
        for token_str in po_token_strs:
            po_token_client, sep, po_token = token_str.partition('+')
            if not sep:
                self.report_warning('Invalid po_token configuration format. Expected "client+po_token"')
                continue
            if po_token_client == client:
                return po_token

    def fetch_po_token(self, client='web', visitor_data=None, data_sync_id=None, player_url=None, **kwargs):
        # PO Token is bound to visitor_data / Visitor ID when logged out. Must have visitor_data for it to function.
        if not visitor_data and not self.is_authenticated and player_url:
            self.report_warning(
                f'Unable to fetch PO Token for {client} client: Missing required Visitor Data. '
                f'You may need to pass Visitor Data with --extractor-args "youtube:visitor_data=XXX"')
            return

        config_po_token = self._get_config_po_token(client)
        if config_po_token:
            # PO token is bound to data_sync_id / account Session ID when logged in. However, for the config po_token,
            # if using first channel in an account then we don't need the data_sync_id anymore...
            if not data_sync_id and self.is_authenticated and player_url:
                self.report_warning(
                    f'Got a PO Token for {client} client, but missing Data Sync ID for account. Formats may not work.'
                    f'You may need to pass a Data Sync ID with --extractor-args "youtube:data_sync_id=XXX"')

            return config_po_token

        # Require PO Token if logged in for external fetching
        if not data_sync_id and self.is_authenticated and player_url:

Review comment (suggestion):
Could include the bad arg with an only_once
```suggestion
                self.report_warning(
                    f'Invalid po_token configuration format. Expected "client+po_token", got "{token_str}"', only_once=True)
```

Code after:
        return itertools.islice(_real_comment_extract(contents), 0, max_comments)

    @staticmethod
    def _get_checkok_params():
        return {'contentCheckOk': True, 'racyCheckOk': True}

    @classmethod
    def _generate_player_context(cls, sts=None):
        context = {
            'html5Preference': 'HTML5_PREF_WANTS',
        }
        if sts is not None:
            context['signatureTimestamp'] = sts
        return {
            'playbackContext': {
                'contentPlaybackContext': context,
            },
            **cls._get_checkok_params(),
        }

    def _get_config_po_token(self, client):
        po_token_strs = self._configuration_arg('po_token', [], ie_key=YoutubeIE, casesense=True)
        for token_str in po_token_strs:
            po_token_client, sep, po_token = token_str.partition('+')
            if not sep:
                self.report_warning(
                    f'Invalid po_token configuration format. Expected "client+po_token", got "{token_str}"', only_once=True)
                continue
            if po_token_client == client:
                return po_token

    def fetch_po_token(self, client='web', visitor_data=None, data_sync_id=None, player_url=None, **kwargs):
        # PO Token is bound to visitor_data / Visitor ID when logged out. Must have visitor_data for it to function.
        if not visitor_data and not self.is_authenticated and player_url:
            self.report_warning(
                f'Unable to fetch PO Token for {client} client: Missing required Visitor Data. '
                f'You may need to pass Visitor Data with --extractor-args "youtube:visitor_data=XXX"')
            return

        config_po_token = self._get_config_po_token(client)
        if config_po_token:
            # PO token is bound to data_sync_id / account Session ID when logged in. However, for the config po_token,
            # if using first channel in an account then we don't need the data_sync_id anymore...
            if not data_sync_id and self.is_authenticated and player_url:
                self.report_warning(
                    f'Got a PO Token for {client} client, but missing Data Sync ID for account. Formats may not work.'
                    f'You may need to pass a Data Sync ID with --extractor-args "youtube:data_sync_id=XXX"')

            return config_po_token

        # Require PO Token if logged in for external fetching