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

Code before:
                return extract_video_data(try_get(
                    js_data, lambda x: x['jsmods']['instances'], list) or [])

        def extract_dash_manifest(video, formats):
            dash_manifest = traverse_obj(video, 'dash_manifest', 'playlist', expected_type=str)
            if dash_manifest:
                formats.extend(self._parse_mpd_formats(
                    compat_etree_fromstring(urllib.parse.unquote_plus(dash_manifest)),
                    mpd_url=video.get('dash_manifest_url')))

        def process_formats(info):
            # Downloads with browser's User-Agent are rate limited. Working around
            # with non-browser User-Agent.
            for f in info['formats']:
                # Downloads with browser's User-Agent are rate limited. Working around
                # with non-browser User-Agent.
                f.setdefault('http_headers', {})['User-Agent'] = 'facebookexternalhit/1.1'
                # Formats larger than ~500MB will return error 403 unless chunk size is regulated
                f.setdefault('downloader_options', {})['http_chunk_size'] = 250 << 20

        def yield_all_relay_data(_filter):
            for relay_data in re.findall(rf'data-sjs>({{.*?{_filter}.*?}})</script>', webpage):
                yield self._parse_json(relay_data, video_id, fatal=False) or {}

        def extract_relay_data(_filter):
            return next(yield_all_relay_data(_filter), {})

        def extract_relay_prefetched_data(_filter, target_keys=None):
            path = 'data'
            if target_keys is not None:
                path = lambda k, v: k == 'data' and any(target in v for target in variadic(target_keys))
            return traverse_obj(yield_all_relay_data(_filter), (
                ..., 'require', (None, (..., ..., ..., '__bbox', 'require')),
                lambda _, v: any(key.startswith('RelayPrefetchedStreamCache') for key in v),
                ..., ..., '__bbox', 'result', path, {dict}), get_all=False) or {}

        if not video_data:
            server_js_data = self._parse_json(self._search_regex([
                r'bigPipe\.onPageletArrive\(({.+?})\)\s*;\s*}\s*\)\s*,\s*["\']onPageletArrive\s+' + self._SUPPORTED_PAGLETS_REGEX,
                rf'bigPipe\.onPageletArrive\(({{.*?id\s*:\s*"{self._SUPPORTED_PAGLETS_REGEX}".*?}})\);',
            ], webpage, 'js data', default='{}'), video_id, js_to_json, False)
            video_data = extract_from_jsmods_instances(server_js_data)

        if not video_data:
            data = extract_relay_prefetched_data(
                r'"(?:dash_manifest|playable_url(?:_quality_hd)?)',
                target_keys=('video', 'event', 'nodes', 'node', 'mediaset'))
            if data:
                entries = []

                def parse_graphql_video(video):

Review comment (suggestion):
Shouldnt we try to find one that has info? or am i missing something?
```suggestion
            return next(filter(None, yield_all_relay_data(_filter)), {})
```

Code after:
                return extract_video_data(try_get(
                    js_data, lambda x: x['jsmods']['instances'], list) or [])

        def extract_dash_manifest(video, formats):
            dash_manifest = traverse_obj(video, 'dash_manifest', 'playlist', expected_type=str)
            if dash_manifest:
                formats.extend(self._parse_mpd_formats(
                    compat_etree_fromstring(urllib.parse.unquote_plus(dash_manifest)),
                    mpd_url=video.get('dash_manifest_url')))

        def process_formats(info):
            # Downloads with browser's User-Agent are rate limited. Working around
            # with non-browser User-Agent.
            for f in info['formats']:
                # Downloads with browser's User-Agent are rate limited. Working around
                # with non-browser User-Agent.
                f.setdefault('http_headers', {})['User-Agent'] = 'facebookexternalhit/1.1'
                # Formats larger than ~500MB will return error 403 unless chunk size is regulated
                f.setdefault('downloader_options', {})['http_chunk_size'] = 250 << 20

        def yield_all_relay_data(_filter):
            for relay_data in re.findall(rf'data-sjs>({{.*?{_filter}.*?}})</script>', webpage):
                yield self._parse_json(relay_data, video_id, fatal=False) or {}

        def extract_relay_data(_filter):
            return next(filter(None, yield_all_relay_data(_filter)), {})

        def extract_relay_prefetched_data(_filter, target_keys=None):
            path = 'data'
            if target_keys is not None:
                path = lambda k, v: k == 'data' and any(target in v for target in variadic(target_keys))
            return traverse_obj(yield_all_relay_data(_filter), (
                ..., 'require', (None, (..., ..., ..., '__bbox', 'require')),
                lambda _, v: any(key.startswith('RelayPrefetchedStreamCache') for key in v),
                ..., ..., '__bbox', 'result', path, {dict}), get_all=False) or {}

        if not video_data:
            server_js_data = self._parse_json(self._search_regex([
                r'bigPipe\.onPageletArrive\(({.+?})\)\s*;\s*}\s*\)\s*,\s*["\']onPageletArrive\s+' + self._SUPPORTED_PAGLETS_REGEX,
                rf'bigPipe\.onPageletArrive\(({{.*?id\s*:\s*"{self._SUPPORTED_PAGLETS_REGEX}".*?}})\);',
            ], webpage, 'js data', default='{}'), video_id, js_to_json, False)
            video_data = extract_from_jsmods_instances(server_js_data)

        if not video_data:
            data = extract_relay_prefetched_data(
                r'"(?:dash_manifest|playable_url(?:_quality_hd)?)',
                target_keys=('video', 'event', 'nodes', 'node', 'mediaset'))
            if data:
                entries = []

                def parse_graphql_video(video):