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

Code before:
        # stripped out even if not requested by the user
        # See: https://github.com/yt-dlp/yt-dlp/issues/501
        yielded_pr = False
        if initial_pr:
            pr = dict(initial_pr)
            pr['streamingData'] = None
            yielded_pr = True
            yield pr

        last_error = None
        tried_iframe_fallback = False
        player_url = None
        while clients:
            client = clients.pop()
            player_ytcfg = master_ytcfg if client == 'web' else {}
            if 'configs' not in self._configuration_arg('player_skip'):
                player_ytcfg = self._extract_player_ytcfg(client, video_id) or player_ytcfg

            player_url = player_url or self._extract_player_url(master_ytcfg, player_ytcfg, webpage=webpage)
            require_js_player = self._get_default_ytcfg(client).get('REQUIRE_JS_PLAYER')
            if 'js' in self._configuration_arg('player_skip'):
                require_js_player = False
                player_url = None

            if not player_url and not tried_iframe_fallback and require_js_player:
                player_url = self._download_player_url(video_id)
                tried_iframe_fallback = True

            try:
                pr = initial_pr if client == 'web' and initial_pr else self._extract_player_response(
                    client, video_id, player_ytcfg or master_ytcfg, player_ytcfg, identity_token, player_url, initial_pr, require_js_player)
            except ExtractorError as e:
                if last_error:
                    self.report_warning(last_error)
                last_error = e
                continue

            if pr:
                yielded_pr = True
                yield pr

            # creator clients can bypass AGE_VERIFICATION_REQUIRED if logged in
            if client.endswith('_agegate') and self._is_unplayable(pr) and self._generate_sapisidhash_header():
                append_client(client.replace('_agegate', '_creator'))
            elif self._is_agegated(pr):
                append_client(f'{client}_agegate')

        yield player_url
        if last_error:
            if not yielded_pr:
                raise last_error

Review comment (refactor):
assuming `require_js_player` doesnt need to be passed to `_extract_player_response`, this can be simplified

Code after:
        # extraction of some data. So we return the initial_pr with formats
        # stripped out even if not requested by the user
        # See: https://github.com/yt-dlp/yt-dlp/issues/501
        if initial_pr:
            pr = dict(initial_pr)
            pr['streamingData'] = None
            prs.append(pr)

        last_error = None
        tried_iframe_fallback = False
        player_url = None
        while clients:
            client = clients.pop()
            player_ytcfg = master_ytcfg if client == 'web' else {}
            if 'configs' not in self._configuration_arg('player_skip'):
                player_ytcfg = self._extract_player_ytcfg(client, video_id) or player_ytcfg

            player_url = player_url or self._extract_player_url(master_ytcfg, player_ytcfg, webpage=webpage)
            require_js_player = self._get_default_ytcfg(client).get('REQUIRE_JS_PLAYER')
            if 'js' in self._configuration_arg('player_skip'):
                require_js_player = False
                player_url = None

            if not player_url and not tried_iframe_fallback and require_js_player:
                player_url = self._download_player_url(video_id)
                tried_iframe_fallback = True

            try:
                pr = initial_pr if client == 'web' and initial_pr else self._extract_player_response(
                    client, video_id, player_ytcfg or master_ytcfg, player_ytcfg, identity_token, player_url if require_js_player else None, initial_pr)
            except ExtractorError as e:
                if last_error:
                    self.report_warning(last_error)
                last_error = e
                continue

            if pr:
                prs.append(pr)

            # creator clients can bypass AGE_VERIFICATION_REQUIRED if logged in
            if client.endswith('_agegate') and self._is_unplayable(pr) and self._generate_sapisidhash_header():
                append_client(client.replace('_agegate', '_creator'))
            elif self._is_agegated(pr):
                append_client(f'{client}_agegate')

        if last_error:
            if not len(prs):
                raise last_error
            self.report_warning(last_error)
        return prs, player_url