back to scripts

media-english-check.sh

bash 69 lines secrets redacted

Flags media with missing or non-English audio/subtitle tracks.

Note Live script from my home-lab server. Tokens, IDs, phone numbers and other secrets have been replaced with placeholders like <WHATSAPP_GROUP_ID> — everything else is the real, running code.
#!/usr/bin/env bash
set -euo pipefail

REPORT_DIR=/home/lanky/reports
LOCK_FILE=$REPORT_DIR/media-english-check.lock
GROUP_ID=<WHATSAPP_GROUP_ID>
mkdir -p "$REPORT_DIR"

if [ "${1:-}" = "--worker" ]; then
  exec 9>"$LOCK_FILE"
  if ! flock -n 9; then
    exit 0
  fi

  stamp=$(date +%Y%m%d-%H%M%S)
  run_log="$REPORT_DIR/media-english-check-$stamp.log"
  set +e
  report_path=$(/home/lanky/scripts/nas-media-check.py 2>"$run_log")
  status=$?
  set -e

  if [ -n "$report_path" ] && [ -f "$report_path" ]; then
    cp "$report_path" "$REPORT_DIR/media-english-check-latest.txt"
    summary=$(awk '
      /^Media files checked:/ {checked=$0}
      /^Playback concerns:/ {playback=$0}
      /^No English audio tag:/ {english=$0}
      /^Unknown audio language:/ {unknown=$0}
      END {
        print "Media Admin English/playback check completed."
        print "- Status: " (status == 0 ? "ok" : "needs review")
        print "- " checked
        print "- " playback
        print "- " english
        print "- " unknown
      }
    ' status="$status" "$report_path")
    summary="$summary
- Full report: $report_path
- No files were deleted or moved by this English/playback check."
    if [ -z "${SERVICE_DESK_JOB_ID:-}" ]; then
      sudo -u lanky openclaw message send \
        --channel whatsapp \
        --account default \
        --target "$GROUP_ID" \
        --message "$summary" \
        --media "$report_path" \
        --force-document >>"$run_log" 2>&1 || true
    fi
  else
    if [ -z "${SERVICE_DESK_JOB_ID:-}" ]; then
      sudo -u lanky openclaw message send \
        --channel whatsapp \
        --account default \
        --target "$GROUP_ID" \
        --message "Media Admin English/playback check failed before producing a report. Log: $run_log" >>"$run_log" 2>&1 || true
    fi
  fi
  exit "$status"
fi

if flock -n "$LOCK_FILE" true; then
  nohup "$0" --worker >/dev/null 2>&1 &
  echo "Media Admin English/playback check started in the background."
  echo "It is report-only: no files will be deleted or moved."
  echo "A WhatsApp update will be sent to Lanky Server Alerts when complete."
else
  echo "A Media Admin English/playback check is already running."
fi

back to scripts