-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwl.sh
56 lines (47 loc) · 1.75 KB
/
dwl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
# dwl.sh
# Copyright (c) 2020 Nils Stratmann <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# according to https://insanity.industries/post/safeshell/
set -e
set -u
set -E
export SHELLOPTS
# maybe reuse this script some other time?
URL1='https://link.springer.com/search/page/'
URL2='?facet-content-type=%22Book%22&package=mat-covid19_textbooks&facet-language=%22En%22&sortOrder=newestFirst&showAll=true'
URL_BASE='https://link.springer.com'
DEST="$(pwd)/springer-books"
# make working dir
mkdir -p "$DEST"
cd "$DEST"
# download list of links to book-pages
for i in {1..21}; do
curl "${URL1}${i}${URL2}" | grep 'class="title"' | awk -F'href="' '{print $2}' | awk -F'" title="' '{print $1}' >> books.txt
done
# get list of download locations
while IFS= read -r line
do
curl "${URL_BASE}${line}" | grep 'class="c-button' | awk -F'href="' '{print $2}' | awk -F'" title=' '{print $1}' | awk -F'" target="' '{print $1}' | sort | uniq >> dwl.txt
done < books.txt
# actual download
while IFS= read -r line
do
filename=$(basename $line)
# curl -o "$filename" "${URL_BASE}${line}"
echo $line
done < dwl.txt
rm books.txt dwl.txt