Skip to content

Instantly share code, notes, and snippets.

@MarcosBL
Created December 27, 2013 17:52
Show Gist options
  • Save MarcosBL/8150348 to your computer and use it in GitHub Desktop.
Save MarcosBL/8150348 to your computer and use it in GitHub Desktop.
Download contents from ISSUU in PDF format
TMP_DIR="/tmp/issud/"
TMP_FILE="issuufile"
KONT=1
I_MAGICK=0
TITLE=""
if [ -z "$1" ]; then
echo "Script para descargar documentos de ISSUU"
echo "Usage: `basename $0` URL"
echo ""
exit 1
fi
if [ -z `which convert` ]; then
echo ""
echo "No esta disponible el comando convert."
echo "El script puede continuar su ejecucion"
echo "pero no se creara el PDF."
read -p "Continuar? (s/n)" RESPUESTA
if [ "$RESPUESTA" = "s" ]; then
I_MAGICK=1
else
exit 1
fi
fi
[ -e $TMP_DIR ] || mkdir $TMP_DIR
wget -q --output-document=$TMP_DIR$TMP_FILE $1
DOCID=`grep -m 1 documentId $TMP_DIR$TMP_FILE | sed -e 's/.*documentId=//g' | sed -e 's/">//g' | sed -e 's/ //g'`
TITLE=`grep "<title>" $TMP_DIR$TMP_FILE | sed -e 's/.*<title>//g' | sed -e 's/<\/title>//g' | sed -e 's/ //g'`
while [ 1 ]; do
let "FILENAME=$KONT+10000"
sleep 5
wget -t 18 --wait=7 --random-wait --output-document=$TMP_DIR$FILENAME.jpg http://image.issuu.com/$DOCID/jpg/page_$KONT.jpg
if [ ! `file -b --mime-type $TMP_DIR$FILENAME.jpg` = "image/jpeg" ]; then
rm -f $TMP_DIR$FILENAME.jpg
let "KONT=$KONT-1"
break
fi
let "KONT=$KONT+1"
done
if [ "$KONT" = 0 ]; then
echo "No he podido descargar ningun fichero de imagen."
echo "Verifica la URL que has introducido."
exit 1
fi
echo ""
echo "Resumen:"
echo " Descargados $KONT ficheros de imagen."
if [ $I_MAGICK ]; then
convert $TMP_DIR*.jpg $TITLE.pdf
echo " Creado el fichero: $TITLE.pdf"
rm -rf $TMP_DIR
else
rm -f $TMP_DIR$TMP_FILE
mv $TMP_DIR ./$TITLE
echo " Creado el directorio $TITLE con los ficheros de imagen"
fi
echo " Done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment