#!/bin/bash
set -e
REPO="/root/firefrost-work/firefrost-operations-manual"
IMG_BASE="$REPO/photos/staff-archive/images"
VID_BASE="/tmp/staff-videos"
EXTRACT="/tmp/staff-extract"
rm -rf "$EXTRACT" && mkdir -p "$EXTRACT"
unzip -q /root/staff.zip -d "$EXTRACT"
for year in 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025; do
  mkdir -p "$IMG_BASE/$year" "$VID_BASE/$year"
done
mkdir -p "$IMG_BASE/unknown" "$VID_BASE/unknown"
IMG_COUNT=0; VID_COUNT=0
for file in "$EXTRACT"/Staff/*; do
  [ -f "$file" ] || continue
  fn=$(basename "$file")
  ext=$(echo "${fn##*.}" | tr '[:upper:]' '[:lower:]')
  year="unknown"
  [[ "$fn" =~ (20[12][0-9]) ]] && year="${BASH_REMATCH[1]}"
  if [[ "$ext" =~ ^(mp4|mov|avi|mkv|m4v|webm)$ ]]; then
    cp "$file" "$VID_BASE/$year/$fn"
    VID_COUNT=$((VID_COUNT+1))
  else
    cp "$file" "$IMG_BASE/$year/$fn"
    IMG_COUNT=$((IMG_COUNT+1))
  fi
done
echo "Images: $IMG_COUNT | Videos: $VID_COUNT"
for dir in "$IMG_BASE"/*/; do
  c=$(ls -1 "$dir" 2>/dev/null | wc -l)
  [ "$c" -gt 0 ] && echo "IMG $(basename $dir): $c"
done
for dir in "$VID_BASE"/*/; do
  c=$(ls -1 "$dir" 2>/dev/null | wc -l)
  [ "$c" -gt 0 ] && echo "VID $(basename $dir): $c"
done
