diff --git a/insert-date-into-json.bash b/insert-date-into-json.bash new file mode 100644 index 0000000..0aa0d0a --- /dev/null +++ b/insert-date-into-json.bash @@ -0,0 +1,29 @@ +#!/bin/bash + +for f in *.info.json; do + [ -f "$f" ] || continue + + # Extract title without extension + title="${f%.info.json}" + # Remove trailing ID if present + title="${title% \[*\]}" + + # Extract the date at the beginning of the title (YYYYMMDD) + if [[ "$title" =~ ^([0-9]{8}) ]]; then + upload_date="${BASH_REMATCH[1]}" + else + echo "No date found in $f, skipping." + continue + fi + + # Update JSON upload_date + if command -v jq >/dev/null 2>&1; then + tmpfile=$(mktemp) + jq --arg date "$upload_date" '.upload_date = $date' "$f" > "$tmpfile" && mv "$tmpfile" "$f" + echo "Updated upload_date in $f: $upload_date" + else + # Simple sed fallback (only for simple JSON) + sed -i "s/\"upload_date\": *\"\"/\"upload_date\": \"$upload_date\"/" "$f" + echo "Updated upload_date in $f: $upload_date (using sed)" + fi +done