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

Code before:
        self._remove_duplicate_formats(formats)
        return formats, subtitles

    def _get_direct_subtitles(self, caption_json):
        subs = {}
        for caption in traverse_obj(caption_json, lambda _, v: url_or_none(v['vttUrl'])):
            subs.setdefault(caption.get('language') or 'und', []).append({
                'url': caption['vttUrl'],
                'name': caption.get('name'),
            })

        return subs

    def _get_chapters(self, video_id):
        sections_json = self._download_json(
            f'https://play.vidyard.com/video/{video_id}', video_id, note='Downloading chapter metadata', fatal=False)

        if sections_json:
            return traverse_obj(sections_json, {
                'chapters': ('videoSections', ..., {
                    'title': ('title', {str}),
                    'start_time': ('milliseconds', {float_or_none(scale=1000)}),
                }),
            })

        return {}

    def _fetch_video_json(self, video_id):
        return self._download_json(
            f'https://play.vidyard.com/player/{video_id}.json', video_id)['payload']

    def _process_video_json(self, json_data, video_id):
        formats, subtitles = self._get_formats_and_subtitles(json_data['sources'], video_id)
        self._merge_subtitles(self._get_direct_subtitles(json_data.get('captions')), target=subtitles)

        return {
            **traverse_obj(json_data, {
                'id': ('facadeUuid', {str}),
                'display_id': ('videoId', {int}, {str_or_none}),
                'title': ('name', {str}),
                'description': ('description', {str}, {unescapeHTML}, filter),
                'duration': ((
                    ('milliseconds', {float_or_none(scale=1000)}),
                    ('seconds', {int_or_none})), any),
                'thumbnails': ('thumbnailUrls', ('small', 'normal'), {'url': {url_or_none}}),
                'tags': ('tags', ..., 'name', {str}),
            }),
            'formats': formats,
            'subtitles': subtitles,
            'http_headers': self._HEADERS,
            **self._get_chapters(json_data['facadeUuid']),

Review comment (suggestion):
If we make that additional request, we might as well use all the metadata
```suggestion
    def _get_additional_metadata(self, video_id):
        additional_metadata = self._download_json(
            f'https://play.vidyard.com/video/{video_id}', video_id,
            note='Downloading additional metadata', fatal=False)
        return traverse_obj(additional_metadata, {
            'title': ('name', {str}),
            'duration': ('seconds', {int_or_none}),
            'thumbnail': ('thumbnailUrl', {url_or_none}),
            'chapters': ('videoSections', ..., {
                'title': ('title', {str}),
                'start_time': ('milliseconds', {float_or_none(scale=1000)}),
            }),
        })
```
also no need to handle the `not sections_json` case with `traverse_obj`.

Code after:
        self._remove_duplicate_formats(formats)
        return formats, subtitles

    def _get_direct_subtitles(self, caption_json):
        subs = {}
        for caption in traverse_obj(caption_json, lambda _, v: url_or_none(v['vttUrl'])):
            subs.setdefault(caption.get('language') or 'und', []).append({
                'url': caption['vttUrl'],
                'name': caption.get('name'),
            })

        return subs

    def _get_additional_metadata(self, video_id):
        additional_metadata = self._download_json(
            f'https://play.vidyard.com/video/{video_id}', video_id,
            note='Downloading additional metadata', fatal=False)
        return traverse_obj(additional_metadata, {
            'title': ('name', {str}),
            'duration': ('seconds', {int_or_none}),
            'thumbnails': ('thumbnailUrl', {'url': {url_or_none}}, all),
            'chapters': ('videoSections', lambda _, v: float_or_none(v['milliseconds']) is not None, {
                'title': ('title', {str}),
                'start_time': ('milliseconds', {float_or_none(scale=1000)}),
            }),
        })

    def _fetch_video_json(self, video_id):
        return self._download_json(
            f'https://play.vidyard.com/player/{video_id}.json', video_id)['payload']

    def _process_video_json(self, json_data, video_id):
        formats, subtitles = self._get_formats_and_subtitles(json_data['sources'], video_id)
        self._merge_subtitles(self._get_direct_subtitles(json_data.get('captions')), target=subtitles)

        return {
            **self._get_additional_metadata(json_data['facadeUuid']),
            **traverse_obj(json_data, {
                'id': ('facadeUuid', {str}),
                'display_id': ('videoId', {int}, {str_or_none}),
                'title': ('name', {str}),
                'description': ('description', {str}, {unescapeHTML}, filter),
                'duration': ((
                    ('milliseconds', {float_or_none(scale=1000)}),
                    ('seconds', {int_or_none})), any),
                'thumbnails': ('thumbnailUrls', ('small', 'normal'), {'url': {url_or_none}}),
                'tags': ('tags', ..., 'name', {str}),
            }),
            'formats': formats,
            'subtitles': subtitles,
            'http_headers': self._HEADERS,