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

Code before:
    def _extract_api_key(self, ytcfg=None):
        return try_get(ytcfg, lambda x: x['INNERTUBE_API_KEY'], compat_str) or self._YT_INNERTUBE_API_KEY

    def _extract_yt_initial_data(self, video_id, webpage):
        return self._parse_json(
            self._search_regex(
                (r'%s\s*%s' % (self._YT_INITIAL_DATA_RE, self._YT_INITIAL_BOUNDARY_RE),
                 self._YT_INITIAL_DATA_RE), webpage, 'yt initial data'),
            video_id)

    def _extract_identity_token(self, webpage, item_id):
        ytcfg = self._extract_ytcfg(item_id, webpage)
        if ytcfg:
            token = try_get(ytcfg, lambda x: x['ID_TOKEN'], compat_str)
            if token:
                return token
        return self._search_regex(
            r'\bID_TOKEN["\']\s*:\s*["\'](.+?)["\']', webpage,
            'identity token', default=None)

    @staticmethod
    def _extract_account_syncid(data):
        """
        Extract syncId required to download private playlists of secondary channels
        params:
        - data: can be either response or ytcfg
        """
        sync_ids = (try_get(
            data, (lambda x: x['responseContext']['mainAppWebResponseContext']['datasyncId'],
                   lambda x: x['DATASYNC_ID']), compat_str) or '').split("||")
        if len(sync_ids) >= 2 and sync_ids[1]:
            # datasyncid is of the form "channel_syncid||user_syncid" for secondary channel
            # and just "user_syncid||" for primary channel. We only want the channel_syncid
            return sync_ids[0]
        # ytcfg includes channel_syncid if on secondary channel
        return data.get('DELEGATED_SESSION_ID')

    def _extract_ytcfg(self, video_id, webpage):
        return self._parse_json(
            self._search_regex(
                r'ytcfg\.set\s*\(\s*({.+?})\s*\)\s*;', webpage, 'ytcfg',
                default='{}'), video_id, fatal=False) or {}

    def __extract_client_version(self, ytcfg):
        return try_get(ytcfg, lambda x: x['INNERTUBE_CLIENT_VERSION'], compat_str) or self._YT_WEB_CLIENT_VERSION

    def _extract_context(self, ytcfg=None):
        context = try_get(ytcfg, lambda x: x['INNERTUBE_CONTEXT'], dict)
        if context:
            return context


Review comment (suggestion):
```suggestion
        @param data Either response or ytcfg
```

This is the standard, although I probably missed this in the earlier PRs

Code after:
    def _extract_api_key(self, ytcfg=None):
        return try_get(ytcfg, lambda x: x['INNERTUBE_API_KEY'], compat_str) or self._YT_INNERTUBE_API_KEY

    def _extract_yt_initial_data(self, video_id, webpage):
        return self._parse_json(
            self._search_regex(
                (r'%s\s*%s' % (self._YT_INITIAL_DATA_RE, self._YT_INITIAL_BOUNDARY_RE),
                 self._YT_INITIAL_DATA_RE), webpage, 'yt initial data'),
            video_id)

    def _extract_identity_token(self, webpage, item_id):
        ytcfg = self._extract_ytcfg(item_id, webpage)
        if ytcfg:
            token = try_get(ytcfg, lambda x: x['ID_TOKEN'], compat_str)
            if token:
                return token
        return self._search_regex(
            r'\bID_TOKEN["\']\s*:\s*["\'](.+?)["\']', webpage,
            'identity token', default=None)

    @staticmethod
    def _extract_account_syncid(data):
        """
        Extract syncId required to download private playlists of secondary channels
        @param data Either response or ytcfg
        """
        sync_ids = (try_get(
            data, (lambda x: x['responseContext']['mainAppWebResponseContext']['datasyncId'],
                   lambda x: x['DATASYNC_ID']), compat_str) or '').split("||")
        if len(sync_ids) >= 2 and sync_ids[1]:
            # datasyncid is of the form "channel_syncid||user_syncid" for secondary channel
            # and just "user_syncid||" for primary channel. We only want the channel_syncid
            return sync_ids[0]
        # ytcfg includes channel_syncid if on secondary channel
        return data.get('DELEGATED_SESSION_ID')

    def _extract_ytcfg(self, video_id, webpage):
        return self._parse_json(
            self._search_regex(
                r'ytcfg\.set\s*\(\s*({.+?})\s*\)\s*;', webpage, 'ytcfg',
                default='{}'), video_id, fatal=False) or {}

    def __extract_client_version(self, ytcfg):
        return try_get(ytcfg, lambda x: x['INNERTUBE_CLIENT_VERSION'], compat_str) or self._YT_WEB_CLIENT_VERSION

    def _extract_context(self, ytcfg=None):
        context = try_get(ytcfg, lambda x: x['INNERTUBE_CONTEXT'], dict)
        if context:
            return context

        # Recreate the client context (required)