Melnikoff.org

 

Scripts

Rajče downloader

Downloads albums from rajce.idnes.cz.

Usage:
./script.sh album_url_address
or:
./script.sh album_url_address username password
Example:
./script.sh http://test.rajce.idnes.cz/test_album

Can handle password protected album too.

#!/bin/bash

URL=$1
USER=$2
PASS=$3
if [ -z "$URL" ]; then
        echo "Usage:"
	echo "$0 http://rajce_album_url"
	echo "$0 http://rajce_album_url username password"
        exit
fi

echo "Downloading album from $URL"
if [ -n "$USER" -a -n "$PASS" ]; then
        PAGE=`wget -qO- --post-data "login=$USER&password=$PASS" $URL`
else
        PAGE=`wget -qO- $URL`
fi

if [ $? -ne 0 ]; then
        echo "Cannot get given album, please check URL and connection."
        exit
fi

ALBUM_NAME=`echo "$PAGE" | grep albumName | sed 's/^.*albumName">\([^<]*\).*/\1/'`
FILES=`echo "$PAGE" | grep photoID | sed 's/^.*fileName: "\([^"]*\).*/\1/'`
FILES_COUNT=`echo "$FILES" | wc -l`
STORAGE=`echo "$PAGE" | grep storage | sed 's/^.*storage = "\([^"]*\).*/\1/'`
if [ -z "$ALBUM_NAME" -o -z "$FILES" -o -z "$STORAGE" ]; then
        echo "Error: cannot find album, please check URL."
        exit
fi
echo "Found album: $ALBUM_NAME"
echo "Pictures count: $FILES_COUNT"

mkdir "$ALBUM_NAME"
if [ $? -ne 0 ]; then
        echo "Cannot create album folder, please check your rights and \
possibility, that album already exists."
        exit
fi

pushd "$ALBUM_NAME"
for FILE in $(echo "$FILES")
do
        echo Downloading "${STORAGE}images/${FILE}"
        wget ${STORAGE}images/${FILE}
done
popd