#!/bin/bash relay=$1 pubkey=$2 backup_folder="$3/$2" mkdir -p "$backup_folder" jsonl_output=$(nak req -a "$pubkey" -k 1 -k 30023 -k 30024 --limit 10000 "$relay") while IFS= read -r line; do image_urls=$(echo "$line" | jq -r '.content | scan("(https?://[^)\\] ]+\\.(?:png|jpg|jpeg|gif))") | .[]?') for url in $image_urls; do file_name=$(basename "$url") local_file="$backup_folder/$file_name" if [[ -f "$local_file" ]]; then echo "skipping $url, already downloaded." else curl -L -s -o "$local_file" "$url" if [[ $? -eq 0 ]]; then echo "downloaded $url" else echo "failed to download $url" exit 1 fi fi done <<< "$image_urls" done <<< "$jsonl_output" echo "backup for $pubkey completed"