-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4chanDownload
executable file
·50 lines (37 loc) · 1.29 KB
/
4chanDownload
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
#!/bin/bash
## -------------------------------------------------------------------
## 4CHAN image downloader 1.0.0
##
## This is free software: you are free to change and redistribute it.
## There is NO WARRANTY, to the extent permitted by law.
## -------------------------------------------------------------------
### Downloads all pictures in a 4CHAN thread.
### Usage: 4chanDownload [options] <url>
###
### -h, --help Show help options.
### -v, --version Print program version.
help=$(grep "^### " "$0" | cut -c 5-)
version=$(grep "^## " "$0" | cut -c 4-)
eval "$(docopts -A args -h "$help" -V "$version" : "$@")"
. $(dirname $0)/scriptsConfig
LOC=$(echo "${args[<url>]}" | egrep -o '\/thread\/[0-9]+' | egrep -o '[0-9]+' )
echo "Downloading to $CHANPICTUREDIR/$LOC"
if [ ! -d $CHANPICTUREDIR/$LOC ]; then
mkdir -p $CHANPICTUREDIR/$LOC
fi
cd $CHANPICTUREDIR/$LOC
while [ "1" = "1" ]; do
TMP=`mktemp`
TMP2=`mktemp`
wget -O "$TMP" "${args[<url>]}"
if [ "$?" != "0" ]; then
rm $TMP $TMP2
exit 1
fi
egrep '//i\.4cdn\.org/[a-zA-Z0-9]+/[0-9A-Za-z]+\.(jpg|png|gif|webm)' "$TMP" -o > "$TMP2"
cat "$TMP2" | sed 's/\/\//http:\/\//g' > "$TMP"
wget -nc -i $TMP
rm $TMP $TMP2
echo "Waiting 15 seconds before next run"
sleep 15
done;