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

Code before:
    _HOST = 'zattoo.com'


def _make_valid_url(tmpl, host):
    return tmpl % re.escape(host)


class ZattooIE(ZattooBaseIE):
    _VALID_URL_TEMPLATE = r'''(?x)
                            https?://(?:www\.)?%s/
                            (?:
                                (?:
                                    vod/movies/([A-Za-z0-9]+)|
                                    (?:program|watch)/([^/]+)/(\d+)|
                                    live/([^/]+)
                                )|
                                (?:
                                    .+\?recording=([0-9]+)|
                                    .+\?movie_id=([A-Za-z0-9]+)|
                                    .+\?channel=([^&]+)(?:
                                        &program=(\d+)
                                    )?
                                )
                            )'''

    _VALID_URL = _make_valid_url(_VALID_URL_TEMPLATE, ZattooBaseIE._HOST)
    _TESTS = [{
        'url': 'https://zattoo.com/channels/german?channel=srf_zwei',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/guide/german?channel=srf1&program=169860555',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/recordings?recording=193615508',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/tc/ptc_recordings_all_recordings?recording=193615420',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/vod/movies/7521',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/program/daserste/210177916',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/ondemand?movie_id=7521&term_token=9f00f43183269484edde',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/live/srf1',
        'only_matching': True,
    }]

Review comment (refactor):
```suggestion
    _VALID_URL = r'''(?x)
        https?://(?:www\.)?zattoo.com/(?:
            (?:
                vod/movies/([A-Za-z0-9]+)|
                (?:program|watch)/([^/]+)/(\d+)|
                live/([^/]+)
            )|
            [^?#]+\?(?:
                recording=([0-9]+)|
                movie_id=([A-Za-z0-9]+)|
                channel=([^&]+)(?:&program=(\d+))?
            )
        )'''
```
Also:
1. Use named groups
2. Simplify regex to only include what is needed to perform a match. Rest of the data can be obtained using `parse_qs`

Code after:
    }]


class ZattooLiveIE(ZattooBaseIE):
    _VALID_URL = ZattooBaseIE._create_valid_url(r'[^/?&#]+', 'channel', 'live')
    _TYPE = 'live'
    _TESTS = [{
        'url': 'https://zattoo.com/channels/german?channel=srf_zwei',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/live/srf1',
        'only_matching': True,
    }]

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


class ZattooMoviesIE(ZattooBaseIE):
    _VALID_URL = ZattooBaseIE._create_valid_url(r'\w+', 'movie_id', 'vod/movies')
    _TYPE = 'ondemand'
    _TESTS = [{
        'url': 'https://zattoo.com/vod/movies/7521',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/ondemand?movie_id=7521&term_token=9f00f43183269484edde',
        'only_matching': True,
    }]


class ZattooRecordingsIE(ZattooBaseIE):
    _VALID_URL = ZattooBaseIE._create_valid_url(r'\d+', 'recording')
    _TYPE = 'record'
    _TESTS = [{
        'url': 'https://zattoo.com/recordings?recording=193615508',
        'only_matching': True,
    }, {
        'url': 'https://zattoo.com/tc/ptc_recordings_all_recordings?recording=193615420',
        'only_matching': True,
    }]


class NetPlusIE(ZattooPlatformBaseIE):
    _NETRC_MACHINE = 'netplus'
    _HOST = 'netplus.tv'
    _API_HOST = 'www.%s' % _HOST
    _VALID_URL = _make_valid_url(_HOST)

    _TESTS = [{
        'url': 'https://www.netplus.tv/watch/abc/123-abc',