2023-11-07 18:04:04 -06:00
|
|
|
#!/bin/sh
|
|
|
|
set -euf
|
|
|
|
|
|
|
|
# $@ are resrec urls to things
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
[ -f "${tmp_recuri:-}" ] && rm "$tmp_recuri"
|
|
|
|
[ -f "${tmp_json:-}" ] && rm "$tmp_json"
|
|
|
|
[ -f "${tmp_json2:-}" ] && rm "$tmp_json2"
|
|
|
|
[ -f "${tmpfile:-}" ] && rm "$tmpfile"
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
trap 'cleanup' INT HUP QUIT EXIT
|
|
|
|
|
|
|
|
outdir="$HOME/pics/screenshots/Resonite"
|
|
|
|
|
|
|
|
for resrec; do
|
|
|
|
cleanup
|
|
|
|
|
|
|
|
resrec="${resrec#resrec:///}"
|
|
|
|
recuri="https://api.resonite.com/users/${resrec%%/*}/records/${resrec##*/}"
|
|
|
|
tmp_recuri="$(mktemp)"
|
|
|
|
curl -s -o "$tmp_recuri" "$recuri"
|
|
|
|
|
|
|
|
# asset uri stuff
|
|
|
|
asseturi="$(jq -r '.assetUri | sub("resdb:///(?<x>[^.]+).*";"https://assets.resonite.com/\(.x)")' < "$tmp_recuri")"
|
|
|
|
tmp_json="$(mktemp)"
|
2024-01-24 23:44:20 -06:00
|
|
|
# TODO: suck it up and make my own fucking bson->json thing so I can make this actually good
|
|
|
|
# for now this works. ew.
|
|
|
|
curl -s "$asseturi" | tail -c +10 | brotli -d | bson2 print | tr -d '\n' > "$tmp_json"
|
2023-11-07 18:04:04 -06:00
|
|
|
|
|
|
|
# save the image itself
|
|
|
|
imguri="$(jq -r '.Object.Children[0].Components.Data.[] |
|
|
|
|
select(.Type=="FrooxEngine.StaticTexture2D").Data.URL.Data |
|
|
|
|
sub("@resdb:///(?<x>[^.]+).*";"https://assets.resonite.com/\(.x)")' \
|
|
|
|
< "$tmp_json"
|
|
|
|
)"
|
2023-11-07 19:32:47 -06:00
|
|
|
timestamp="$(date -u -d "$(jq -r '.tags[] | select(contains("timestamp:")) |
|
|
|
|
sub("timestamp:(?<date>.+)";"\(.date)")' \
|
|
|
|
< "$tmp_recuri")" +'%Y-%m-%d_%H-%M-%S'
|
|
|
|
)" || timestamp="$(date -u -d "$(jq -r '.creationTime' < "$tmp_recuri")" +'%Y-%m-%d_%H-%M-%S')"
|
2023-11-07 18:04:04 -06:00
|
|
|
|
|
|
|
echo "downloading image $timestamp.webp"
|
|
|
|
tmpfile="$(mktemp)"
|
|
|
|
curl -s -o "$tmpfile" "$imguri"
|
|
|
|
|
|
|
|
outfile="$outdir/$timestamp.webp"
|
|
|
|
if [ -f "$outfile" ]; then
|
|
|
|
if cmp -s "$tmpfile" "$outfile"; then
|
|
|
|
echo "Duplicate file, not saving"
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
echo "WARNING: filename exists in 1st pass, making unique name as safeguard"
|
|
|
|
outfile="${outfile%.webp}_$(uuidgen).webp"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check if photometadata even exists
|
|
|
|
if [ "$(jq '.TypeVersions."FrooxEngine.PhotoMetadata"' < "$tmp_json")" = "null" ]; then
|
|
|
|
echo "no photometadata"
|
|
|
|
else
|
|
|
|
# if it does, we're in business
|
|
|
|
tmp_json2="$(mktemp)"
|
|
|
|
jq '.Object.Children[0].Components.Data.[] | select(.Type=="FrooxEngine.PhotoMetadata")' "$tmp_json" > "$tmp_json2"
|
|
|
|
|
|
|
|
meta_time="$(date -u -d "@$(jq -r '.Data.TimeTaken.Data | sub("{\\$date: (?<x>[0-9]+)[0-9][0-9][0-9]}"; "\(.x)")' < "$tmp_json2")" +'%Y:%m:%d %H:%M:%S')"
|
|
|
|
meta_host="$(jq -r '.Data.LocationHost._userId.Data' < "$tmp_json2")"
|
|
|
|
meta_place="$(jq -r '.Data.LocationName.Data | gsub("<[^<]+>";"")' < "$tmp_json2")"
|
|
|
|
meta_photographer="$(jq -r '.Data.TakenBy._userId.Data' < "$tmp_json2")"
|
|
|
|
meta_presentusers="$(jq -r '[.Data.UserInfos.Data[].User._userId.Data] | @tsv | gsub("\t";", ")' < "$tmp_json2")"
|
|
|
|
|
|
|
|
exiftool -overwrite_original -UserComment="World: $meta_place
|
|
|
|
Host: $meta_host
|
|
|
|
Photographer: $meta_photographer
|
|
|
|
Present Users: $meta_presentusers" "$tmpfile" \
|
|
|
|
-datetimeoriginal="$meta_time"
|
|
|
|
|
|
|
|
# outfile will be in yyyy-mm-dd_hh-mm-ss, UTC TIME!!!
|
|
|
|
outfile="$outdir/$(printf '%s' "$meta_time" | sed -e 's/:/-/g' -e 's/ /_/g').webp"
|
|
|
|
if [ -f "$outfile" ]; then
|
|
|
|
if cmp -s "$tmpfile" "$outfile"; then
|
|
|
|
echo "WARNING: Duplicate file after 2nd pass, not saving"
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
outfile="${outfile%.webp}_$(uuidgen).webp"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv "$tmpfile" "$outfile"
|
|
|
|
done
|
|
|
|
|
|
|
|
# note: when converting to png then jxl, sometimes tags get fucked up. do this
|
2024-01-24 23:44:20 -06:00
|
|
|
# alternatively: use vips pngsave instead of imagemagick
|
2023-11-07 18:04:04 -06:00
|
|
|
# for i in *.jxl; do exiftool -tagsfromfile "${i%.jxl}.webp" -usercomment -datetimeoriginal -m "$i"; done
|