Sergey Oboguev (oboguev) wrote,
Sergey Oboguev
oboguev

ГПИБ shpl download script



#!/bin/bash

# load.sh book-url

if [ -z "$1" ]; then
    echo "usage: load.sh book-url"
    exit 1
fi

if [ "$#" -ne 1 ]; then
    echo "usage: load.sh book-url"
    exit 1
fi

URL="$1"

if [ -z `which jq` ]; then
    echo "jq is not installed"
    exit 1
fi

TFR="/tmp/$$.raw-book.shpl"
TF="/tmp/$$.book.shpl"

echo "Loading root page ..."
wget --quiet -O $TFR $URL
if [ "$?" -ne 0 ]; then
    echo "Unable to load the page"
    exit 1
fi

tr '\r\n' '  ' <$TFR >$TF
rm $TFR
awk 'BEGIN { FS = "pages: \\[" } ; { print $2 }' $TF | awk 'BEGIN { FS = "\\]" } ; { print "[ " $1 " ]" }' >pages.shpl
awk 'BEGIN { FS = "maxZoom: " } ; { print $2 }' $TF | awk 'BEGIN { FS = "," } ; { print $1 }' | xargs >maxzoom.shpl

MZ=`cat maxzoom.shpl`

if [ ! -z "${MZ##*[!0-9]*}" ] ; then
    echo "Using zoom $MZ"
else
    echo "Invalid zoom, defaulting to zoom 7"
    MZ="7"
fi

jq '.[] | .id' <pages.shpl >page-ids.shpl
NPAGES=`wc -l <page-ids.shpl`
echo Number of pages: $NPAGES

PAGEIDS=`cat page-ids.shpl`
PAGE=1
for ID in $PAGEIDS ; do
    echo "Loading page $PAGE (of $NPAGES) ..."
    URL="http://elib.shpl.ru/pages/$ID/zooms/$MZ"
    wget --quiet -O $ID.jpg $URL
    if [ "$?" -ne 0 ]; then
        echo "Unable to load the page ($URL)"
        exit 1
    fi
    let PAGE=PAGE+1
done

rm -f $TFR
rm -f $TF
rm *.shpl

echo Finished.

Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 4 comments