2014-06-07 06:06:23 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#cfg
|
|
|
|
useragent="Love by u/gadelat"
|
|
|
|
|
|
|
|
subreddit=$1
|
2019-01-05 08:20:21 -05:00
|
|
|
url="https://www.reddit.com/r/$subreddit/.json?raw_json=1"
|
2018-04-07 11:08:31 -04:00
|
|
|
content=`wget -U "$useragent" -q -O - $url`
|
2019-01-24 09:35:32 -05:00
|
|
|
mkdir -p $subreddit
|
2014-06-07 06:06:23 -04:00
|
|
|
while : ; do
|
2019-03-28 05:01:45 -04:00
|
|
|
urls=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")) | .data.preview.images[0].source.url')
|
|
|
|
names=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")) | .data.title')
|
|
|
|
ids=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")) | .data.id')
|
2014-06-07 06:06:23 -04:00
|
|
|
a=1
|
2019-02-17 11:55:07 -05:00
|
|
|
wait # prevent spawning too many processes
|
|
|
|
for url in $urls; do
|
2019-03-28 05:01:45 -04:00
|
|
|
name=`echo -n "$names"|sed -n "$a"p`
|
|
|
|
id=`echo -n "$ids"|sed -n "$a"p`
|
|
|
|
ext=`echo -n "${url##*.}"|cut -d '?' -f 1`
|
2019-02-17 11:55:07 -05:00
|
|
|
newname="$name"_"$subreddit"_$id.$ext
|
|
|
|
echo $name
|
|
|
|
wget -U "$useragent" --no-check-certificate -nv -nc -P down -O "$subreddit/$newname" $url &>/dev/null &
|
2014-06-07 06:06:23 -04:00
|
|
|
a=$(($a+1))
|
|
|
|
done
|
2019-03-28 05:01:45 -04:00
|
|
|
after=$(echo -n "$content"| jq -r '.data.after')
|
2014-06-07 06:06:23 -04:00
|
|
|
if [ -z $after ]; then
|
|
|
|
break
|
|
|
|
fi
|
2019-01-05 08:20:21 -05:00
|
|
|
url="https://www.reddit.com/r/$subreddit/.json?count=200&after=$after&raw_json=1"
|
2014-06-07 06:06:23 -04:00
|
|
|
content=`wget -U "$useragent" --no-check-certificate -q -O - $url`
|
|
|
|
#echo -e "$urls"
|
2018-04-07 11:08:31 -04:00
|
|
|
done
|