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

Code before:

            stream = self._download_json(
                f'{self._BASE_URL}/api/v2/cdn/delivery', media_id, query={
                    'type': 'vod' if media_typ == 'video' else 'aod',
                    'guid': metadata['guid'],
                }, note=f'Downloading {media_typ} stream data',
                impersonate=self._IMPERSONATE_TARGET)

            path_template = traverse_obj(stream, ('resource', 'uri', {str}))

            def format_path(params):
                path = path_template
                for i, val in (params or {}).items():
                    path = path.replace(f'{{qualityLevelParams.{i}}}', val)
                return path

            formats = []
            for quality in traverse_obj(stream, ('resource', 'data', 'qualityLevels', ...)):
                url = urljoin(stream['cdn'], format_path(traverse_obj(
                    stream, ('resource', 'data', 'qualityLevelParams', quality['name'], {dict}))))
                format_id = traverse_obj(quality, ('name', {str}))

                m3u8_data = self._download_webpage(
                    url, media_id, fatal=False, impersonate=self._IMPERSONATE_TARGET,
                    note=join_nonempty('Downloading', format_id, 'm3u8 information', delim=' '),
                    errnote=join_nonempty('Failed to download', format_id, 'm3u8 information', delim=' '), headers=self._HEADERS)
                if not m3u8_data:
                    continue
                hls_aes = {}
                key_url = self._search_regex(
                    r'#EXT-X-KEY:METHOD=AES-128,URI="(https?://[^"]+)"',
                    m3u8_data, 'HLS AES key URI', default=None)
                if key_url:
                    urlh = self._request_webpage(
                        key_url, media_id, fatal=False, impersonate=self._IMPERSONATE_TARGET,
                        note=join_nonempty('Downloading', format_id, 'HLS AES key', delim=' '),
                        errnote=join_nonempty('Failed to download', format_id, 'HLS AES key', delim=' '),
                    )
                    if urlh:
                        hls_aes['key'] = urlh.read().hex()
                formats.append({
                    **traverse_obj(quality, {
                        'format_note': ('label', {str}),
                        'width': ('width', {int}),
                        'height': ('height', {int}),
                    }),
                    **parse_codecs(quality.get('codecs')),
                    'url': url,
                    'ext': determine_ext(url.partition('/chunk.m3u8')[0], 'mp4'),
                    'format_id': format_id,
                    'hls_media_playlist_data': m3u8_data,

Review comment (bug):
just for line length
```suggestion
                m3u8_data = self._download_webpage(
                    url, media_id, fatal=False, impersonate=self._IMPERSONATE_TARGET, headers=self._HEADERS,
                    note=join_nonempty('Downloading', format_id, 'm3u8 information', delim=' '),
                    errnote=join_nonempty('Failed to download', format_id, 'm3u8 information', delim=' '))
```

Code after:

            stream = self._download_json(
                f'{self._BASE_URL}/api/v2/cdn/delivery', media_id, query={
                    'type': 'vod' if media_typ == 'video' else 'aod',
                    'guid': metadata['guid'],
                }, note=f'Downloading {media_typ} stream data',
                impersonate=self._IMPERSONATE_TARGET)

            path_template = traverse_obj(stream, ('resource', 'uri', {str}))

            def format_path(params):
                path = path_template
                for i, val in (params or {}).items():
                    path = path.replace(f'{{qualityLevelParams.{i}}}', val)
                return path

            formats = []
            for quality in traverse_obj(stream, ('resource', 'data', 'qualityLevels', ...)):
                url = urljoin(stream['cdn'], format_path(traverse_obj(
                    stream, ('resource', 'data', 'qualityLevelParams', quality['name'], {dict}))))
                format_id = traverse_obj(quality, ('name', {str}))
                hls_aes = {}
                m3u8_data = None

                # If we need impersonation for the API, then we need it for HLS keys too: extract in advance
                if self._IMPERSONATE_TARGET is not None:
                    m3u8_data = self._download_webpage(
                        url, media_id, fatal=False, impersonate=self._IMPERSONATE_TARGET, headers=self._HEADERS,
                        note=join_nonempty('Downloading', format_id, 'm3u8 information', delim=' '),
                        errnote=join_nonempty('Failed to download', format_id, 'm3u8 information', delim=' '))
                    if not m3u8_data:
                        continue

                    key_url = self._search_regex(
                        r'#EXT-X-KEY:METHOD=AES-128,URI="(https?://[^"]+)"',
                        m3u8_data, 'HLS AES key URI', default=None)
                    if key_url:
                        urlh = self._request_webpage(
                            key_url, media_id, fatal=False, impersonate=self._IMPERSONATE_TARGET, headers=self._HEADERS,
                            note=join_nonempty('Downloading', format_id, 'HLS AES key', delim=' '),
                            errnote=join_nonempty('Failed to download', format_id, 'HLS AES key', delim=' '))
                        if urlh:
                            hls_aes['key'] = urlh.read().hex()

                formats.append({
                    **traverse_obj(quality, {
                        'format_note': ('label', {str}),
                        'width': ('width', {int}),
                        'height': ('height', {int}),
                    }),
                    **parse_codecs(quality.get('codecs')),