Exemplo n.º 1
0
    def __init__(self):
        TealPrint.debug(f"Sqlite DB location: {SqliteGateway.__FILE_PATH}")
        self.__connection = sqlite3.connect(SqliteGateway.__FILE_PATH)
        self.__cursor = self.__connection.cursor()

        # Create DB (if not exists)
        self._create_db()
Exemplo n.º 2
0
 def _find_diff_files(self, path: Path, indent: int):
     # File/Dir has changed
     try:
         TealPrint.debug(f"{path}", indent=indent)
         if path.is_symlink() or (not path.is_dir()
                                  and self.is_modified_within_diff(path)):
             self.tar.add(path)
         # Check children
         else:
             if not path.is_symlink():
                 for child in path.glob("*"):
                     self._find_diff_files(child, indent + 1)
                 for child in path.glob(".*"):
                     self._find_diff_files(child, indent + 1)
     except FileNotFoundError:
         # Skip if we didn't find a file
         pass
Exemplo n.º 3
0
    def add_downloaded(self, channel_name: str, video_id: str):
        """Adds a downloaded episode to the DB

        Args:
            channel_name (str): Channel name (not channel_id)
            video_id (str): YouTube's video id for the video that was downloaded
        """
        episode_number = self.get_next_episode_number(channel_name)

        TealPrint.debug(
            f"💾 Save to DB {video_id} from {channel_name} with episode number {episode_number}.",
            color=LogColors.added,
        )

        if not config.pretend:
            sql = "INSERT INTO video (id, episode_number, channel_name) VALUES(?, ?, ?)"
            self.__cursor.execute(sql,
                                  (video_id, episode_number, channel_name))
            self.__connection.commit()
Exemplo n.º 4
0
    def render(video: Video, in_file: Path, out_file: Path,
               speed: float) -> bool:
        completed_process = True
        tmp_out = Path(gettempdir(), f"{video.id}_render_out.mp4")

        if not config.pretend:
            # Create parent directories
            out_file.parent.mkdir(parents=True, exist_ok=True)

            audio_speed = speed
            video_speed = 1.0 / audio_speed

            completed_process = (subprocess.run(
                [
                    "ffmpeg",
                    "-y",
                    "-i",
                    in_file,
                    "-metadata",
                    f'title="{video.title}"',
                    "-threads",
                    str(config.general.threads),
                    "-filter_complex",
                    f"[0:v]setpts=({video_speed})*PTS[v];[0:a]atempo={audio_speed}[a]",
                    "-map",
                    "[v]",
                    "-map",
                    "[a]",
                    tmp_out,
                ],
                stdout=FfmpegGateway._get_verbose_out(),
            ).returncode == 0)

        if completed_process:
            # Copy the temprory file to series/Minecraft
            if not config.pretend:
                copyfile(tmp_out, out_file)

        TealPrint.debug("🗑 Deleting temporary files")
        in_file.unlink(missing_ok=True)
        tmp_out.unlink(missing_ok=True)

        return completed_process
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def close(self):
     TealPrint.debug("Closing Sqlite DB connection")
     self.__connection.commit()
     self.__connection.close()