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

Code before:
                'ks': '{1:result:ks}',
            },
            # captions
            {
                'action': 'list',
                'filter:entryIdEqual': video_id,
                'service': 'caption_captionasset',
                'ks': '{1:result:ks}',
            },
        ]
        # second object (representing the second start widget session) is None
        header, _, _info, flavor_assets, captions = self._kaltura_api_call(
            video_id, actions, service_url, note='Downloading video info JSON (Kaltura kwidget player)')
        info = _info['objects'][0]
        return header, info, flavor_assets, captions

    def _real_extract(self, url):
        url, smuggled_data = unsmuggle_url(url, {})

        mobj = self._match_valid_url(url)
        partner_id, entry_id = mobj.group('partner_id', 'id')
        ks = None
        captions = None
        player_type = 'html5'
        if 'html5lib/v2' in url:
            player_type = 'kwidget'
        if partner_id and entry_id:
            _, info, flavor_assets, captions = self._get_video_info(entry_id, partner_id, smuggled_data.get('service_url'), player_type=player_type)
        else:
            path, query = mobj.group('path', 'query')
            if not path and not query:
                raise ExtractorError('Invalid URL', expected=True)
            params = {}
            if query:
                params = compat_parse_qs(query)
            if path:
                splitted_path = path.split('/')
                params.update(dict((zip(splitted_path[::2], [[v] for v in splitted_path[1::2]]))))
            if 'wid' in params:
                if params['wid'][0].startswith('_'):
                    partner_id = params['wid'][0][1:]
                else:
                    partner_id = params['wid'][0]
            elif 'p' in params:
                partner_id = params['p'][0]
            elif 'partner_id' in params:
                partner_id = params['partner_id'][0]
            else:
                raise ExtractorError('Invalid URL', expected=True)
            if 'entry_id' in params:
                entry_id = params['entry_id'][0]

Review comment (suggestion):
```suggestion
        player_type = 'kwidget' if 'html5lib/v2' in url else 'html5'
```

Code after:
                'ks': '{1:result:ks}',
            },
            # captions
            {
                'action': 'list',
                'filter:entryIdEqual': video_id,
                'service': 'caption_captionasset',
                'ks': '{1:result:ks}',
            },
        ]
        # second object (representing the second start widget session) is None
        header, _, _info, flavor_assets, captions = self._kaltura_api_call(
            video_id, actions, service_url, note='Downloading video info JSON (Kaltura kwidget player)')
        info = _info['objects'][0]
        return header, info, flavor_assets, captions

    def _build_widget_id(self, partner_id):
        return partner_id if '_' in partner_id else f'_{partner_id}'

    IFRAME_PACKAGE_DATA_REGEX = r'window\.kalturaIframePackageData\s*='

    def _real_extract(self, url):
        url, smuggled_data = unsmuggle_url(url, {})

        mobj = self._match_valid_url(url)
        partner_id, entry_id, player_type = mobj.group('partner_id', 'id', 'player_type')
        ks, captions = None, None
        if not player_type:
            player_type = 'kwidget' if 'html5lib/v2' in url else 'html5'
        if partner_id and entry_id:
            _, info, flavor_assets, captions = self._get_video_info(entry_id, partner_id, smuggled_data.get('service_url'), player_type=player_type)
        else:
            path, query = mobj.group('path', 'query')
            if not path and not query:
                raise ExtractorError('Invalid URL', expected=True)
            params = {}
            if query:
                params = compat_parse_qs(query)
            if path:
                splitted_path = path.split('/')
                params.update(dict((zip(splitted_path[::2], [[v] for v in splitted_path[1::2]]))))
            if 'wid' in params:
                partner_id = remove_start(params['wid'][0], '_')
            elif 'p' in params:
                partner_id = params['p'][0]
            elif 'partner_id' in params:
                partner_id = params['partner_id'][0]
            else:
                raise ExtractorError('Invalid URL', expected=True)
            if 'entry_id' in params:
                entry_id = params['entry_id'][0]