Last active
July 10, 2023 23:30
-
-
Save alexandreprates/a32ddd46f2a60659181a2d5f8fd0fe0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OUTPUTFILE=.response.json.tmp | |
function fetch_data() { | |
echo "$1" | |
curl -s -H "Authorization: Bearer $(cat .civitai_token)" $1 -o $OUTPUTFILE || rm $OUTPUTFILE | |
} | |
function parse() { | |
cat $OUTPUTFILE | jq -r '.items[] | [ .type, (.modelVersions[0].files[].name | gsub(" "; "-")), .modelVersions[0].files[].downloadUrl] | @csv' | |
} | |
function nextpage() { | |
cat $OUTPUTFILE | jq -r '.metadata.nextPage' | |
} | |
function fetch_model() { | |
IFS=',' read -r type filename url <<< "$1" | |
type="${type,,}" | |
type="${type//\"/}" | |
filename="${filename//\"/}" | |
url="${url//\"/}" | |
echo "CHECK: $filename [$type]" | |
case $type in | |
checkpoint) | |
destination_folder="./models/Stable-diffusion" | |
;; | |
textualinversion) | |
destination_folder="./embeddings" | |
;; | |
lora) | |
destination_folder="./models/Lora" | |
;; | |
locon) | |
destination_folder="./models/LyCORIS" | |
;; | |
hypernetwork) | |
destination_folder="./models/hypernetworks" | |
;; | |
*) | |
echo Unknow type: "$type" | |
return 0 | |
;; | |
esac | |
if [ -f "$destination_folder/$filename" ]; then | |
echo "File $destination_folder/$filename exists IGNORING" | |
return 0 | |
fi | |
aria2c --console-log-level=error -x 6 -s 6 -k 100M "$url" -d $destination_folder -o $filename | |
sleep 5 | |
} | |
fetch_data "https://civitai.com/api/v1/models?favorites=true&primaryFileOnly=true" | |
while : ; do | |
for line in $(parse); do | |
fetch_model $line | |
done | |
sleep 1 | |
[ "$(nextpage)" = "null" ] && break | |
fetch_data "$(nextpage)" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment