/
imgboxdwl
executable file
·84 lines (58 loc) · 1.71 KB
/
imgboxdwl
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
#!/usr/bin/env bash
#
# easily download all images from an imgbox gallery
#
function help {
local script_name=$0
printf "\\nUsage: %s imgbox_gallery_url\\n" "${script_name}"
printf "\\nEasily download all images from an imgbox gallery\\n\\n"
}
function check_requirements {
declare -a requirements=("curl")
for requirement in "${requirements[@]}"; do
if ! command -v "${requirement}" &> /dev/null; then
printf "\\nError: '%s' is a requirement and wasn't found in this system.\\n\\n" "${requirement}"
exit 1
fi
done
}
function extract_name {
local url="$1"
temp=${url##*/}
echo ${temp%%_*}
}
function number_of_images_in_the_gallery {
local url="$1"
curl -s "${url}" | grep -o -E "[0-9]+ image" | cut -f1 -d" "
}
function is_imgbox_gallery_url {
local url="$1"
if [[ "${url}" =~ https?://imgbox.com/g/ ]]; then
true
else
false
fi
}
check_requirements
if [[ $# -ne 1 ]]; then
help
exit 1
fi
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
help
exit 0
fi
gallery_url="$1"
if ! is_imgbox_gallery_url "${gallery_url}"; then
printf "\\nError: The inputed url doesn't appear to be a proper imgbox gallery url\\n\\n"
exit 1
fi
gallery_name=$(extract_name "${gallery_url}")
mkdir -p "${gallery_name}" && cd "${gallery_name}"
printf "\\n\\nAbout to save %d images to folder %s/\\n\\n" $(number_of_images_in_the_gallery "${gallery_url}") "${gallery_name}"
for url in $(curl -s "${gallery_url}" | grep -E -o 'thumbs[0-9]+.*"' | tr -d '"'); do
printf -v link "https://imgbox.com/%s" $(extract_name "${url}")
temp=$(curl -s "${link}" | grep -E -o 'https?.*download=true')
curl -O -# ${temp%%\?*}
done
printf "\\n\\n%s images were saved to folder %s/\\n\\n" $(find . -type f | wc -l) "${gallery_name}"