def _matches_any_exclude(self, channel: Channel, video: Video) -> bool:
        title = video.title.lower()
        TealPrint.verbose(f"🚦 Check exclude filter", push_indent=True)

        if len(channel.excludes) == 0:
            TealPrint.verbose(f"🟢 Pass: no exclude filter",
                              color=LogColors.passed)
            TealPrint.pop_indent()
            return False

        for filter in channel.excludes:
            filter = filter.lower()
            if re.search(filter, title):
                TealPrint.verbose(f"🔴 Matched filter: {filter}",
                                  color=LogColors.filtered)
                TealPrint.pop_indent()
                return True
            else:
                TealPrint.verbose(f"🟡 Didn't match filter: {filter}",
                                  color=LogColors.no_match)

        TealPrint.verbose(f"🟢 Didn't match any exclude filter",
                          color=LogColors.passed)
        TealPrint.pop_indent()
        return False
def main():
    check_for_programs()
    config.set_cli_args(get_args())
    config_gateway.check_config_exists()
    init_logs()

    if config.daemon:
        TealPrint.verbose(f"Starting {config.app_name} as a daemon")
        _daemon()
    else:
        TealPrint.verbose(f"Running {config.app_name} once")
        _run_once()
Example #3
0
    def run(self) -> None:
        """Add files to tar"""
        TealPrint.info(f"Backing up {self.name}", color=attr("bold"))

        # Full backup
        if self.part == BackupParts.full:
            TealPrint.info(f"Doing a full backup", indent=1)
            for path_glob in self.paths:
                TealPrint.verbose(f"{path_glob}", indent=2)
                for path in glob(path_glob):
                    TealPrint.debug(f"{path}", indent=3)
                    self.tar.add(path)

        # Diff backup
        else:
            TealPrint.info("Doing a diff backup", indent=1)
            for path_glob in self.paths:
                TealPrint.verbose(f"{path_glob}", indent=2)
                for path in glob(path_glob):
                    self._find_diff_files(Path(path), 3)
    def _is_old(self, video: Video) -> bool:
        TealPrint.verbose(f"🚦 Is the video old?", push_indent=True)

        old_date = datetime.now().astimezone() - timedelta(
            days=config.general.max_days_back)
        video_date = datetime.strptime(video.date, "%Y-%m-%dT%H:%M:%S%z")

        if video_date >= old_date:
            TealPrint.verbose(f"🟢 Video is new", color=LogColors.passed)
            TealPrint.pop_indent()
            return False
        else:
            TealPrint.verbose(f"🔴 Video is old", color=LogColors.filtered)
            TealPrint.pop_indent()
            return True
    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()
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