Changed due to reCaptcha implementation on website to manual downloading

This commit is contained in:
Christian Wolf 2017-06-08 14:37:02 +02:00
parent 97d5c5185a
commit 4e51d06a1a

41
run.sh
View File

@ -1,43 +1,16 @@
#!/bin/sh #!/bin/sh
echo 'Logging in' #set -x
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' #echo 'Logging in'
url=$(curl -b cookies -c cookies -s https://www.packtpub.com/packt/offers/free-learning | grep freelearning-claim | grep -o 'href="[^"]*' | grep -o '/free.*') formid=$(curl -b cookies -c cookies -s https://www.packtpub.com/ | grep 'form_build_id' | head -n 1 | grep -Eo 'value="[^"]*"' | sed -E 's@value="(.*)"@\1@')
echo 'Claiming free book' curl -b cookies -c cookies -s -F 'email=ChristianLupus@web.de' -F 'form_id=packt_user_login_form' -F 'password=naitsirhc' -F 'op=Login' -F "form_build_id=$formid" https://www.packtpub.com/ > /dev/null
curl -b cookies -c cookies https://www.packtpub.com$url
opwd=$(pwd) #echo 'Obtaining free book information'
if [ $# -eq 1 ]; then title=$(curl -b cookies -c cookies -s https://www.packtpub.com/packt/offers/free-learning | awk '/<h2>/,/<\/h2>/' | tr -d '\n\r\t' | grep -Po '<h2>.*?</h2>' | head -n 1 | sed 's@<h2>\(.*\)</h2>@\1@')
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=$? echo "The packt book today is \"$title\". You can find it under https://www.packtpub.com/packt/offers/free-learning."
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