summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfetch-all-album-images.sh/fetch-all-album-images.sh39
1 files changed, 33 insertions, 6 deletions
diff --git a/fetch-all-album-images.sh/fetch-all-album-images.sh b/fetch-all-album-images.sh/fetch-all-album-images.sh
index 13e0a54..b1069f6 100755
--- a/fetch-all-album-images.sh/fetch-all-album-images.sh
+++ b/fetch-all-album-images.sh/fetch-all-album-images.sh
@@ -32,6 +32,7 @@ Return values:
3 Incorrect OS type
4 Unable to find dependency
5 Not run as root or sudo
+ 6 Webpage error
Environment variables:
FAAI_OUTDIR Destination directory for downloaded images. Default is PWD.
ENDUSAGE
@@ -94,14 +95,40 @@ fetch_image_for() {
local thisdomain="$( echo "${baseurl}" | grep -oE 'https?:\/\/[a-zA-Z.]*\/' )"
local tp="$( curl -H "${FAAI_USERAGENT}" -H "${FAAI_H1}" -H "${FAAI_H2}" -H "${FAAI_H3}" --referer "${referer}" -c "${cookiefile}" -s -L -k "${baseurl}/${item}" )"
+
+ local method=""
+ echo "${tp}" | grep -qE "Captcha_image\".*action=\"\/download\/.*download\.gif" && method="captcha"
+ echo "${tp}" | grep -qoE 'a href="\/.*download\.gif' && method="href"
+
debuglev 5 && echo "${tp}"| grep -oE 'a href="\/.*download\.gif'
- # fetch image
- for word in $( echo "${tp}" | awk '/class="selectedCoverThumb"/{print;}' | grep -oE 'a href="\/download\/[A-Za-z0-9\/_-]*"><img' | sed -r -e 's/^a href="\///;' -e 's/"><img.*$//;' -e "s@^@${thisdomain}@;" ) ;
- do
- echo "curl -H "${FAAI_USERAGENT}" -H ${FAAI_H1} -H ${FAAI_H2} -H ${FAAI_H3} --referer ${referer} -c ${cookiefile} -s -L -k ${word} > ${FAAI:-.}/${artist} - ${album} - ${item}.jpg"
- curl -H "${FAAI_USERAGENT}" -H "${FAAI_H1}" -H "${FAAI_H2}" -H "${FAAI_H3}" --referer "${referer}" -c "${cookiefile}" -s -L -k ${word} > "${FAAI:-.}/${artist} - ${album} - ${item}.jpg"
- done
+ case "${method}" in
+
+ href)
+ # fetch image
+ for word in $( echo "${tp}" | awk '/class="selectedCoverThumb"/{print;}' | grep -oE 'a href="\/download\/[A-Za-z0-9\/_-]*"><img' | sed -r -e 's/^a href="\///;' -e 's/"><img.*$//;' -e "s@^@${thisdomain}@;" ) ;
+ do
+ echo "curl -H "${FAAI_USERAGENT}" -H ${FAAI_H1} -H ${FAAI_H2} -H ${FAAI_H3} --referer ${referer} -c ${cookiefile} -s -L -k ${word} > ${FAAI:-.}/${artist} - ${album} - ${item}.jpg"
+ curl -H "${FAAI_USERAGENT}" -H "${FAAI_H1}" -H "${FAAI_H2}" -H "${FAAI_H3}" --referer "${referer}" -c "${cookiefile}" -s -L -k ${word} > "${FAAI:-.}/${artist} - ${album} - ${item}.jpg"
+ done
+ ;;
+
+ captcha)
+ # need to visit each page, collect its captcha action string and plug it in as a URL
+ for word in $( echo "${tp}" | grep -oE '"Captcha_image".*action="\/download\/[A-Za-z0-9\/_-]*"><input type=' | sed -r -e 's/^"Captcha_image".*action="//;' -e 's/"><input type=.*$//;' -e "s@^@${thisdomain}@;" ) ;
+ do
+ echo "curl -H "${FAAI_USERAGENT}" -H ${FAAI_H1} -H ${FAAI_H2} -H ${FAAI_H3} --referer ${referer} -c ${cookiefile} -s -L -k ${word} > ${FAAI:-.}/${artist} - ${album} - ${item}.jpg"
+ curl -H "${FAAI_USERAGENT}" -H "${FAAI_H1}" -H "${FAAI_H2}" -H "${FAAI_H3}" --referer "${referer}" -c "${cookiefile}" -s -L -k ${word} > "${FAAI:-.}/${artist} - ${album} - ${item}.jpg"
+ done
+ ;;
+
+ *)
+ ferror "${scripttrim} 6: Unsupported webpage provided. Output follows."
+ echo "${tp}" 1>&2
+ exit 2
+ ;;
+
+ esac
}
# DEFINE TRAPS
bgstack15