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

Code before:
        data = self._call_api(asset_id, client)
        formats, subtitles = self._extract_formats_and_subtitles(data, asset_id)

        description = self._html_search_meta(
            ['og:description', 'twitter:description', 'description'], webpage)
        if description == '…':
            description = None

        return {
            'id': asset_id,
            'formats': formats,
            'subtitles': subtitles,
            'description': description,
            'thumbnail': url_or_none(attrs.get('data-posterimage')),
            'duration': float_or_none(attrs.get('data-duration'), 1000),
            '_old_archive_ids': [make_archive_id('Canvas', asset_id)],
            **traverse_obj(data, {
                'title': ('title', {str}),
                'description': ('shortDescription', {str}),
                'duration': ('duration', {float_or_none(scale=1000)}),
                'thumbnail': ('posterImageUrl', {url_or_none}),
            }),
        }


def jwt_is_expired(token):
    return jwt_decode_hs256(token)['exp'] - time.time() < 300


class VrtNUIE(VRTBaseIE):
    IE_DESC = 'VRT MAX'
    _VALID_URL = r'https?://(?:www\.)?vrt\.be/(?:vrtnu|vrtmax)/a-z/(?:[^/]+/){2}(?P<id>[^/?#&]+)'
    _TESTS = [{
        'url': 'https://www.vrt.be/vrtmax/a-z/ket---doc/trailer/ket---doc-trailer-s6/',
        'info_dict': {
            'channel': 'VRT',
            'description': 'Neem een kijkje in de bijzondere wereld van deze Ketnetters.',
            'display_id': 'ket---doc-trailer-s6',
            'duration': 30.0,
            'episode': 'Reeks 6 volledig vanaf 3 maart',
            'episode_id': '1739450401467',
            'ext': 'mp4',
            'id': 'pbs-pub-c8a78645-5d3e-468a-89ec-6f3ed5534bd5$vid-242ddfe9-18f5-4e16-ab45-09b122a19251',
            'season': 'Trailer',
            'season_id': '1739450401467',
            'series': 'Ket & Doc',
            'thumbnail': 'https://images.vrt.be/orig/2025/02/21/63f07122-5bbd-4ca1-b42e-8565c6cd95df.jpg',
            'timestamp': 1740373200,
            'title': 'Reeks 6 volledig vanaf 3 maart',
            'upload_date': '20250224',
            '_old_archive_ids': ['canvas pbs-pub-c8a78645-5d3e-468a-89ec-6f3ed5534bd5$vid-242ddfe9-18f5-4e16-ab45-09b122a19251'],

Review comment (refactor):
Arguably this should be moved in to the `InfoExtractor` base class. Please do not move it out of `VrtNUIE`.

Code after:
            'formats': formats,
            'subtitles': subtitles,
            'description': description,
            'thumbnail': url_or_none(attrs.get('data-posterimage')),
            'duration': float_or_none(attrs.get('data-duration'), 1000),
            '_old_archive_ids': [make_archive_id('Canvas', asset_id)],
            **traverse_obj(data, {
                'title': ('title', {str}),
                'description': ('shortDescription', {str}),
                'duration': ('duration', {float_or_none(scale=1000)}),
                'thumbnail': ('posterImageUrl', {url_or_none}),
            }),
        }


class VrtNUIE(VRTBaseIE):
    IE_NAME = 'vrtmax'
    IE_DESC = 'VRT MAX (formerly VRT NU)'
    _VALID_URL = r'https?://(?:www\.)?vrt\.be/(?:vrtnu|vrtmax)/a-z/(?:[^/]+/){2}(?P<id>[^/?#&]+)'
    _TESTS = [{
        'url': 'https://www.vrt.be/vrtmax/a-z/ket---doc/trailer/ket---doc-trailer-s6/',
        'info_dict': {
            'id': 'pbs-pub-c8a78645-5d3e-468a-89ec-6f3ed5534bd5$vid-242ddfe9-18f5-4e16-ab45-09b122a19251',
            'ext': 'mp4',
            'channel': 'ketnet',
            'description': 'Neem een kijkje in de bijzondere wereld van deze Ketnetters.',
            'display_id': 'ket---doc-trailer-s6',
            'duration': 30.0,
            'episode': 'Reeks 6 volledig vanaf 3 maart',
            'episode_id': '1739450401467',
            'season': 'Trailer',
            'season_id': '1739450401467',
            'series': 'Ket & Doc',
            'thumbnail': 'https://images.vrt.be/orig/2025/02/21/63f07122-5bbd-4ca1-b42e-8565c6cd95df.jpg',
            'timestamp': 1740373200,
            'title': 'Reeks 6 volledig vanaf 3 maart',
            'upload_date': '20250224',
            '_old_archive_ids': ['canvas pbs-pub-c8a78645-5d3e-468a-89ec-6f3ed5534bd5$vid-242ddfe9-18f5-4e16-ab45-09b122a19251'],
        },
    }, {
        'url': 'https://www.vrt.be/vrtnu/a-z/taboe/3/taboe-s3a4/',
        'info_dict': {
            'id': 'pbs-pub-f50faa3a-1778-46b6-9117-4ba85f197703$vid-547507fe-1c8b-4394-b361-21e627cbd0fd',
            'ext': 'mp4',
            'channel': 'een',
            'description': 'md5:bf61345a95eca9393a95de4a7a54b5c6',
            'display_id': 'taboe-s3a4',
            'duration': 2882.02,
            'episode': 'Mensen met het syndroom van Gilles de la Tourette',
            'episode_id': '1739055911734',
            'episode_number': 4,