[bin] Update cocktail of webcam scripts
This commit is contained in:
126
bin/.bin/webcam-build-timelapses
Executable file
126
bin/.bin/webcam-build-timelapses
Executable file
@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env bash
|
||||
# run_all_timelapses.sh
|
||||
#
|
||||
# Run timelapse creation for a fixed set of webcams,
|
||||
# collect public URLs, update HTML index, and send one combined ntfy notification.
|
||||
#
|
||||
# Requirements: make_timelapse.sh in same folder or PATH
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# --- Settings ---
|
||||
BASE_DIR="/media/photos/misc/webcams"
|
||||
INDEX_FILE="$BASE_DIR/timelapses.html"
|
||||
WEBCAMS=(
|
||||
"frontyard"
|
||||
"basement_table"
|
||||
"mailbox"
|
||||
"basement_extension"
|
||||
"backyard_low"
|
||||
"backyard_north"
|
||||
"basement_cape"
|
||||
"basement_tv"
|
||||
"backyard"
|
||||
"bulkhead"
|
||||
"barn"
|
||||
"garage"
|
||||
"birds"
|
||||
"porch"
|
||||
"garden"
|
||||
"diningroom"
|
||||
)
|
||||
TIMELAPSE_SCRIPT="/usr/local/bin/make_timelapse"
|
||||
|
||||
NTFY_URL="https://ntfy.unbl.ink/timelapse"
|
||||
WEB_PREFIX="https://files.lab.unbl.ink"
|
||||
# ----------------
|
||||
|
||||
# Yesterday's date
|
||||
if date -d "yesterday" +%Y >/dev/null 2>&1; then
|
||||
# GNU date (Linux)
|
||||
YESTERDAY=$(date -d "yesterday" +"%Y/%m/%d")
|
||||
else
|
||||
# BSD date (macOS)
|
||||
YESTERDAY=$(date -v-1d +"%Y/%m/%d")
|
||||
fi
|
||||
|
||||
LINKS=()
|
||||
|
||||
for cam in "${WEBCAMS[@]}"; do
|
||||
TARGET_DIR="$BASE_DIR/$cam/$YESTERDAY"
|
||||
|
||||
if [[ -d "$TARGET_DIR" ]]; then
|
||||
echo "📷 Processing $cam ($TARGET_DIR)"
|
||||
OUTPUT=$("$TIMELAPSE_SCRIPT" "$TARGET_DIR")
|
||||
echo "$OUTPUT"
|
||||
|
||||
LINK="$WEB_PREFIX/$cam/$YESTERDAY/timelapse.mp4"
|
||||
if [[ -f "$TARGET_DIR/timelapse.mp4" ]]; then
|
||||
LINKS+=("[$cam] $LINK")
|
||||
fi
|
||||
else
|
||||
echo "⚠️ Skipping $cam (no folder for $YESTERDAY)"
|
||||
fi
|
||||
done
|
||||
|
||||
# --- Update HTML index ---
|
||||
mkdir -p "$BASE_DIR"
|
||||
if [[ ! -f "$INDEX_FILE" ]]; then
|
||||
cat >"$INDEX_FILE" <<EOF
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Webcam Timelapses</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 1em; background: #f9f9f9; }
|
||||
h2 { margin-top: 1.5em; }
|
||||
ul { list-style: none; padding: 0; }
|
||||
li { margin: 0.3em 0; }
|
||||
a { text-decoration: none; color: #0366d6; }
|
||||
a:hover { text-decoration: underline; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Webcam Timelapses</h1>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Insert new section for yesterday at the top
|
||||
TMP=$(mktemp)
|
||||
{
|
||||
echo "<h2>$YESTERDAY</h2>"
|
||||
echo "<ul>"
|
||||
for entry in "${LINKS[@]}"; do
|
||||
cam="${entry%%]*}"
|
||||
cam="${cam#[}"
|
||||
url="${entry#* }"
|
||||
echo " <li><a href=\"$url\">$cam</a></li>"
|
||||
done
|
||||
echo "</ul>"
|
||||
echo "<hr>"
|
||||
} >"$TMP"
|
||||
|
||||
# Place new block after <h1> line
|
||||
awk -v block="$(cat "$TMP")" '
|
||||
/<h1>/ { print; getline; print; print block; next }
|
||||
{ print }
|
||||
' "$INDEX_FILE" >"$INDEX_FILE.new"
|
||||
|
||||
mv "$INDEX_FILE.new" "$INDEX_FILE"
|
||||
rm "$TMP"
|
||||
|
||||
echo "📄 Updated HTML index: $INDEX_FILE"
|
||||
|
||||
# --- Send combined notification ---
|
||||
if [[ -n "$NTFY_URL" ]] && [[ ${#LINKS[@]} -gt 0 ]]; then
|
||||
MSG="Timelapses for $YESTERDAY:\n$(printf '%s\n' "${LINKS[@]}")"
|
||||
curl -s -H "Title: Timelapses complete" \
|
||||
-H "Priority: high" \
|
||||
-d "$MSG" \
|
||||
"$NTFY_URL" >/dev/null || true
|
||||
echo "📢 Combined notification sent to ntfy."
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user