예제 #1
0
    # Backup /etc
    io.mkdir(BACKUP_ETC_PATH)
    io.cp_file("/etc/exports", BACKUP_ETC_PATH)
    io.cp_file("/etc/fstab", BACKUP_ETC_PATH)
    io.cp_file("/etc/mpd.conf", BACKUP_ETC_PATH)
    io.cp_dir("/etc/ssh", f"{BACKUP_ETC_PATH}/ssh")
    io.cp_dir("/etc/sysctl.d", f"{BACKUP_ETC_PATH}/sysctl.d")
    io.cp_dir("/etc/systemd", f"{BACKUP_ETC_PATH}/systemd")
    io.cp_dir("/etc/X11", f"{BACKUP_ETC_PATH}/X11")

    # Backup /var
    io.mkdir(f"{BACKUP_VAR_PATH}/mpd")
    io.cp_file("/var/lib/mpd/database", f"{BACKUP_VAR_PATH}/mpd")
    io.cp_dir("/var/lib/mpd/playlists", f"{BACKUP_VAR_PATH}/mpd/playlists")

    # Backup crontab
    CRON_ROOT = common.system_call("crontab -l")
    with open(f"{BACKUP_PATH}/crontab_root.txt", 'wb') as f:
        f.write(CRON_ROOT)
    CRON_ME = common.system_call("crontab -l -u nyxouf")
    with open(f"{BACKUP_PATH}/crontab_nyxouf.txt", 'wb') as f:
        f.write(CRON_ME)

    # Compress & copy
    io.chown(BACKUP_PATH, "nyxouf", "nyxouf")
    io.tar_xz(BACKUP_DIR, BACKUP_NAME)
    io.mv(BACKUP_NAME, f"/media/nyxouf/internal/{BACKUP_NAME}")
    io.chown(f"/media/nyxouf/internal/{BACKUP_NAME}", "nyxouf", "nyxouf")
    io.chmod(f"/media/nyxouf/internal/{BACKUP_NAME}", 777)
    io.rm(BACKUP_DIR)
예제 #2
0
def get_file_infos(filepath: Path) -> str:
    """ffmpeg -i `filepath`"""
    data = common.system_call(f"ffmpeg -hide_banner -i {quote(str(filepath))}", True).decode("utf-8")
    return data
예제 #3
0
 def get_file_infos(path: Path):
     """Invoke mkvmerge to get infos"""
     a = common.system_call(f'mkvmerge -J {quote(str(path))}')
     return json.loads(a)
예제 #4
0
 def video_codec_desc(self) -> str:
     """return smth like AVC [email protected] 24fps"""
     return common.system_call(
         f'mediainfo --Inform="Video;%Format% %Format_Profile% %FrameRate%fps" {quote(str(self.path))}'
     ).decode("utf-8").strip()
예제 #5
0
def is_420_subsampled(path: Path) -> bool:
    """Check if the jpeg file at `path` is 420"""
    ch = common.system_call(
        f"identify -format %[jpeg:sampling-factor] {quote(str(path))}").decode(
            "utf-8").strip()
    return '2x2,1x1,1x1' in ch
from utils import common

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("input", type=Path, help="Path to movie file")
    parser.add_argument("-n",
                        "--number-of-screenshots",
                        dest="number_of_screenshots",
                        type=int,
                        default=10,
                        help="Number of screenshots to take")
    args = parser.parse_args()

    # Sanity checks
    common.ensure_exist(["ffprobe", "mpv"])
    if args.input.exists() is False or args.input.is_file() is False:
        common.abort(parser.format_help())

    duration = float(
        common.system_call(
            f'ffprobe -i {quote(str(args.input))} -show_entries format=duration -v quiet -of csv="p=0"'
        ).decode("utf-8").split('.')[0])

    step = int(duration / args.number_of_screenshots + 1)
    current = step
    for i in range(args.number_of_screenshots):
        scname = f'{args.input.stem}-{i:0>2}-{current}.png'
        cmd = f'mpv {quote(str(args.input))} --no-config --quiet --no-terminal --aid=no --sid=no --frames=1 --start={current} --o={quote(scname)}'
        os.system(cmd)
        current += step
예제 #7
0
def get_tags(flac_file: str) -> List[str]:
    """return list of tags for `flac_file`"""
    metaflac = f"metaflac --export-tags-to=- {quote(flac_file)}"
    data = common.system_call(metaflac).decode('utf-8')
    lines = data.split("\n")
    return list(filter(lambda x: "=" in x, lines))