Skip to content

Instantly share code, notes, and snippets.

@denpatin
Last active January 19, 2016 03:58
Show Gist options
  • Save denpatin/a2a80071eb96755fc07d to your computer and use it in GitHub Desktop.
Save denpatin/a2a80071eb96755fc07d to your computer and use it in GitHub Desktop.
Script for downloading free books from Springer
#!/bin/bash
#
# Usage:
# $ springer.sh
# will save all books
#
# $ springer.sh word
# will save all books whose titles or authors match "word"
# Link with books and links
springer="https://gist.githubusercontent.com/bishboria/8326b17bbd652f34566a/raw/0594f99c580c3befb924f3d36ab187c2da8f441b/springer-free-maths-books.md"
# Processing the argument
param=""
if [ ! -z "$1" ]
then
export param="$1"
fi
while read -r book
do
# Parsing markdown
link=$(echo "$book" | awk -F'[][()]' '{print $4}')
# Contains title and author
naming=$(echo "$book" | awk -F'[][()]' '{print $2}')
author=$(echo "$naming" | awk -F, '{print $NF}' | sed 's/^ //g')
title=$(echo "$naming" | sed "s/$author$//" | rev | cut -c 3- | rev | sed 's/[:*"]//g')
file="$title ($author).pdf"
# If a file exists (that is, either the newest edition is already downloaded, or the script
# is being run once again), then skip the book cuz we need neither older version nor duplicate
if [ -f "$file" ]; then continue; fi
# Downloading the file with a new name
wget -O "$file" "$link" -q --show-progress -o /dev/null
# Get only lines that contain links, and output them in a reversed order
done < <(curl "$springer" | sed '/^[^[]*$/d' | sed '1!G;h;$!d' | grep -i "$param")
@FrankCreen
Copy link

It works! Thank you!

@walkingpendulum
Copy link

+1, thx!

@immartian
Copy link

why it reports such error?
wget: unrecognized option '--show-progress'

@denpatin
Copy link
Author

denpatin commented Jan 9, 2016

@isaacmao
This option works for wget starting from version 1.16. Just update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment