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

Code before:
        actual_video_id = traverse_obj(nuxt_data, ('item', 'video'))

        if not actual_video_id:
            raise ExtractorError('Unable to extract actual video ID')

        video_data = self._download_json(
            f'http://playvideo.qcloud.com/getplayinfo/v2/1253584441/{actual_video_id}',
            actual_video_id,
            headers={'Referer': 'http://www.amadeus.tv/'}
        )

        transcode_list = traverse_obj(video_data, ('videoInfo', 'transcodeList'), default=[])
        formats = []
        for video in transcode_list:
            format_info = {
                'url': video['url'],
                'format_id': 'http-%d' % video['definition'],
                'width': int_or_none(video.get('width')),
                'height': int_or_none(video.get('height')),
                'filesize': int_or_none(video.get('size')),
                'vcodec': video.get('videoStreamList', [{}])[0].get('codec'),
                'acodec': video.get('audioStreamList', [{}])[0].get('codec'),
                'fps': int_or_none(video.get('videoStreamList', [{}])[0].get('fps')),
                'http_headers': {'Referer': 'http://www.amadeus.tv/'}
            }
            formats.append(format_info)

        return {
            'id': actual_video_id,
            'title': traverse_obj(video_data, ('videoInfo', 'basicInfo', 'name'), default=video_id),
            'thumbnail': traverse_obj(video_data, ('coverInfo', 'coverUrl')),
            'formats': formats,
            'duration': int_or_none(traverse_obj(video_data, ('videoInfo', 'sourceVideo', 'duration'))),
        }


Review comment (refactor):
I would write this like so to also extract the source video:
```suggestion
        formats = []
        for video in traverse_obj(video_data, ('videoInfo', ('sourceVideo', ('transcodeList', ...)), {dict})):
            if not url_or_none(video.get('url')):
                continue
            formats.append({
                **traverse_obj(video, {
                    'url': 'url',
                    'format_id': ('definition', {lambda x: f'http-{x or "0"}'}),
                    'width': ('width', {int_or_none}),
                    'height': ('height', {int_or_none}),
                    'filesize': (('totalSize', 'size'), {int_or_none}),
                    'vcodec': ('videoStreamList', 0, 'codec'),
                    'acodec': ('audioStreamList', 0, 'codec'),
                    'fps': ('videoStreamList', 0, 'fps', {float_or_none}),
                }, get_all=False),
                'http_headers': {'Referer': 'http://www.amadeus.tv/'},
            })
```

Code after:
        }
    }]

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)

        nuxt_data = self._search_nuxt_data(webpage, display_id, traverse=('fetch', '0'))
        video_id = traverse_obj(nuxt_data, ('item', 'video', {str}))

        if not video_id:
            raise ExtractorError('Unable to extract actual video ID')

        video_data = self._download_json(
            f'http://playvideo.qcloud.com/getplayinfo/v2/1253584441/{video_id}',
            video_id, headers={'Referer': 'http://www.amadeus.tv/'})

        formats = []
        for video in traverse_obj(video_data, ('videoInfo', ('sourceVideo', ('transcodeList', ...)), {dict})):
            if not url_or_none(video.get('url')):
                continue
            formats.append({
                **traverse_obj(video, {
                    'url': 'url',
                    'format_id': ('definition', {lambda x: f'http-{x or "0"}'}),
                    'width': ('width', {int_or_none}),
                    'height': ('height', {int_or_none}),
                    'filesize': (('totalSize', 'size'), {int_or_none}),
                    'vcodec': ('videoStreamList', 0, 'codec'),
                    'acodec': ('audioStreamList', 0, 'codec'),
                    'fps': ('videoStreamList', 0, 'fps', {float_or_none}),
                }, get_all=False),
                'http_headers': {'Referer': 'http://www.amadeus.tv/'},
            })

        return {
            'id': video_id,
            'display_id': display_id,
            'formats': formats,
            **traverse_obj(video_data, {
                'title': ('videoInfo', 'basicInfo', 'name', {str}),
                'thumbnail': ('coverInfo', 'coverUrl', {url_or_none}),
                'duration': ('videoInfo', 'sourceVideo', ('floatDuration', 'duration'), {float_or_none}),
            }, get_all=False),
            **traverse_obj(nuxt_data, ('item', {
                'title': (('title', 'title_en', 'title_cn'), {str}),
                'description': (('description', 'description_en', 'description_cn'), {str}),
                'timestamp': ('date', {parse_iso8601}),
                'view_count': ('view', {int_or_none}),
            }), get_all=False),
        }