-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdlspwalls
95 lines (75 loc) · 2.6 KB
/
dlspwalls
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
#----------------------------------------------------------------------------------
# Project Name - miscellaneous/dlspwalls
# Started On - Sun 15 Oct 20:48:22 BST 2017
# Last Change - Tue 3 Apr 12:51:06 BST 2018
# Author E-Mail - [email protected]
# Author GitHub - https://github.com/terminalforlife
#----------------------------------------------------------------------------------
_VERSION_="2018-04-03"
XERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; exit 1; }
ERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; }
USAGE(){
while read -r; do
printf "%s\n" "$REPLY"
done <<-EOF
DLSPWALLS ($_VERSION_)
Written by terminalforlife ([email protected])
Download a collection of steampunk wallpapers.
SYNTAX: dlspwalls [OPTS]
OPTS: --help|-h|-? - Displays this help information.
--version|-v - Output only the version datestamp.
--quiet|-q - Runs in quiet mode. Errors still output.
--debug|-D - Enables the built-in bash debugging.
NOTE: Files will be download to the current directory, as JPGs.
SITE: https://wallpapercave.com
EOF
}
while [ "$1" ]; do
case "$1" in
--help|-h|-\?)
USAGE; exit 0 ;;
--version|-v)
printf "%s\n" "$_VERSION_"
exit 0 ;;
--quiet|-q)
BEQUIET="true" ;;
--debug|-D)
DEBUGME="true" ;;
*)
XERR "$LINENO" "Incorrect argument(s) specified." ;;
esac
shift
done
[ -x /usr/bin/wget ] || ERR "$LINENO" "Dependency '/usr/bin/wget' not met."
read -a WGET_VER_LINE <<< "$(/usr/bin/wget --version)"
WGET_VERSION=0${WGET_VER_LINE[2]//[!0-9]}
if [ $WGET_VERSION -ge 01192 -a $WGET_VERSION -lt 01194 ]; then
NOWARC="--no-warc-compression"
fi
[ "$BEQUIET" == "true" ] && exec 1> /dev/null
[ "$DEBUGME" == "true" ] && set -x
URL="https://wallpapercave.com/download/steampunk-wallpaper"
HTML=`/usr/bin/wget -q $NOWARC "${URL%/down*}/steampunk-wallpaper-1920x1080" -O -`
GETID=()
while read -a Y; do
for FIELD in ${Y[@]/src=\"\/wp}; {
[ "$FIELD" == "$OLD" ] && continue
if [[ "$FIELD" == /* ]]; then
if [[ "$FIELD" =~ [0-9A-Za-z]+.jpg ]]; then
GETID+=("${FIELD%.jpg\"}")
fi
else
continue
fi
OLD="$FIELD"
}
done <<< "$HTML"
declare -i N=0
for ID in ${GETID[@]//\/}; {
N+=1
printf "%s\n" "DOWNLOADING: steampunk-wallpaper-1920x1080-${ID}.jpg"
printf -v FNAME "./steampunk-wallpaper-1920x1080-%0.2d.jpg" "${N}"
/usr/bin/wget -qc $NOWARC "${URL}-1920x1080-${ID}" -O "$FNAME"
}
# vim: ft=sh noexpandtab colorcolumn=84 tabstop=8 noswapfile nobackup