packt-loader/run.sh

44 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
echo 'Loggin in'
curl -b cookies -c cookies -s -F 'email=ChristianLupus@web.de' -F 'form_id=packt_user_login_form' -F 'password=naitsirhc' -F 'op=Login' https://www.packtpub.com/ > /dev/null
echo 'Obtaining free book information'
url=$(curl -b cookies -c cookies -s https://www.packtpub.com/packt/offers/free-learning | grep freelearning-claim | grep -o 'href="[^"]*' | grep -o '/free.*')
echo 'Claiming free book'
curl -b cookies -c cookies https://www.packtpub.com$url
opwd=$(pwd)
if [ $# -eq 1 ]; then
mkdir -p "$1"
cd "$1"
else
mkdir -p downloads
cd downloads
fi
echo 'Downloading books'
id=$(echo $url | grep -o '/[0-9/]*/' | grep -o '[0-9]*')
name=$(curl -b "$opwd/cookies" -c "$opwd/cookies" -sI https://www.packtpub.com/ebook_download/$id/pdf | grep 'Location' | grep -Eo 'https?://[^?]*' | sed 's@.*/@@' | sed 's@\.pdf@@i' )
echo $name
out=$(curl -b "$opwd/cookies" -c "$opwd/cookies" -L https://www.packtpub.com/ebook_download/$id/pdf https://www.packtpub.com/ebook_download/$id/epub -o "$name.pdf" -o "$name.epub" 2>&1 )
ret=$?
cd "$opwd"
echo 'Logging off'
curl -b cookies -c cookies -s https://www.packtpub.com/logout > /dev/null
if [ $ret -ne 0 ]; then
if [ $ret -eq 23 ]; then
echo Could not write file to file system:
fi
echo -e "$out"
fi