resonite-photoexif: we are EPIC. we FIX THIS for DIRECTORIES
This commit is contained in:
parent
5284872d77
commit
52d52bb2eb
|
@ -1,25 +1,36 @@
|
|||
#!/bin/sh
|
||||
set -euf
|
||||
|
||||
# $@ are resrec urls to things
|
||||
|
||||
NL="
|
||||
"
|
||||
cleanup() {
|
||||
trap 'exit' INT HUP QUIT TERM EXIT
|
||||
[ -f "${tmp_recuri:-}" ] && rm "$tmp_recuri"
|
||||
[ -f "${tmp_json:-}" ] && rm "$tmp_json"
|
||||
[ -f "${tmpfile:-}" ] && rm "$tmpfile"
|
||||
true
|
||||
}
|
||||
|
||||
trap 'cleanup' INT HUP QUIT EXIT
|
||||
trap 'cleanup' INT HUP QUIT TERM EXIT
|
||||
tmp_json="$(mktemp)"
|
||||
tmp_recuri="$(mktemp)"
|
||||
tmpfile="$(mktemp)"
|
||||
|
||||
outdir="$HOME/pics/screenshots/Resonite"
|
||||
if [ -z "$*" ]; then # default folder thingy
|
||||
read -r folder < "$outdir/secret.txt" # contains the public folder 4 screenshots
|
||||
user=$(printf '%s' "$folder" | awk -v RS='/' '$0 ~ /^U-/')
|
||||
# get all screenshot record ids
|
||||
# these never contain a space so like, lol
|
||||
set -- $(curl "$folder" | jq -r '.[].id')
|
||||
opt_folder=1
|
||||
fi
|
||||
|
||||
for resrec; do
|
||||
resrec="${resrec#resrec:///}"
|
||||
recuri="https://api.resonite.com/users/${resrec%%/*}/records/${resrec##*/}"
|
||||
for record; do
|
||||
if [ -z "${opt_folder:=}" ]; then
|
||||
record=${record#resrec:///}
|
||||
user=${record%%/*}
|
||||
record=${record##*/}
|
||||
fi
|
||||
recuri="https://api.resonite.com/users/$user/records/$record"
|
||||
curl -s -o "$tmp_recuri" "$recuri"
|
||||
timestamp="$(date -u -d "$(jq -r '.creationTime' < "$tmp_recuri")" +'%Y-%m-%d_%H-%M-%S')"
|
||||
|
||||
|
@ -28,64 +39,44 @@ for resrec; do
|
|||
curl -s "$asseturi" | tail -c +10 | brotli -d | bson2json > "$tmp_json"
|
||||
|
||||
while read -r argline; do
|
||||
exifdata="" exifdate=""
|
||||
eval "set -- $argline"
|
||||
outfile="$outdir/$timestamp.webp"
|
||||
imguri=$1
|
||||
imguri=$1; shift
|
||||
echo "downloading image $timestamp.webp"
|
||||
aria2c -q -d / --allow-overwrite=true --auto-file-renaming=false -o "$tmpfile" "$imguri"
|
||||
if [ $# -gt 1 ]; then
|
||||
meta_place=$2
|
||||
meta_host=$3
|
||||
meta_photographer=$4
|
||||
meta_time=$(date -u -d "@$5" +'%Y:%m:%d %H:%M:%S')
|
||||
shift 5
|
||||
meta_presentusers=$(sed 's/ /, /g' <<-EOF
|
||||
$*
|
||||
EOF
|
||||
)
|
||||
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, not saving"
|
||||
continue
|
||||
else
|
||||
outfile="${outfile%.webp}_$(uuidgen).webp"
|
||||
fi
|
||||
[ -n "$1" ] && exifdata="$exifdata${NL}World: $1"; shift
|
||||
[ -n "$1" ] && exifdata="$exifdata${NL}Host: $1"; shift
|
||||
[ -n "$1" ] && exifdata="$exifdata${NL}Photographer: $1"; shift
|
||||
[ -n "$1" ] && exifdate="$(date -u -d "@$1" +'%Y:%m:%d %H:%M:%S')"; shift
|
||||
[ -n "$1" ] && exifdata="$exifdata${NL}Present Users: $(printf '%s' "$*" | sed 's/ /, /g')"
|
||||
exiftool -overwrite_original -UserComment="${exifdata#$NL}" -datetimeoriginal="$exifdate" -- \
|
||||
"$tmpfile"
|
||||
outfile="$outdir/$(printf '%s' "${exifdate:-${timestamp}}" | sed 's/:/-/g ; s/ /_/g').webp"
|
||||
|
||||
if [ -f "$outfile" ]; then
|
||||
if cmp -s "$tmpfile" "$outfile"; then
|
||||
echo "WARNING: Duplicate file, not saving"
|
||||
continue
|
||||
else
|
||||
outfile="${outfile%.webp}_$(uuidgen).webp"
|
||||
fi
|
||||
else
|
||||
echo "image "$imguri" doesn't have metadata"
|
||||
fi
|
||||
|
||||
mv "$tmpfile" "$outfile"
|
||||
|
||||
done <<-EOF
|
||||
$(jq -r '.Object.Children | .. | objects | .Components.Data | select(. != null)
|
||||
| [ .[]
|
||||
| ( select(.Type=="FrooxEngine.StaticTexture2D").Data.URL.Data
|
||||
| sub("@(resdb:///(?<x>[^.]+))?.*";"https://assets.resonite.com/\(.x)")
|
||||
),
|
||||
( select(.Type=="FrooxEngine.PhotoMetadata").Data.LocationName.Data
|
||||
| gsub("\\n"; " ")
|
||||
),
|
||||
select(.Type=="FrooxEngine.PhotoMetadata").Data.LocationHost._userId.Data,
|
||||
select(.Type=="FrooxEngine.PhotoMetadata").Data.TakenBy._userId.Data,
|
||||
select(.Type=="FrooxEngine.PhotoMetadata").Data.TimeTaken.Data/1000,
|
||||
select(.Type=="FrooxEngine.PhotoMetadata").Data.UserInfos.Data[].User._userId.Data
|
||||
]
|
||||
| select(. != []) | @sh' < "$tmp_json" \
|
||||
|| jq -r '.Object.Children | .. | objects | .Components.Data | select(. != null)
|
||||
| [ .[]
|
||||
| ( select(.Type=="FrooxEngine.StaticTexture2D").Data.URL.Data
|
||||
| sub("@(resdb:///(?<x>[^.]+))?.*";"https://assets.resonite.com/\(.x)")
|
||||
)
|
||||
]
|
||||
| select(. != []) | @sh' < "$tmp_json")
|
||||
$(jq -r '.Object | .. | select(.[].Type=="FrooxEngine.StaticTexture2D")? |
|
||||
[ .[] |
|
||||
select(.Type=="FrooxEngine.StaticTexture2D"),
|
||||
select(.Type=="FrooxEngine.PhotoMetadata")
|
||||
] | [
|
||||
( .[0].Data.URL.Data | sub("@(resdb:///(?<x>[^.]+))?.*";"https://assets.resonite.com/\(.x)") ),
|
||||
try (.[1].Data.LocationName.Data | gsub("\\n"; " ")) catch "",
|
||||
.[1].Data.LocationHost._userId.Data // "",
|
||||
.[1].Data.TakenBy._userId.Data // "",
|
||||
try (.[1].Data.TimeTaken.Data/1000) catch "",
|
||||
try (.[1].Data.UserInfos.Data[].User._userId.Data) catch ""
|
||||
] | @sh' < "$tmp_json")
|
||||
EOF
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in New Issue