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

Code before:
                'responsive_web_graphql_skip_user_profile_image_extensions_enabled': False,
                'responsive_web_graphql_timeline_navigation_enabled': True,
                'responsive_web_enhance_cards_enabled': False
            },
            'fieldToggles': {
                'withArticleRichContentState': False
            }
        }

    def _extract_status(self, twid):
        if self.is_logged_in:
            return self._graphql_to_legacy(
                self._call_graphql_api('zZXycP0V6H7m-2r0mOnFcA/TweetDetail', twid), twid)

        try:
            if self._configuration_arg('legacy_api'):
                status = traverse_obj(self._call_api(f'statuses/show/{twid}.json', twid, {
                    'cards_platform': 'Web-12',
                    'include_cards': 1,
                    'include_reply_count': 1,
                    'include_user_entities': 0,
                    'tweet_mode': 'extended',
                }), 'retweeted_status', None)
            else:
                status = self._graphql_to_legacy(
                    self._call_graphql_api('2ICDjqPd81tulZcYrtpTuQ/TweetResultByRestId', twid), twid)

        except ExtractorError as e:
            if e.expected:
                raise
            self.report_warning(
                f'{e.orig_msg}. Falling back to syndication endpoint; some metadata may be missing', twid)
            status = self._download_json(
                'https://cdn.syndication.twimg.com/tweet-result', twid, 'Downloading syndication JSON',
                headers={'User-Agent': 'Googlebot'}, query={'id': twid})
            status['extended_entities'] = {'media': status.get('mediaDetails')}

        return status

    def _real_extract(self, url):
        twid, selected_index = self._match_valid_url(url).group('id', 'index')
        status = self._extract_status(twid)

        title = description = traverse_obj(
            status, (('full_text', 'text'), {lambda x: x.replace('\n', ' ')}), get_all=False) or ''
        # strip  'https -_t.co_BJYgOjSeGA' junk from filenames
        title = re.sub(r'\s+(https?://[^ ]+)', '', title)
        user = status.get('user') or {}
        uploader = user.get('name')
        if uploader:
            title = f'{uploader} - {title}'

Review comment (suggestion):
```suggestion
            if not self._configuration_arg('legacy_api'):
                return self._graphql_to_legacy(
                    self._call_graphql_api('2ICDjqPd81tulZcYrtpTuQ/TweetResultByRestId', twid), twid)
            return traverse_obj(self._call_api(f'statuses/show/{twid}.json', twid, {
                'cards_platform': 'Web-12',
                'include_cards': 1,
                'include_reply_count': 1,
                'include_user_entities': 0,
                'tweet_mode': 'extended',
            }), 'retweeted_status', None)
```

Code after:
                'responsive_web_graphql_skip_user_profile_image_extensions_enabled': False,
                'responsive_web_graphql_timeline_navigation_enabled': True,
                'responsive_web_enhance_cards_enabled': False
            },
            'fieldToggles': {
                'withArticleRichContentState': False
            }
        }

    def _extract_status(self, twid):
        if self.is_logged_in:
            return self._graphql_to_legacy(
                self._call_graphql_api('zZXycP0V6H7m-2r0mOnFcA/TweetDetail', twid), twid)

        try:
            if not self._configuration_arg('legacy_api'):
                return self._graphql_to_legacy(
                    self._call_graphql_api('2ICDjqPd81tulZcYrtpTuQ/TweetResultByRestId', twid), twid)
            return traverse_obj(self._call_api(f'statuses/show/{twid}.json', twid, {
                'cards_platform': 'Web-12',
                'include_cards': 1,
                'include_reply_count': 1,
                'include_user_entities': 0,
                'tweet_mode': 'extended',
            }), 'retweeted_status', None)

        except ExtractorError as e:
            if e.expected:
                raise
            self.report_warning(
                f'{e.orig_msg}. Falling back to syndication endpoint; some metadata may be missing', twid)

        status = self._download_json(
            'https://cdn.syndication.twimg.com/tweet-result', twid, 'Downloading syndication JSON',
            headers={'User-Agent': 'Googlebot'}, query={'id': twid})
        status['extended_entities'] = {'media': status.get('mediaDetails')}
        return status

    def _real_extract(self, url):
        twid, selected_index = self._match_valid_url(url).group('id', 'index')
        status = self._extract_status(twid)

        title = description = traverse_obj(
            status, (('full_text', 'text'), {lambda x: x.replace('\n', ' ')}), get_all=False) or ''
        # strip  'https -_t.co_BJYgOjSeGA' junk from filenames
        title = re.sub(r'\s+(https?://[^ ]+)', '', title)
        user = status.get('user') or {}
        uploader = user.get('name')
        if uploader:
            title = f'{uploader} - {title}'
        uploader_id = user.get('screen_name')