Save Gemini JSON in parent in-dir as YYYYMMDD-name.json (avoid affecting job fingerprint)
This commit is contained in:
parent
b3cf019a24
commit
3de0d498ce
1 changed files with 22 additions and 5 deletions
|
|
@ -1,11 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
IN_DIR="${1:?Usage: $0 <input-dir> [\"Title\"] [\"Location\"] [max_frames] [no-append]}"
|
||||
IN_DIR="${1:?Usage: $0 <input-dir> [\"Title\"] [\"Location\"] [max_frames]}"
|
||||
TITLE="${2:-}"
|
||||
LOCATION="${3:-}"
|
||||
MAX_FRAMES="${4:-12}"
|
||||
NO_APPEND="${5:-}"
|
||||
|
||||
# Source system-wide Gemini API key if present so the webserver can run this as www-data.
|
||||
if [ -f /etc/mvlog/gemini.env ]; then
|
||||
|
|
@ -196,9 +195,27 @@ if [ -z "$TEXT" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Save raw Gemini JSON for reference
|
||||
OUT_JSON="$IN_DIR/gemini_generated.json"
|
||||
# Save raw Gemini JSON for reference in parent in-dir with YYYYMMDD-name.json
|
||||
OUT_PARENT="$(dirname "$IN_DIR")"
|
||||
JOBNAME="$(basename "$IN_DIR")"
|
||||
if [[ "$JOBNAME" =~ ^([0-9]{8})[_-](.+)$ ]]; then
|
||||
DATE_PART="${BASH_REMATCH[1]}"
|
||||
NAME_PART="${BASH_REMATCH[2]}"
|
||||
else
|
||||
firstfile="$(find "$IN_DIR" -maxdepth 1 -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.webp' -o -iname '*.gif' -o -iname '*.mp4' -o -iname '*.mov' -o -iname '*.m4v' -o -iname '*.webm' -o -iname '*.mkv' \) -printf '%p\n' | sort | head -n1)"
|
||||
if [ -n "$firstfile" ]; then
|
||||
DATE_PART="$(date -r "$firstfile" +%Y%m%d 2>/dev/null || date +%Y%m%d)"
|
||||
else
|
||||
DATE_PART="$(date +%Y%m%d)"
|
||||
fi
|
||||
NAME_PART="$JOBNAME"
|
||||
fi
|
||||
# sanitize
|
||||
SAFE_NAME="$(echo "$NAME_PART" | tr ' /' '__' | tr -c '[:alnum:]_.-' '_')"
|
||||
OUT_JSON="$OUT_PARENT/${DATE_PART}-${SAFE_NAME}.json"
|
||||
echo "$TEXT" | jq . > "$OUT_JSON"
|
||||
chown www-data:www-data "$OUT_JSON" 2>/dev/null || true
|
||||
chmod 664 "$OUT_JSON" 2>/dev/null || true
|
||||
|
||||
# Extract fields from Gemini JSON
|
||||
DESCRIPTION=$(echo "$TEXT" | jq -r '.description // empty')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue