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

Code before:
        # we've hit a 403 with a client challenge, we need to solve it
        self.write_debug('Found facebook ads JS challenge')

        challenge_path = self._search_regex(
            r'''fetch\s*\(\s*['"](\/__rd_verify[^'"]+)['"]''',
            error_page,
            'challenge path',
            default=None,
        )
        if not challenge_path:
            raise ExtractorError(
                'Unable to extract rd_challenge.',
                expected=True,
            )

        # we have to POST to the challenge URL to get a cookie back (rd_challenge) (the system adds it to the cookie jar)
        full_challenge_url = urljoin(url, challenge_path)
        self._request_webpage(
            full_challenge_url,
            video_id,
            note='Solving rd_challenge',
            errnote='Failed to solve rd_challenge',
            expected_status=[200],
            fatal=True,
            data=b'',
        )

        # should have the required cookies now, so we try again
        return self._download_webpage(url, video_id)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_fb_webpage_and_verify(url, video_id)

        post_data = traverse_obj(
            re.findall(r'data-sjs>({.*?ScheduledServerJS.*?})</script>', webpage), (..., {json.loads}))
        data = get_first(post_data, (
            'require', ..., ..., ..., '__bbox', 'require', ..., ..., ...,
            'entryPointRoot', 'otherProps', 'deeplinkAdCard', 'snapshot', {dict}))
        if not data:
            raise ExtractorError('Unable to extract ad data')

        title = data.get('title')
        if not title or title == '{{product.name}}':
            title = join_nonempty('display_format', 'page_name', delim=' by ', from_dict=data)
        markup_id = traverse_obj(data, ('body', '__m', {str}))
        markup = traverse_obj(post_data, (
            ..., 'require', ..., ..., ..., '__bbox', 'markup', lambda _, v: v[0].startswith(markup_id),
            ..., '__html', {clean_html}, {lambda x: not x.startswith('{{product.') and x}, any))

        info_dict = merge_dicts({

Review comment (suggestion):
we can inline the `urljoin` call, remove default kwarg values
```suggestion
        self._request_webpage(
            urljoin(url, challenge_path), video_id, 'Requesting verification cookie',
            'Unable to get verification cookie', data=b'')
```

Code after:
                'ext': 'mp4',
                'quality': qualities(tuple(self._FORMATS_MAP))(format_key),
            })
        return formats

    def _download_fb_webpage_and_verify(self, url, video_id):
        # See https://github.com/yt-dlp/yt-dlp/issues/15577

        try:
            return self._download_webpage(url, video_id)
        except ExtractorError as e:
            if (
                not isinstance(e.cause, HTTPError)
                or e.cause.status != 403
                or e.cause.reason != 'Client challenge'
            ):
                raise
            error_page = self._webpage_read_content(e.cause.response, url, video_id)

        self.write_debug('Received a client challenge response')

        challenge_path = self._search_regex(
            r'fetch\s*\(\s*["\'](/__rd_verify[^"\']+)["\']',
            error_page, 'challenge path')

        # Successful response will set the necessary cookie
        self._request_webpage(
            urljoin(url, challenge_path), video_id, 'Requesting verification cookie',
            'Unable to get verification cookie', data=b'')

        return self._download_webpage(url, video_id)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_fb_webpage_and_verify(url, video_id)

        post_data = traverse_obj(
            re.findall(r'data-sjs>({.*?ScheduledServerJS.*?})</script>', webpage), (..., {json.loads}))
        data = get_first(post_data, (
            'require', ..., ..., ..., '__bbox', 'require', ..., ..., ...,
            'entryPointRoot', 'otherProps', 'deeplinkAdCard', 'snapshot', {dict}))
        if not data:
            raise ExtractorError('Unable to extract ad data')

        title = data.get('title')
        if not title or title == '{{product.name}}':
            title = join_nonempty('display_format', 'page_name', delim=' by ', from_dict=data)
        markup_id = traverse_obj(data, ('body', '__m', {str}))
        markup = traverse_obj(post_data, (
            ..., 'require', ..., ..., ..., '__bbox', 'markup', lambda _, v: v[0].startswith(markup_id),
            ..., '__html', {clean_html}, {lambda x: not x.startswith('{{product.') and x}, any))