Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Set admin password here
- password=""
- password_hash=$(echo -ne "choujin-steiner--$password--" | sha1sum | awk '{print $1}')
- SCRIPT_DIR=/srv/auto_tagger
- cd $SCRIPT_DIR
- sleep 1
- # Loop through spool/ content
- while true ; do
- oldest_file="$(find spool -mindepth 1 -type f | sort -n | head -n 1)"
- # if nothing to process, exit
- if [ -z "${oldest_file}" ]; then
- rm /tmp/deepdanbooru_thread.lock
- break
- fi
- image_id=$(basename "$oldest_file")
- # Break if booru is not running
- if ! curl "127.0.0.1:8080/post.json" --no-progress-meter > /dev/null ; then
- rm /tmp/deepdanbooru_thread.lock
- break
- fi
- # Get page of post
- max_id=$(curl 127.0.0.1:8080/post.json --no-progress-meter | jq -r '.[0] | .id')
- dp=$(($max_id-$image_id))
- page=$(($dp/40+1))
- # Get image tags
- curl "127.0.0.1:8080/post.json?page=$page" --no-progress-meter | jq -r ".[] | select(.id==$image_id) | .tags + \" \""" > /tmp/autotagging_image_tags.txt
- # Check if image contains 'auto_tagged' tag
- if cat /tmp/autotagging_image_tags.txt | grep -qF 'auto_tagged' ; then
- # Strip auto_tagged and continue
- sed -i 's/\<auto_tagged\>//g' /tmp/autotagging_image_tags.txt
- curl "127.0.0.1:8080/post/update.xml" \
- --no-progress-meter \
- -H "Expect:" \
- -F 'login=admin' \
- -F "password_hash=$password_hash" \
- -F "id=$image_id" \
- -F "post[tags]=</tmp/autotagging_image_tags.txt"
- else
- # Start deepdanbooru processing
- image_path=$(cat "$oldest_file")
- ./add_deepdanbooru_tags.sh "$image_path" /tmp/autotagging_image_tags.txt
- # Break if booru is not running
- if ! curl "127.0.0.1:8080/post.json" --no-progress-meter > /dev/null ; then
- rm /tmp/deepdanbooru_thread.lock
- break
- fi
- # Update tags
- curl "127.0.0.1:8080/post/update.xml" \
- --no-progress-meter \
- -H "Expect:" \
- -F 'login=admin' \
- -F "password_hash=$password_hash" \
- -F "id=$image_id" \
- -F "post[tags]=</tmp/autotagging_image_tags.txt"
- sleep 1
- fi
- rm /tmp/autotagging_image_tags.txt
- rm $oldest_file
- done
Add Comment
Please, Sign In to add comment