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

Code before:
                'width': ('width', {int_or_none}),
                'height': ('height', {int_or_none}),
                'vcodec': ('videoCodec', {str}),
                'acodec': ('audioCodec', {str}),
                'abr': ('audioBitrate', {int_or_none(scale=1000)}),
                'vbr': ('videoBitrate', {int_or_none(scale=1000)}),
                'audio_channels': ('audioChannels', {int_or_none}),
                'tbr': ('avgBitrate', {int_or_none(scale=1000)}),
                'format': ('qualityType', {str}),
                'filesize': ('size', {int_or_none}),
                'duration': ('duration', {float_or_none(scale=1000)}),
            })

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

        if origin_key := traverse_obj(note_info, ('video', 'consumer', 'originVideoKey', {str})):
            # Not using a head request because of false negatives
            urlh = self._request_webpage(
                f'https://sns-video-bd.xhscdn.com/{origin_key}', display_id,
                'Checking original video availability', 'Original video is not available', fatal=False)
            if urlh:
                formats.append({
                    'format_id': 'direct',
                    'ext': urlhandle_detect_ext(urlh, default='mp4'),
                    'filesize': int_or_none(urlh.headers.get('Content-Length')),
                    'url': urlh.url,
                    'quality': 1,
                })

        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}),

Review comment (suggestion):
```suggestion
                    'filesize': int_or_none(urlh.get_header('Content-Length')),
```

Code after:
                'width': ('width', {int_or_none}),
                'height': ('height', {int_or_none}),
                'vcodec': ('videoCodec', {str}),
                'acodec': ('audioCodec', {str}),
                'abr': ('audioBitrate', {int_or_none(scale=1000)}),
                'vbr': ('videoBitrate', {int_or_none(scale=1000)}),
                'audio_channels': ('audioChannels', {int_or_none}),
                'tbr': ('avgBitrate', {int_or_none(scale=1000)}),
                'format': ('qualityType', {str}),
                'filesize': ('size', {int_or_none}),
                'duration': ('duration', {float_or_none(scale=1000)}),
            })

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

        if origin_key := traverse_obj(note_info, ('video', 'consumer', 'originVideoKey', {str})):
            # Not using a head request because of false negatives
            urlh = self._request_webpage(
                f'https://sns-video-bd.xhscdn.com/{origin_key}', display_id,
                'Checking original video availability', 'Original video is not available', fatal=False)
            if urlh:
                formats.append({
                    'format_id': 'direct',
                    'ext': urlhandle_detect_ext(urlh, default='mp4'),
                    'filesize': int_or_none(urlh.get_header('Content-Length')),
                    'url': urlh.url,
                    'quality': 1,
                })

        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}),