aboutsummaryrefslogtreecommitdiff
path: root/scripts/.local/bin/personal/hdqwd
blob: 0d7f709248fcc81cbe4f3c3a1606f9b416106845 (plain)
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
#!/bin/bash

# A utility to download all images from a specific website give the exact url

# https://hdqwalls.com/2880x1800/anime-girl-wallpapers/page/2
# https://hdqwalls.com/search?q=Genshin+Impact&page=2

FILE="/tmp/wallpaperhtml"

download() {
  curl -s "$1" > "$FILE"

  IMAGES=$(cat "$FILE" | pup img.thumbnail |  grep -o '"http[^"]\+"' | sed 's/\/wallpapers\/thumb/\/download/g' | sed 's/.jpg"$/-2560x1600.jpg/g' | sed 's/"//g')
  COUNTER=0

  for IMG in $IMAGES; do
    let COUNTER++
    NAME="$(basename $IMG)"

    echo "[ Download ] ($COUNTER) $NAME" 
    curl -s "$IMG" > "$NAME"
    sleep 2
  done

  echo -e "\nFinished!"
}

if [[ -z "$1" ]]; then
  echo "[ Error ] Please provide a URL"
  exit 1
fi

if [[ "$1" = "s" ]]; then
	IMAGE=$(curl -s "$2" | pup img.d_img_holder |  grep -o '"http[^"]\+"' | sed 's/\/wallpapers\/bthumb/\/download/g' | sed 's/.jpg"$/-2560x1600.jpg/g' | sed 's/"//g')
	NAME="$(date +"%s")"
	curl -s "$IMAGE" > "$NAME.jpg"
else
	download "$1"
fi