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

Code before:
        for alert_type, alert_message in alerts:
            if alert_type.lower() == 'error':
                errors.append([alert_type, alert_message])
            else:
                warnings.append([alert_type, alert_message])

        for alert_type, alert_message in (warnings + errors[:-1]):
            self.report_warning('YouTube said: %s - %s' % (alert_type, alert_message))
        if errors:
            raise ExtractorError('YouTube said: %s' % errors[-1][1], expected=expected)

    def _extract_and_report_alerts(self, data, *args, **kwargs):
        return self._report_alerts(self._extract_alerts(data), *args, **kwargs)

    def _extract_badges(self, renderer: dict):
        badges = set()
        for badge in try_get(renderer, lambda x: x['badges'], list) or []:
            label = try_get(badge, lambda x: x['metadataBadgeRenderer']['label'], compat_str)
            if label:
                badges.add(label.lower())
        return badges

    @staticmethod
    def _get_text(data, getter=None, max_runs=None):
        for get in variadic(getter):
            d = try_get(data, get) or data
            text = try_get(d, lambda x: x['simpleText'], compat_str)
            if text:
                return text
            runs = try_get(d, lambda x: x['runs'], list) or []
            if not runs and isinstance(d, list):
                runs = d

            def get_runs(runs):
                for i in range(0, min(len(runs), max_runs or len(runs))):
                    yield try_get(runs[i], lambda x: x['text'], compat_str) or ''

            text = ''.join(get_runs(runs))
            if text:
                return text

    def _extract_response(self, item_id, query, note='Downloading API JSON', headers=None,
                          ytcfg=None, check_get_keys=None, ep='browse', fatal=True, api_hostname=None,
                          default_client='WEB'):
        response = None
        last_error = None
        count = -1
        retries = self.get_param('extractor_retries', 3)
        if check_get_keys is None:
            check_get_keys = []
        while count < retries:

Review comment (suggestion):
```suggestion
            d = try_get(data, get) if get is not None else data
```
right? since it shouldn't fallback to data if try_get returns None

Code after:
                message = cls._get_text(alert.get('text'))
                if message:
                    yield alert_type, message

    def _report_alerts(self, alerts, expected=True):
        errors = []
        warnings = []
        for alert_type, alert_message in alerts:
            if alert_type.lower() == 'error':
                errors.append([alert_type, alert_message])
            else:
                warnings.append([alert_type, alert_message])

        for alert_type, alert_message in (warnings + errors[:-1]):
            self.report_warning('YouTube said: %s - %s' % (alert_type, alert_message))
        if errors:
            raise ExtractorError('YouTube said: %s' % errors[-1][1], expected=expected)

    def _extract_and_report_alerts(self, data, *args, **kwargs):
        return self._report_alerts(self._extract_alerts(data), *args, **kwargs)

    def _extract_badges(self, renderer: dict):
        badges = set()
        for badge in try_get(renderer, lambda x: x['badges'], list) or []:
            label = try_get(badge, lambda x: x['metadataBadgeRenderer']['label'], compat_str)
            if label:
                badges.add(label.lower())
        return badges

    @staticmethod
    def _get_text(data, getter=None, max_runs=None):
        for get in variadic(getter):
            d = try_get(data, get) if get is not None else data
            text = try_get(d, lambda x: x['simpleText'], compat_str)
            if text:
                return text
            runs = try_get(d, lambda x: x['runs'], list) or []
            if not runs and isinstance(d, list):
                runs = d

            def get_runs(runs):
                for run in runs[:min(len(runs), max_runs or len(runs))]:
                    yield try_get(run, lambda x: x['text'], compat_str) or ''

            text = ''.join(get_runs(runs))
            if text:
                return text

    def _extract_response(self, item_id, query, note='Downloading API JSON', headers=None,
                          ytcfg=None, check_get_keys=None, ep='browse', fatal=True, api_hostname=None,
                          default_client='WEB'):