-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimgur.sh
executable file
·67 lines (56 loc) · 1.31 KB
/
imgur.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
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#############################################################
# Script to download all images in an imgur.com album
# to disk.
# USAGE: ./imgur.sh http://imgur.com/a/id
#
#############################################################
url=('')
ass=".tmp"
usage(){
echo "USAGE: ./imgur.sh http://imgur.com/a/id"
}
url=$1
if [[ -z $url ]]
then
usage
exit 1
fi
if [[ "$url" =~ "imgur.com/a/" ]]
then
curl -s $url > $ass
title=$(awk -F \" '/data-cover/ {print $6; exit}' $ass)
if [[ -z $title ]]
then
title=$(awk -F \" '/data-cover/ {print $8}' $ass)
fi
title=${title// /_}
dir="${title//[^a-zA-Z0-9_]/}"
if [[ -d $dir ]]
then
echo "Directory exists, you may have downloaded this album before."
exit 1
else
if [[ -z $dir ]]
then
echo "Empty album most likely, using a random integer name"
dir=$((RANDOM))
fi
echo "Saving to $dir/"
mkdir -p $dir
fi
for image in $(awk -F \" '/data-src/ {print $10}' $ass | sed /^$/d | sed s/s.jpg/.jpg/)
do
filename=$(sed s/http:\\/\\/i.imgur.com\\/// <<< $image)
curl -# $image > "$dir/$filename"
ftype=$(file "$dir/$filename" | grep PNG | wc -l)
if [[ $ftype == 1 ]]
then
mv "$dir/$filename" "$dir/${filename//.jpg/.png}"
fi
done
fi
echo "Removing tmp"
rm $ass
echo "Done"
#exit 0