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

Code before:

        formats = []
        for info in video_info:
            format_info = traverse_obj(info, {
                'fps': 'fps',
                'width': 'width',
                'height': 'height',
                'vcodec': 'videoCodec',
                'acodec': 'audioCodec',
                'abr': 'audioBitrate',
                'vbr': 'videoBitrate',
                'audio_channels': 'audioChannels',
                'tbr': 'avgBitrate',
                'format': 'qualityType',
                'filesize': 'size',
                'duration': ('duration', {lambda x: float_or_none(x, scale=1000)})
            })

            formats.extend(traverse_obj(info, (('mediaUrl', ('backupUrls', ...)), {
                lambda url: url_or_none(url) and {'url': url, 'ext': 'mp4', **format_info}})))

        thumbnails = []
        for image_info in traverse_obj(note_info, ('imageList', ...)):
            thumbnail_info = traverse_obj(image_info, {
                'height': 'height',
                'width': 'width'
            })
            for url in traverse_obj(image_info, (('urlDefault', 'urlPre'), {url_or_none})):
                thumbnails.append({
                    'url': url,
                    **thumbnail_info
                })

        return {
            'id': display_id,
            'formats': formats or [{
                'url': self._html_search_meta(['og:video'], webpage, fatal=True),
                'ext': 'mp4'
            }],
            'thumbnails': thumbnails or [{
                'url': self._html_search_meta(['og:image'], webpage, default=None)
            }],
            'title': self._html_search_meta(['og:title'], webpage, default=None),
            **traverse_obj(note_info, {
                'title': 'title',
                'description': 'desc',
                'tags': ('tagList', ..., 'name', {str}),
                'uploader_id': ('user', 'userId'),
            }),
        }


Review comment (suggestion):
```suggestion
                'height': ('height', {int_or_none}),
                'width': ('width', {int_or_none}),
```

Code after:

        note_info = traverse_obj(initial_state, ('note', 'noteDetailMap', display_id, 'note'))
        video_info = traverse_obj(note_info, ('video', 'media', 'stream', ('h264', 'av1', 'h265'), ...))

        formats = []
        for info in video_info:
            format_info = traverse_obj(info, {
                'fps': ('fps', {int_or_none}),
                'width': ('width', {int_or_none}),
                'height': ('height', {int_or_none}),
                'vcodec': ('videoCodec', {str}),
                'acodec': ('audioCodec', {str}),
                'abr': ('audioBitrate', {int_or_none}),
                'vbr': ('videoBitrate', {int_or_none}),
                'audio_channels': ('audioChannels', {int_or_none}),
                'tbr': ('avgBitrate', {int_or_none}),
                'format': ('qualityType', {str}),
                'filesize': ('size', {int_or_none}),
                'duration': ('duration', {functools.partial(float_or_none, scale=1000)})
            })

            formats.extend(traverse_obj(info, (('mediaUrl', ('backupUrls', ...)), {
                lambda u: url_or_none(u) and {'url': u, **format_info}})))

        thumbnails = []
        for image_info in traverse_obj(note_info, ('imageList', ...)):
            thumbnail_info = traverse_obj(image_info, {
                'height': ('height', {int_or_none}),
                'width': ('width', {int_or_none}),
            })
            for thumb_url in traverse_obj(image_info, (('urlDefault', 'urlPre'), {url_or_none})):
                thumbnails.append({
                    'url': thumb_url,
                    **thumbnail_info,
                })

        return {
            'id': display_id,
            'formats': formats,
            'thumbnails': thumbnails,
            'title': self._html_search_meta(['og:title'], webpage, default=None),
            **traverse_obj(note_info, {
                'title': ('title', {str}),
                'description': ('desc', {str}),
                'tags': ('tagList', ..., 'name', {str}),
                'uploader_id': ('user', 'userId', {str}),
            }),
        }