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

Code before:
                        continue
                    format_url = format_item
                    format_url = url_or_none(format_url)
                    if not format_url or format_url in format_urls:
                        continue
                    format_urls.add(format_url)
                    formats.append({
                        'format_id': f'{format_id}-{quality}',
                        'url': format_url,
                        'ext': determine_ext(format_url, 'mp4'),
                        'height': get_height(quality),
                        'filesize': format_sizes.get(quality),
                        'http_headers': {
                            'Referer': urlh.url,
                        },
                    })
            xplayer_sources = try_get(
                initials, lambda x: x['xplayerSettings']['sources'], dict)
            if xplayer_sources:
                hls_sources = xplayer_sources.get('hls')
                if isinstance(hls_sources, dict):
                    if 'url' in hls_sources or 'fallback' in hls_sources:
                        for hls_format_key in ('url', 'fallback'):
                            hls_url = hls_sources.get(hls_format_key)
                            if not hls_url:
                                continue
                            hls_url = self._decipher_format_url(hls_url, f'hls-{hls_format_key}')
                            if not hls_url or hls_url in format_urls:
                                continue
                            format_urls.add(hls_url)
                            formats.extend(self._extract_m3u8_formats(
                                hls_url, video_id, 'mp4', entry_protocol='m3u8_native',
                                m3u8_id='hls', fatal=False))
                standard_sources = xplayer_sources.get('standard')
                if isinstance(standard_sources, dict):
                    for identifier, formats_list in standard_sources.items():
                        if not isinstance(formats_list, list):
                            continue
                        for standard_format in formats_list:
                            if not isinstance(standard_format, dict):
                                continue
                            for standard_format_key in ('url', 'fallback'):
                                standard_url = standard_format.get(standard_format_key)
                                if not standard_url:
                                    continue
                                quality = (str_or_none(standard_format.get('quality'))
                                           or str_or_none(standard_format.get('label'))
                                           or '')
                                format_id = join_nonempty(identifier, quality)
                                standard_url = self._decipher_format_url(standard_url, format_id)
                                if not standard_url or standard_url in format_urls:

Review comment (refactor):
Remove preceding two lines, "simplify" this part, and reindent the lines down to, but not including, original l.244 :
```suggestion
     
       for hls_format_key, hls_url in traverse_obj(initials, (
               'xplayerSettings', 'sources', 'hls', {dict.items},
               lambda _, k_v: k_v[0] in ('url', 'fallback') and k_v[1]))):
```

Code after:
                    })
            xplayer_sources = try_get(
                initials, lambda x: x['xplayerSettings']['sources'], dict)
            if xplayer_sources:
                hls_sources = xplayer_sources.get('hls')
                if isinstance(hls_sources, dict):
                    for hls_format_key in ('url', 'fallback'):
                        hls_url = hls_sources.get(hls_format_key)
                        if not hls_url:
                            continue
                        hls_url = self._decipher_format_url(hls_url, f'hls-{hls_format_key}')
                        if not hls_url or hls_url in format_urls:
                            continue
                        format_urls.add(hls_url)
                        formats.extend(self._extract_m3u8_formats(
                            hls_url, video_id, 'mp4', entry_protocol='m3u8_native',
                            m3u8_id='hls', fatal=False))
                standard_sources = xplayer_sources.get('standard')
                if isinstance(standard_sources, dict):
                    for identifier, formats_list in standard_sources.items():
                        if not isinstance(formats_list, list):
                            continue
                        for standard_format in formats_list:
                            if not isinstance(standard_format, dict):
                                continue
                            for standard_format_key in ('url', 'fallback'):
                                standard_url = standard_format.get(standard_format_key)
                                if not standard_url:
                                    continue
                                quality = (str_or_none(standard_format.get('quality'))
                                           or str_or_none(standard_format.get('label'))
                                           or '')
                                format_id = join_nonempty(identifier, quality)
                                standard_url = self._decipher_format_url(standard_url, format_id)
                                if not standard_url or standard_url in format_urls:
                                    continue
                                format_urls.add(standard_url)
                                ext = determine_ext(standard_url, 'mp4')
                                if ext == 'm3u8':
                                    formats.extend(self._extract_m3u8_formats(
                                        standard_url, video_id, 'mp4', entry_protocol='m3u8_native',
                                        m3u8_id='hls', fatal=False))
                                    continue

                                formats.append({
                                    'format_id': format_id,
                                    'url': standard_url,
                                    'ext': ext,
                                    'height': get_height(quality),
                                    'filesize': format_sizes.get(quality),
                                    'http_headers': {