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

Code before:
    def _extract_playlist(self, host, type, id):
        info = self.call_api(host, id, '', type, note='Downloading playlist information', fatal=False)

        playlist_title = info.get('displayName')
        playlist_description = info.get('description')
        playlist_timestamp = unified_timestamp(info.get('createdAt'))
        channel = try_get(info, lambda x: x['ownerAccount']['name']) or info.get('displayName')
        channel_id = try_get(info, lambda x: x['ownerAccount']['id']) or info.get('id')
        thumbnail = info.get('thumbnailPath')
        thumbnail = f'https://{host}{thumbnail}' if thumbnail else None

        entries = OnDemandPagedList(functools.partial(
            self.fetch_page, host, id, type), self._PAGE_SIZE)

        return self.playlist_result(
            entries, id, playlist_title, playlist_description,
            timestamp=playlist_timestamp, channel=channel, channel_id=channel_id, thumbnail=thumbnail)

    def _real_extract(self, url):
        type, host, id = self._match_valid_url(url).group('type', 'host', 'id')
        if type == 'a':
            type = 'accounts'
        elif type == 'c':
            type = 'video-channels'
        elif type == 'w/p':
            type = 'video-playlists'
        return self._extract_playlist(host, type, id)


Review comment (suggestion):
you can add this in the class definition
```py
    _TYPES = {
        'a': 'accounts',
        ...
    }
```
and then do
```py
       type = self._TYPES[type]
```

Then u can also use `'|'.join(_TYPES.keys())` in `_VALID_URL`

Code after:
        page += 1
        video_data = self.call_api(
            host, id,
            f'/videos?sort=-createdAt&start={self._PAGE_SIZE * (page - 1)}&count={self._PAGE_SIZE}&nsfw=both',
            type, note=f'Downloading page {page}').get('data', [])
        for video in video_data:
            shortUUID = video.get('shortUUID') or try_get(video, lambda x: x['video']['shortUUID'])
            video_title = video.get('name') or try_get(video, lambda x: x['video']['name'])
            yield self.url_result(
                f'https://{host}/w/{shortUUID}', PeerTubeIE.ie_key(),
                video_id=shortUUID, video_title=video_title)

    def _extract_playlist(self, host, type, id):
        info = self.call_api(host, id, '', type, note='Downloading playlist information', fatal=False)

        playlist_title = info.get('displayName')
        playlist_description = info.get('description')
        playlist_timestamp = unified_timestamp(info.get('createdAt'))
        channel = try_get(info, lambda x: x['ownerAccount']['name']) or info.get('displayName')
        channel_id = try_get(info, lambda x: x['ownerAccount']['id']) or info.get('id')
        thumbnail = info.get('thumbnailPath')
        thumbnail = f'https://{host}{thumbnail}' if thumbnail else None

        entries = OnDemandPagedList(functools.partial(
            self.fetch_page, host, id, type), self._PAGE_SIZE)

        return self.playlist_result(
            entries, id, playlist_title, playlist_description,
            timestamp=playlist_timestamp, channel=channel, channel_id=channel_id, thumbnail=thumbnail)

    def _real_extract(self, url):
        type, host, id = self._match_valid_url(url).group('type', 'host', 'id')
        type = self._TYPES[type]
        return self._extract_playlist(host, type, id)