#!/bin/sh -e pebkac() { [ "${*}" ] && printf "%s\n\n" "${*}" cat < Given an ID number from the Gelbooru site, downloads and stashes the full-size image in the md5 directory and adds whatever tags are found into the tag area. EOF kill $$ exit 1 } [ "${*}" ] || pebkac id="${1}" [ -z "$(echo "${id}" | tr -d '[0-9]')" ] || pebkac "ID should be an integer" taggery_name="$(basename "${0}")" case "${taggery_name}" in e621) e621_image_url_filter() { sed -e '/Size: /!d; s/^.*.*$//; s/^.*href="\([^"]*\)".*$/\1/; /:\/\//!s/^/http:\/\/e621.net/' } e621_image_tags_filter() { sed -e '/id="tag-sidebar"/,/<\/ul>/!d; /class="tag-type-/!d; s/\([^?]\)<\/a>.*$/\1/; s/^.*>//; s/ /_/g' } taggery_fmturl="http://e621.net/post/show/%s" taggery_image_url_filter=e621_image_url_filter taggery_image_tags_filter=e621_image_tags_filter ;; gelbooru) gelbooru_image_url_filter() { sed -e '/>Original imageOriginal image.*//i; s/^.*/&\n/g' | sed -e '/class="tag-type-/!d; s/\([^?]\)<\/a>.*$/\1/; s/^.*>//; s/ /_/g' } taggery_fmturl="http://gelbooru.com/index.php?page=post&s=view&id=%s" taggery_image_url_filter=gelbooru_image_url_filter taggery_image_tags_filter=gelbooru_image_tags_filter ;; *) pebkac "Unsupported" ;; esac # Load KVS kvs=".${taggery_name}.kvdb" . "$(dirname "${0}")/lib/kvs.sh" # Load Taggery . "$(dirname "${0}")/lib/taggery.sh" image_url() { taggery_image_url "${@}"; } image_tags() { taggery_image_tags "${@}"; } cd "$(dirname "${0}")" file="$(image_url "${id}")" tags="$(image_tags "${id}")" [ "${file}" -a "${tags}" ] || { echo "Nothing found!"; kill $$; exit 1; } name="$(basename "${file}")" wget -O "md5/${name}" "${file}" for tag in ${tags} do echo ${tag} mkdir -p "tag/${tag}" ln -sf "../../md5/${name}" "tag/${tag}/" done