Insert the date (if available) into the sidecar JSON.
This commit is contained in:
parent
08ffabe0d6
commit
1aa0388e80
29
insert-date-into-json.bash
Normal file
29
insert-date-into-json.bash
Normal file
@ -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
|
||||||
Loading…
x
Reference in New Issue
Block a user