#!/usr/bin/env bash # shellcheck disable=SC2086 # License: AGPL3+ cd "${0%/*}" set -eu shopt -s nullglob ffmpeg_ () { local -; set -x; nice -19 ffmpeg &2 "$@"; } user=$(realpath --relative-to .. .) declare -a years=${years:-$(find * -maxdepth 0 -type d -not -name ".*")} for year in ${years[@]}; do pushd "$year" >/dev/null test -d src || { popd; continue; } mkdir -p fav ln -sf -t fav ../../index.css declare -a months=${months:-(01 02 03 04 05 06 07 08 09 10 11 12)} for month in ${months[@]}; do test -d src/"$month" || { popd; continue; } mkdir -p fav/"$month" mkdir -p {tmp,wip}/fav/"$month" { genDate=$(date +%s) cat < camera/$user/$year/$month
EOF } >tmp/fav/"$month"/index.html mv_ -f {tmp/,}fav/"$month"/index.html echo >&2 "$year/$month: remove any deleted favorites" (cd fav; find "$month" -mindepth 1 -type f -not -name index.html) | while read -r fav; do base=${fav%.fav.*} name=${base##*/} unset hasSrc for src in src/"$base".fav.*; do test "${src%.txt}" != "$src" || hasSrc=set; done test "${hasSrc:+set}" || { echo >&2 "$year/$month: removing $year/fav/$fav" rm -f fav/"$fav" rm -f fav/"$month"/by-uuid/*/"${name%.*}".* } done rmdir -p 2>/dev/null fav/"$month"/by-uuid/*/ || true done popd >/dev/null done rmdir 2>/dev/null -p wip/fav/* || true