def get_general(self) -> General:
        general = General()
        self.parser.to_object(
            general,
            "General",
            "series_dir",
            "int:threads",
            "float:speed_up_default",
            "int:max_days_back",
            "log_level",
        )
        if not general.series_dir:
            TealPrint.warning(f"Missing 'series_dir' in [General] in your configuration. Please add it.", exit=True)

        # Convert string to LogLevel
        if isinstance(general.log_level, str):
            try:
                general.log_level = TealLevel[general.log_level]
            except KeyError:
                TealPrint.warning(
                    f"Failed to set log_level from config, invalid level: {general.log_level}. Setting log_level to info"
                )
                general.log_level = TealLevel.info

        return general
    def execute(self, channels: List[Channel]) -> None:
        for channel in channels:
            TealPrint.info(channel.name,
                           color=LogColors.header,
                           push_indent=True)

            videos = self.repo.get_latest_videos(channel)

            if len(videos) == 0:
                TealPrint.info(
                    f"🦘 Skipping {channel.name}, no new matching videos to download",
                    color=LogColors.skipped)

            for video in videos:
                TealPrint.verbose(f"🎞 {video.title}",
                                  color=LogColors.header,
                                  push_indent=True)

                # Skip downloaded videos
                if self.repo.has_downloaded(video):
                    TealPrint.verbose(
                        f"🟠 Skipping {video.title}, already downloaded",
                        color=LogColors.skipped)
                    TealPrint.pop_indent()
                    continue

                # Filter out
                if self._filter_video(channel, video):
                    TealPrint.verbose(f"🔴 Video was filtered out",
                                      color=LogColors.filtered)
                    TealPrint.pop_indent()
                    continue
                TealPrint.verbose(f"🟢 Video passed all filters",
                                  color=LogColors.passed)

                TealPrint.verbose(f"🔽 Downloading...")
                download_path = self.repo.download(video)

                if download_path is None:
                    TealPrint.warning(f"âš  Couldn't download {video.title}")
                    TealPrint.pop_indent()
                    continue

                TealPrint.verbose(
                    f"🎞 Starting rendering, this may take a while...")
                out_path = self._get_out_filepath(channel, video)
                rendered = self.repo.render(video, download_path, out_path,
                                            channel.speed)

                if not rendered:
                    TealPrint.warning(f"âš  Couldn't render {video.title}")
                    TealPrint.pop_indent()
                    continue

                self.repo.set_as_downloaded(channel, video)
                TealPrint.info(
                    f"✔ Video {video.title} downloaded successfully ➡ {out_path}"
                )
                TealPrint.pop_indent()
            TealPrint.pop_indent()
    def get_channels(self) -> List[Channel]:
        channels: List[Channel] = []
        for section in self.parser.sections():
            if ConfigGateway.is_channel_section(section):
                channel = Channel()
                channel.name = section
                self.parser.to_object(
                    channel,
                    section,
                    "id",
                    "name",
                    "dir->collection_dir",
                    "float:speed",
                    "str_list:includes",
                    "str_list:excludes",
                )

                if not channel.id:
                    TealPrint.warning(
                        f"Missing 'id' for channel [{section}] in your configuration. Please add it.", exit=True
                    )

                channels.append(channel)
        return channels
Example #4
0
 def _print_missing(self, section: str, varname: str) -> None:
     TealPrint.warning(
         f"Missing {varname} under section {section}. " + f"Please add it to your configuration file {self.path}",
         exit=True,
     )
Example #5
0
 def _print_section_not_found(section: str) -> None:
     TealPrint.warning(f"⚠ [{section}] section not found!", indent=1)
Example #6
0
    def get_args(self) -> ConfigFileArgs:
        args = ConfigFileArgs()

        if not self.path.exists():
            TealPrint.warning(f"Could not find config file {self.path}. Please add!", exit=True)
            return args

        config = ConfigParser()
        config.read(self.path)

        TealPrint.verbose(f"Reading configuration {self.path}", color=attr("bold"))

        try:
            config.to_object(
                args.general,
                "General",
                "backup_location",
                "int:days_to_keep",
            )
        except SectionNotFoundError:
            ConfigFileParser._print_section_not_found("General")

        try:
            config.to_object(
                args.backups,
                "Backups",
                "daily_alias",
                "weekly_alias",
                "monthly_alias",
                "str_list:daily",
                "str_list:weekly",
                "str_list:monthly",
            )
        except SectionNotFoundError:
            ConfigFileParser._print_section_not_found("Backups")

        try:
            config.to_object(
                args.mysql,
                "MySQL",
                "username",
                "password",
                "address",
                "int:port",
                "str_list:databases",
            )
        except SectionNotFoundError:
            ConfigFileParser._print_section_not_found("MySQL")

        try:
            config.to_object(
                args.email,
                "Email",
                "to->to_address",
                "from->from_address",
                "int:disk_percentage",
            )
        except SectionNotFoundError:
            ConfigFileParser._print_section_not_found("Email")

        self._check_required(args)

        return args