]> CyberLeo.Net >> Repos - CDN/taggery.git/blob - fetch
Move custom site settings into their own files
[CDN/taggery.git] / fetch
1 #!/bin/sh -e
2
3 pebkac() {
4   [ "${*}" ] && printf "%s\n\n" "${*}"
5   cat <<EOF
6 Usage: $(basename "${0}") <id>
7
8 Given an ID number from the Gelbooru site, downloads and stashes the full-size
9 image in the md5 directory and adds whatever tags are found into the tag area.
10 EOF
11   kill $$
12   exit 1
13 }
14
15 [ "${*}" ] || pebkac
16 id="${1}"
17 [ -z "$(echo "${id}" | tr -d '[0-9]')" ] || pebkac "ID should be an integer"
18
19 taggery_name="$(basename "${0}")"
20 case "${taggery_name}" in
21 e621|gelbooru)
22   . "$(dirname "${0}")/lib/${taggery_name}_settings.sh"
23   ;;
24 *) pebkac "Unsupported" ;;
25 esac
26
27 # Load KVS
28 kvs=".${taggery_name}.kvdb"
29 . "$(dirname "${0}")/lib/kvs.sh"
30
31 # Load Taggery
32 . "$(dirname "${0}")/lib/taggery.sh"
33 image_url() { taggery_image_url "${@}"; }
34 image_tags() { taggery_image_tags "${@}"; }
35
36 cd "$(dirname "${0}")"
37
38 file="$(image_url "${id}")"
39 tags="$(image_tags "${id}")"
40
41 [ "${file}" -a "${tags}" ] || { echo "Nothing found!"; kill $$; exit 1; }
42
43 name="$(basename "${file}")"
44 wget -O "md5/${name}" "${file}"
45 for tag in ${tags}
46 do
47   echo ${tag}
48   mkdir -p "tag/${tag}"
49   ln -sf "../../md5/${name}" "tag/${tag}/"
50 done