From e2c4cb11eadb3a1b6bbd834c315860605ddaadec Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Tue, 3 Nov 2015 13:56:58 +0100 Subject: [PATCH] Enabled download and alloed arbitrary destination folder for the downloads --- .gitignore | 2 ++ run.sh | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..446c36c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cookies +downloads \ No newline at end of file diff --git a/run.sh b/run.sh index e1e370d..ea4e4ba 100755 --- a/run.sh +++ b/run.sh @@ -4,19 +4,30 @@ 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 free.html | grep -o 'href="[^"]*' | grep -o '/free.*') +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 +curl -b cookies -c cookies https://www.packtpub.com$url + +opwd=$(pwd) +if [ $# -eq 1 ]; then + mkdir -p "$1" + cd "$1" +else + mkdir downloads + cd downloads +fi echo 'Downloading books' id=$(echo $url | grep -o '/[0-9/]*/' | grep -o '[0-9]*') #curl -b cookies -c cookies -J -O https://www.packtpub.com/ebook_download/$id/pdf #curl -b cookies -c cookies -J -O https://www.packtpub.com/ebook_download/$id/epub -out=$(curl -b cookies -c cookies -J -O -O https://www.packtpub.com/ebook_download/$id/pdf https://www.packtpub.com/ebook_download/$id/epub 2>&1 ) +out=$(curl -b "$opwd/cookies" -c "$opwd/cookies" -J -O -O https://www.packtpub.com/ebook_download/$id/pdf https://www.packtpub.com/ebook_download/$id/epub 2>&1 ) ret=$? +cd "$opwd" + echo 'Logging off' curl -b cookies -c cookies -s https://www.packtpub.com/logout > /dev/null