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

Code before:
    def _extract_ondemand(self, ondemand_id):
        ondemand_termtoken, ondemand_type, info_dict = self._extract_ondemand_info(ondemand_id)
        formats = self._extract_formats(
            None, ondemand_id, ondemand_id=ondemand_id,
            ondemand_termtoken=ondemand_termtoken,
            ondemand_type=ondemand_type)
        info_dict['formats'] = formats
        return info_dict


class QuicklineBaseIE(ZattooPlatformBaseIE):
    _NETRC_MACHINE = 'quickline'
    _HOST = 'mobiltv.quickline.com'


class QuicklineIE(QuicklineBaseIE):
    _VALID_URL = r'https?://(?:www\.)?%s/watch/[^/]+/(?P<id>[0-9]+)' % re.escape(QuicklineBaseIE._HOST)

    _TEST = {
        'url': 'https://mobiltv.quickline.com/watch/prosieben/130671867-maze-runner-die-auserwaehlten-in-der-brandwueste',
        'only_matching': True,
    }

    def _real_extract(self, url):
        video_id = self._match_valid_url(url).groups()
        return self._extract_video(video_id)


class QuicklineLiveIE(QuicklineBaseIE):
    _VALID_URL = r'https?://(?:www\.)?%s/watch/(?P<id>[^/]+)' % re.escape(QuicklineBaseIE._HOST)

    _TEST = {
        'url': 'https://mobiltv.quickline.com/watch/srf1',
        'only_matching': True,
    }

    @classmethod
    def suitable(cls, url):
        return False if QuicklineIE.suitable(url) else super(QuicklineLiveIE, cls).suitable(url)

    def _real_extract(self, url):
        channel_name = self._match_id(url)
        return self._extract_live(channel_name)


class ZattooBaseIE(ZattooPlatformBaseIE):
    _NETRC_MACHINE = 'zattoo'
    _HOST = 'zattoo.com'


def _make_valid_url(tmpl, host):

Review comment (refactor):
```suggestion
        return self._extract_video(self._match_id(url))
```

Code after:


def _make_valid_url(host):
    return rf'https?://(?:www\.)?{re.escape(host)}/watch/[^/]+?/(?P<id>[0-9]+)[^/]+(?:/(?P<recid>[0-9]+))?'


class ZattooBaseIE(ZattooPlatformBaseIE):
    _NETRC_MACHINE = 'zattoo'
    _HOST = 'zattoo.com'

    @staticmethod
    def _create_valid_url(match, qs, base_re=None):
        match_base = fr'|{base_re}/(?P<vid1>{match})' if base_re else '(?P<vid1>)'
        return rf'''(?x)https?://(?:www\.)?zattoo\.com/(?:
            [^?#]+\?(?:[^#]+&)?{qs}=(?P<vid2>{match})
            {match_base}
        )'''

    def _real_extract(self, url):
        vid1, vid2 = self._match_valid_url(url).group('vid1', 'vid2')
        return getattr(self, f'_extract_{self._TYPE}')(vid1 or vid2)


class ZattooIE(ZattooBaseIE):
    _VALID_URL = ZattooBaseIE._create_valid_url(r'\d+', 'program', '(?:program|watch)/[^/]+')
    _TYPE = 'video'
    _TESTS = [{
        'url': 'https://zattoo.com/program/zdf/250170418',
        'info_dict': {
            'id': '250170418',
            'ext': 'mp4',
            'title': 'Markus Lanz',
            'description': 'md5:e41cb1257de008ca62a73bb876ffa7fc',
            'thumbnail': 're:http://images.zattic.com/cms/.+/format_480x360.jpg',
            'creator': 'ZDF HD',
            'release_year': 2022,
            'episode': 'Folge 1655',
            'categories': 'count:1',
            'tags': 'count:2'
        },
        'params': {'skip_download': 'm3u8'}
    }, {
        'url': 'https://zattoo.com/program/daserste/210177916',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/guide/german?channel=srf1&program=169860555',
        'only_matching': True,
    }]


class ZattooLiveIE(ZattooBaseIE):