From d5376704ca183815532d112f58dc80746e0d4086 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Tue, 17 Feb 2026 20:08:06 +0100 Subject: [PATCH] add cbz toolkit --- hosts/darwin/home-default.nix | 1 - hosts/nixos/nfss/system.nix | 1 + modules/media/tool.nix | 28 ++++++++++++++++++++++++++-- modules/syncthing.nix | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/hosts/darwin/home-default.nix b/hosts/darwin/home-default.nix index 0e1904a..bd058a3 100644 --- a/hosts/darwin/home-default.nix +++ b/hosts/darwin/home-default.nix @@ -21,7 +21,6 @@ syncthing-custom.folders = { Credentials.enable = true; Documents.enable = true; - Media.enable = true; Archive.enable = true; }; diff --git a/hosts/nixos/nfss/system.nix b/hosts/nixos/nfss/system.nix index 7ec8369..06c3fc6 100644 --- a/hosts/nixos/nfss/system.nix +++ b/hosts/nixos/nfss/system.nix @@ -146,6 +146,7 @@ services.samba-custom.shares = { Downloads = "/home/yanlin/Downloads"; + Media = "/home/yanlin/Media"; }; # Borg backup configuration diff --git a/modules/media/tool.nix b/modules/media/tool.nix index 9453a10..20ea7dc 100644 --- a/modules/media/tool.nix +++ b/modules/media/tool.nix @@ -9,6 +9,7 @@ shntool cuetools flac + zip unzip p7zip imagemagick @@ -89,6 +90,29 @@ done } + function cbz-compress() { + local dir="''${1:-.}" + dir="$(cd "$dir" && pwd)" + mkdir -p "$dir/compressed" + find "$dir" -path "$dir/compressed" -prune -o -type f \( -iname '*.zip' -o -iname '*.cbz' \) -print | while read -r f; do + echo "Processing: $f" + local tmpdir=$(mktemp -d) + 7z x -o"$tmpdir" -y "$f" > /dev/null + find "$tmpdir" -type f \( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.gif' -o -iname '*.heic' -o -iname '*.heif' \) -print0 | xargs -0 -P4 -n1 sh -c ' + img="$1" + outfile="''${img%.*}.webp" + ${pkgs.imagemagick}/bin/magick "$img" -resize "1500>" -quality 75 "$outfile" + [ "$img" != "$outfile" ] && rm "$img" + ' _ + local relpath="''${f#$dir/}" + local outfile="$dir/compressed/$relpath" + mkdir -p "$(dirname "$outfile")" + (cd "$tmpdir" && zip -r -q "$outfile" .) + rm -rf "$tmpdir" + echo "Done: $outfile" + done + } + function webp2png() { local dir="''${1:-.}" find "$dir" -type f -iname '*.webp' | while read -r img; do @@ -166,7 +190,7 @@ *.gz) gunzip -k "$file" ;; *.bz2) bunzip2 -k "$file" ;; *.xz) unxz -k "$file" ;; - *.zip) unzip -q "$file" -d "$dest" ;; + *.zip|*.cbz) unzip -q "$file" -d "$dest" ;; *.7z) 7z x "$file" -o"$dest" ;; *.rar) 7z x "$file" -o"$dest" ;; *) @@ -206,7 +230,7 @@ case "''${file:l}" in *.tar.gz|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.zst|*.tzst|*.tar) tar -tf "$file" ;; - *.zip) unzip -l "$file" ;; + *.zip|*.cbz) unzip -l "$file" ;; *.7z) 7z l "$file" ;; *.rar) 7z l "$file" ;; *) echo "Unknown archive format: $file" >&2; return 1 ;; diff --git a/modules/syncthing.nix b/modules/syncthing.nix index 2a57b6c..4bbf464 100644 --- a/modules/syncthing.nix +++ b/modules/syncthing.nix @@ -41,7 +41,7 @@ in folders = { Credentials = mkFolderOptions "Credentials" {}; Documents = mkFolderOptions "Documents" { devices = pcDevices ++ serverDevices; }; - Media = mkFolderOptions "Media" { devices = lib.filter (d: d != "iphone") allDevices; }; + Media = mkFolderOptions "Media" { devices = serverDevices ++ [ "ipad" ]; }; Archive = mkFolderOptions "Archive" {}; }; enableGui = lib.mkOption {