#!/bin/bash # migrate-seasons.sh — move old-format seasons clips into the new sky-cam # directory structure for astronomical year 2025 only (Winter 2025-26 onward). # # Earlier years (Autumn 2025 / ASTRO_YEAR=2024 and before) are skipped. # # Two categories of old file: # MIGRATE — clips from the legacy script (filename has "Dayof" with no # preceding digit, e.g. 2026-03-21_Mvt3-Dayof92-final.mp4) # → moved to the correct $MOVIES_DIR//2025//Mvt/ # # QUARANTINE — clips produced by the later broken script that recorded a # specific day number but used the wrong movement total # (filename has Dayof92, e.g. 2026-04-10_Mvt1-Day21of92-final.mp4) # → moved to $MOVIES_DIR//2025/quarantine-old-scripts/ # Review and delete when you're done: rm -rf # # Usage: # ./migrate-seasons.sh [--dry-run] [OLD_ROOT] # # --dry-run print what would happen without moving anything # OLD_ROOT root of old movie archive # (default: ~/drives/local-2tb/movies/sunrise) # # After running, trigger montages for completed movements: # ./montage-mvt.sh 2026-04-19 east # Spring Mvt1 (~20/31 days) # ./montage-mvt.sh 2026-01-18 east # Winter Mvt1 (~18/29 days) # ./montage-mvt.sh 2026-02-16 east # Winter Mvt2 (~24/29 days) # ./montage-mvt.sh 2026-03-19 east # Winter Mvt3 (~20/31 days) set -euo pipefail SCRIPT_DIR="$(dirname "$(realpath "$0")")" source "$SCRIPT_DIR/sky-cam.conf" DRY_RUN=false OLD_ROOT="$HOME/drives/local-2tb/movies/sunrise" for arg in "$@"; do case "$arg" in --dry-run) DRY_RUN=true ;; *) OLD_ROOT="$arg" ;; esac done CAM="$SUNRISE_CAM" NEW_ROOT="$MOVIES_DIR/$CAM/2025" QUARANTINE="$NEW_ROOT/quarantine-old-scripts" echo "Old archive : $OLD_ROOT" echo "New root : $NEW_ROOT" echo "Quarantine : $QUARANTINE" echo "Camera : $CAM" $DRY_RUN && echo "(DRY RUN — no files will be moved)" echo "" declare -A CNT_MIGRATE CNT_QUARANTINE CNT_SKIP do_move() { local src="$1" dst="$2" label="$3" key="$4" local dst_dir dst_dir="$(dirname "$dst")" if [ -e "$dst" ]; then printf " EXISTS %-11s %s\n" "" "$(basename "$src")" CNT_SKIP["$key"]=$(( ${CNT_SKIP["$key"]:-0} + 1 )) return fi if $DRY_RUN; then printf " %-10s %s\n %13s-> %s/\n" \ "$label" "$(basename "$src")" "" "$dst_dir" else mkdir -p "$dst_dir" mv "$src" "$dst" fi case "$label" in MIGRATE) CNT_MIGRATE["$key"]=$(( ${CNT_MIGRATE["$key"]:-0} + 1 )) ;; QUARANTINE) CNT_QUARANTINE["$key"]=$(( ${CNT_QUARANTINE["$key"]:-0} + 1 )) ;; esac } # Returns true if filename has the bad pattern: Dayof92 # (specific day number + wrong 92-day total from the broken Spring script) is_quarantine_candidate() { [[ "$1" =~ Day[0-9]+of92 ]] } while IFS= read -r -d '' src; do fname="$(basename "$src")" # Extract YYYY-MM-DD prefix date_str="${fname%%_*}" if [[ ! "$date_str" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then echo "SKIP (no date): $fname" continue fi # Classify date using the new system's boundaries if ! info="$(python3 "$SCRIPT_DIR/season_info.py" "$date_str" 2>/dev/null)"; then echo "ERROR: season_info.py failed for $date_str — skipping $fname" continue fi eval "$info" # Provides: SEASON MVT_NUM DAY_OF_MVT DAYS_IN_MVT ASTRO_YEAR ... # Skip everything outside the current astronomical year if [ "$ASTRO_YEAR" != "2025" ]; then continue fi key="${SEASON}/Mvt${MVT_NUM}" if is_quarantine_candidate "$fname"; then do_move "$src" "$QUARANTINE/$fname" "QUARANTINE" "$key" else do_move "$src" "$NEW_ROOT/$SEASON/Mvt$MVT_NUM/$fname" "MIGRATE" "$key" fi done < <(find \ "$OLD_ROOT/Spring" \ "$OLD_ROOT/Winter" \ "$OLD_ROOT/Autumn" \ -name "*-final.mp4" -print0 2>/dev/null | sort -z) echo "" echo "=== Summary (ASTRO_YEAR=2025 only) ===" printf "%-22s %8s %11s %7s\n" "Movement" "Migrated" "Quarantined" "Skipped" printf "%-22s %8s %11s %7s\n" "--------" "--------" "-----------" "-------" declare -A ALL_KEYS for k in "${!CNT_MIGRATE[@]}" "${!CNT_QUARANTINE[@]}" "${!CNT_SKIP[@]}"; do ALL_KEYS["$k"]=1 done total_m=0 total_q=0 for key in $(printf '%s\n' "${!ALL_KEYS[@]}" | sort); do m=${CNT_MIGRATE["$key"]:-0} q=${CNT_QUARANTINE["$key"]:-0} s=${CNT_SKIP["$key"]:-0} printf "%-22s %8d %11d %7d\n" "$key" "$m" "$q" "$s" total_m=$(( total_m + m )) total_q=$(( total_q + q )) done printf "%-22s %8d %11d\n" "TOTAL" "$total_m" "$total_q" echo "" if $DRY_RUN; then echo "Re-run without --dry-run to move the files." echo "" fi echo "Next steps:" echo " 1. Build montages for completed movements:" echo " ./montage-mvt.sh 2026-04-19 $CAM # Spring Mvt1" echo " ./montage-mvt.sh 2026-01-18 $CAM # Winter Mvt1" echo " ./montage-mvt.sh 2026-02-16 $CAM # Winter Mvt2" echo " ./montage-mvt.sh 2026-03-19 $CAM # Winter Mvt3" echo " 2. Confirm each montage plays correctly with music." echo " 3. Delete temp files from old archive:" echo " find $OLD_ROOT -name '*-temp.mp4' -delete" echo " 4. Delete quarantined bad clips once confirmed:" echo " rm -rf $QUARANTINE"