Код:
#!/bin/bash
log="/www/bl00dl1nes/projects/new_school_site/aeris/testt/logging"
#main="$1"
fetch_img()
{
#images="$2"
images=`echo "$2" | grep '<b>Images</b>' | awk {'print $7'} | sed 's/<br//'`
id=`echo $1 | sed 's/cat//' | sed 's/p1.html//'`
if [ -z "$images" -o "$images" = "0" ]; then
exit 1
fi
while [ ! "$images" = "0" ]; do
image=`curl [url="http://..." 2>/dev/null | grep 'britepic_src' | sed 's/britepic_src=\"//' | sed 's/\"//'`
if [ "$image" = "" ]; then
images=`echo $(($images-1))`
continue
fi
# echo -n "taking $image in $name" >> $log
wget -U "" $image
images=`echo $(($images-1))`
# echo "; image count=$images" >> $log
sleep 1
done
}
tmp=`curl http://... 2>/dev/null`
jump="1"
sub=`echo "$tmp" | grep -oE "cat"'[0-9]+'"p1.html"`
for i in "$sub"; do
if [ ! "$jump" = "1" ]; then
stmp=`curl http://... 2>/dev/null`
ssub=`echo "$stmp" | grep -oE "cat"'[0-9]+'"p1.html"`
jump="0"
fi
if [ "$last" = "$i" ]; then
continue
fi
# echo -e "$name\n$sub\n" >> debug
name=`echo "$tmp" | grep '<title>' | sed 's/<title>//' | sed 's/<\/title.//' | sed 's/Aeris\ Dies:lB:://'`
if [ ! -d "$name" ]; then
mkdir "$name"
fi
cd "$name"
# echo "name: $name; images: $images;"
fetch_img "$i" "$tmp"
if [ -n "$ssub" ]; then
for f in "$ssub"; do
stmp=`curl http://... 2>/dev/null`
name=`echo "$stmp" | grep '<title>' | sed 's/<title>//' | sed 's/<\/title.//' | sed 's/Aeris\ Dies:lB:://'`
if [ ! -d "$name" ]; then
mkdir "$name"
fi
cd "$name"
fetch_img "$f" "$stmp"
cd ..
done
fi
cd ..
last="$i"
done