Skip to content

Instantly share code, notes, and snippets.

@unphased
Last active March 21, 2024 18:13
Show Gist options
  • Save unphased/8d1a45e670440587cdfc0274f3bc098d to your computer and use it in GitHub Desktop.
Save unphased/8d1a45e670440587cdfc0274f3bc098d to your computer and use it in GitHub Desktop.
civitai download script
#!/bin/bash
for i in "$@"; do
# Forcibly obtain filename via returned header truncated plain get
FILENAME=$(curl -s -H "Authorization: Bearer $(cat ~/civitai_apikey.txt)" -i -L --range '0-1' "$i" | grep -a Content-Disposition | sed -n 's/.*filename=["]*\([^"]*\)["]*.*/\1/p')
if [ -f "$FILENAME" ]; then
echo "!!!! File $FILENAME already exists. Continuing via -L -C - -O \$filename:"
curl -L -C - -o $FILENAME --retry 4 -H "Authorization: Bearer $(cat ~/civitai_apikey.txt)" "$i"
else
echo "========= Downloading into $FILENAME:"
curl -JLO --retry 4 -H "Authorization: Bearer $(cat ~/civitai_apikey.txt)" "$i"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment