Upload dan-download.sh with huggingface_hub
Browse files- dan-download.sh +65 -0
dan-download.sh
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Replace with your danbooru login and API key
|
4 |
+
LOGIN="youridhere"
|
5 |
+
API_KEY="your_api_key_here_xxxxx"
|
6 |
+
|
7 |
+
|
8 |
+
# This script takes filenames
|
9 |
+
# on stdin, and then downloads from danbooru to local directories,
|
10 |
+
# matching the format.
|
11 |
+
# The format should be:
|
12 |
+
# data-xxxx/filename.jpg
|
13 |
+
|
14 |
+
#########################################################################
|
15 |
+
#
|
16 |
+
# script internals only, beyond this point.
|
17 |
+
#########################################################################
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
# This func takes an image pathname, and calculates the
|
22 |
+
# danbooru image id from the filename.
|
23 |
+
# It then grabs the original image,
|
24 |
+
# and the tag info (for .txt), if the jpg does not already exist
|
25 |
+
download_image(){
|
26 |
+
[[ -f $1 ]] && return
|
27 |
+
|
28 |
+
|
29 |
+
# strip off leading directory names, and file extensions
|
30 |
+
id=${1##*/}
|
31 |
+
id=${id%*.???}
|
32 |
+
|
33 |
+
IMAGE_ID=$id
|
34 |
+
imgfile=$IMAGE_ID.jpg
|
35 |
+
|
36 |
+
POST_DATA=$(curl -q -s -u "$LOGIN:$API_KEY" "https://danbooru.donmai.us/posts/$IMAGE_ID.json")
|
37 |
+
# debug
|
38 |
+
#echo $POST_DATA >/tmp/post_data.json
|
39 |
+
|
40 |
+
IMAGE_URL=$(echo $POST_DATA | jq -r '.file_url')
|
41 |
+
# Using _general gives us the non-artist/character tags
|
42 |
+
# Remove _general if you want that included
|
43 |
+
TAG_INFO=$(echo $POST_DATA | jq -r '.tag_string_general')
|
44 |
+
|
45 |
+
if [[ "$IMAGE_URL" == "null" ]] ; then
|
46 |
+
echo ERROR RETREIVING POST
|
47 |
+
echo DEBUG:
|
48 |
+
echo $POST_DATA
|
49 |
+
else
|
50 |
+
echo Downloading to $imgfile
|
51 |
+
curl -s "$IMAGE_URL" > $imgfile
|
52 |
+
tagfile=$IMAGE_ID.txt
|
53 |
+
[[ -f $tagfile ]] || echo "$TAG_INFO" >$tagfile
|
54 |
+
fi
|
55 |
+
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
while read oneline ; do
|
61 |
+
download_image $oneline
|
62 |
+
done
|
63 |
+
|
64 |
+
|
65 |
+
|