from yt_dlp import YoutubeDL


class ChannelManager:

    def __init__(self, channel_url):
        self._channel_url = channel_url
        self._ydl_opts = {
            "extract_flat": True,   # --flat-playlist
            "skip_download": True,
            "quiet": True,
        }

    def get_video_infos(self):
        return list(self._video_iter())

    def _video_iter(self):
        with YoutubeDL(self._ydl_opts) as ydl:
            info = ydl.extract_info(self._channel_url, download=False)

            for e in info["entries"]:
                yield {
                    "id": e.get("id"),
                    "title": e.get("title"),
                    "url": e.get("url"),
                    "duration": e.get("duration"),
                    "upload_date": e.get("upload_date"),
                    "channel": e.get("channel"),
                }
