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

Code before:
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                f'https://cdn.piramide.tv/video/{video_id}/manifest.m3u8', video_id, fatal=fatal)
            video_info = {**traverse_obj(video_data, {
                'id': ('video', 'id', {str}),
                'title': ('video', 'title', {str}),
                'description': ('video', 'description', {str}),
                'thumbnail': ('video', 'media', 'thumbnail', {url_or_none}),
                'channel': ('video', 'channel', 'name', {str}),
                'channel_id': ('video', 'channel', 'id', {str}),
                'timestamp': ('video', 'date', {unified_timestamp}),
            }),
                'formats': formats,
                'subtitles': subtitles,
                'webpage_url': f'https://piramide.tv/video/{video_id}',
                'webpage_url_basename': video_id,
            }
            next_video_id = traverse_obj(video_data, ('video', 'next_video', 'id', {str}))
            return video_info, next_video_id

        video_id = self._match_id(url)
        entries = []
        while video_id is not None:
            video, next_video = extract_video(video_id, (not entries))
            if video.get('formats'):
                entries.append(video)
            video_id = next_video if next_video != video_id else None

        if len(entries) == 1:
            return entries[0]
        elif len(entries) > 1:
            return self.playlist_result(entries, **traverse_obj(entries[0], {
                'id': ('id'),
                'title': ('title'),
                'description': ('description'),
                'channel': ('channel'),
                'channel_id': ('channel_id'),
            }))
        else:
            return {'id': video_id}


class PiramideTVChannelURLIE(InfoExtractor):
    _VALID_URL = r'https?://piramide\.tv/channel/(?P<id>[\w-]+)'
    _TESTS = [{
        'url': 'https://piramide.tv/channel/thekalo',
        'playlist_count': 10,
        'info_dict': {
            'id': 'thekalo',
            'title': 'thekalo',
        },
    }]

Review comment (refactor):
I'm not a huge fan of this logic. This doesn't work with lazy extraction or `--no-playlist`.
Since I can't think of a better way to do this, I would just keep it simple for now and only extract a single video.
If someone comes up with a better way to extract a new PR can be opened.

Code after:
            f'https://cdn.piramide.tv/video/{video_id}/manifest.m3u8', video_id, fatal=False)
        next_video = traverse_obj(video_data, ('video', 'next_video', 'id', {str}))
        return next_video, {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(video_data, ('video', {
                'id': ('id', {str}),
                'title': ('title', {str}),
                'description': ('description', {str}),
                'thumbnail': ('media', 'thumbnail', {url_or_none}),
                'channel': ('channel', 'name', {str}),
                'channel_id': ('channel', 'id', {str}),
                'timestamp': ('date', {parse_iso8601}),
            })),
        }

    def _entries(self, video_id):
        visited = set()
        while True:
            visited.add(video_id)
            next_video, info = self._extract_video(video_id)
            yield info
            if not next_video or next_video in visited:
                break
            video_id = next_video

    def _real_extract(self, url):
        url, smuggled_data = unsmuggle_url(url, {})
        video_id = self._match_id(url)
        if self._yes_playlist(video_id, video_id, smuggled_data):
            return self.playlist_result(self._entries(video_id), video_id)
        return self._extract_video(video_id)[1]


class PiramideTVChannelIE(InfoExtractor):
    _VALID_URL = r'https?://piramide\.tv/channel/(?P<id>[\w-]+)'
    _TESTS = [{
        'url': 'https://piramide.tv/channel/thekalo',
        'playlist_mincount': 10,
        'info_dict': {
            'id': 'thekalo',
        },
    }]

    def _entries(self, channel_name):
        videos = self._download_json(
            f'https://hermes.piramide.tv/channel/list/{channel_name}/date/100000', channel_name)
        for video in traverse_obj(videos, ('videos', lambda _, v: v['id'])):
            yield self.url_result(smuggle_url(
                f'https://piramide.tv/video/{video["id"]}', {'force_noplaylist': True}),