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

Code before:
                media_json = video_json.get('media') or {}
                if api_only and not media_json.get('url') and not video_json.get('url'):
                    raise ExtractorError('Failed to find video data for dashboard-only post')
                provider = video_json.get('provider')
                is_provider_ambiguous = provider in self._ambiguous_providers

                if provider in ('tumblr', None):
                    fallback_format = {
                        'url': media_json.get('url') or video_url,
                        'width': int_or_none(
                            media_json.get('width') or self._og_search_property('video:width', webpage, default=None)),
                        'height': int_or_none(
                            media_json.get('height') or self._og_search_property('video:height', webpage, default=None)),
                    }
                    continue
                elif provider in self._unsupported_providers:
                    ignored_providers.add(provider)
                    continue
                elif provider and not is_provider_ambiguous and provider not in self._providers:
                    unknown_providers.add(provider)

                if video_json.get('url'):
                    # external video host
                    entries.append(self.url_result(
                        video_json['url'],
                        self._providers.get(provider, 'Generic') if not is_provider_ambiguous else None))

        duration = None

        # iframes can supply duration and sometimes additional formats, so check for one
        iframe_url = self._search_regex(
            fr'src=\'(https?://www\.tumblr\.com/video/{blog}/{video_id}/[^\']+)\'',
            webpage, 'iframe url', default=None)
        if iframe_url:
            iframe = self._download_webpage(
                iframe_url, video_id, 'Downloading iframe page',
                headers={'Referer': redirect_url})

            options = self._parse_json(
                self._search_regex(
                    r'data-crt-options=(["\'])(?P<options>.+?)\1', iframe,
                    'hd video url', default='', group='options'),
                video_id, fatal=False)
            if options:
                duration = int_or_none(options.get('duration'))

                hd_url = options.get('hdUrl')
                if hd_url:
                    # there are multiple formats; extract them
                    # ignore other sources of width/height data as they may be wrong
                    sources = []

Review comment (refactor):
If applying the above suggestion about moving `_ambiguous_providers` into `_providers`, we can simplify like this:
```suggestion
                elif provider and and provider not in self._providers:
                    unknown_providers.add(provider)

                if video_json.get('url'):
                    # external video host
                    entries.append(self.url_result(
                        video_json['url'], self._providers.get(provider)))
```

Code after:
        video_url = self._og_search_video_url(webpage, default=None)
        # for external video hosts
        entries = []
        ignored_providers = set()
        unknown_providers = set()

        for video_json in traverse_obj(content_json, lambda _, v: v['type'] in ('video', 'audio')):
            media_json = video_json.get('media') or {}
            if api_only and not media_json.get('url') and not video_json.get('url'):
                raise ExtractorError('Failed to find video data for dashboard-only post')
            provider = video_json.get('provider')

            if provider in ('tumblr', None):
                fallback_format = {
                    'url': media_json.get('url') or video_url,
                    'width': int_or_none(
                        media_json.get('width') or self._og_search_property('video:width', webpage, default=None)),
                    'height': int_or_none(
                        media_json.get('height') or self._og_search_property('video:height', webpage, default=None)),
                }
                continue
            elif provider in self._unsupported_providers:
                ignored_providers.add(provider)
                continue
            elif provider and provider not in self._providers:
                unknown_providers.add(provider)
            if video_json.get('url'):
                # external video host
                entries.append(self.url_result(
                    video_json['url'], self._providers.get(provider)))

        duration = None

        # iframes can supply duration and sometimes additional formats, so check for one
        iframe_url = self._search_regex(
            fr'src=\'(https?://www\.tumblr\.com/video/{blog}/{video_id}/[^\']+)\'',
            webpage, 'iframe url', default=None)
        if iframe_url:
            iframe = self._download_webpage(
                iframe_url, video_id, 'Downloading iframe page',
                headers={'Referer': redirect_url})

            options = self._parse_json(
                self._search_regex(
                    r'data-crt-options=(["\'])(?P<options>.+?)\1', iframe,
                    'hd video url', default='', group='options'),
                video_id, fatal=False)
            if options:
                duration = int_or_none(options.get('duration'))

                hd_url = options.get('hdUrl')