Added sort and time range option
This commit is contained in:
parent
deddc564d7
commit
0046879d08
|
@ -7,7 +7,7 @@ Tired of all of those reddit downloaders which want you to install tons of depen
|
|||
- Linux/MacOS/Windows
|
||||
- Parallel download
|
||||
|
||||
This script just downloads all directly linked images in subreddit. For more complex usage, use other reddit image downloader.
|
||||
This script just downloads all directly linked images in subreddit. It can also download with a specific sort. For more complex usage, use other reddit image downloader.
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
@ -17,6 +17,10 @@ Requirements
|
|||
|
||||
Usage
|
||||
=====
|
||||
`./download-subreddit-images.sh <subreddit_name>`
|
||||
```
|
||||
./download-subreddit-images.sh <subreddit_name>
|
||||
./download-subreddit-images.sh <subreddit_name> <hot|new|rising|top>
|
||||
./download-subreddit-images.sh <subreddit_name> top <all|year|month|week|day>
|
||||
```
|
||||
|
||||
Script downloads images to `<subreddit_name>` folder in current directory. If you want to change that, you need to edit destination in rdit.sh for now.
|
||||
|
|
|
@ -5,7 +5,18 @@ useragent="Love by u/gadelat"
|
|||
timeout=60
|
||||
|
||||
subreddit=$1
|
||||
url="https://www.reddit.com/r/$subreddit/.json?raw_json=1"
|
||||
sort=$2
|
||||
top_time=$3
|
||||
|
||||
if [ -z $sort ]; then
|
||||
sort="hot"
|
||||
fi
|
||||
|
||||
if [ -z $top_time ];then
|
||||
top_time=""
|
||||
fi
|
||||
|
||||
url="https://www.reddit.com/r/$subreddit/$sort/.json?raw_json=1&t=$top_time"
|
||||
content=`wget -T $timeout -U "$useragent" -q -O - $url`
|
||||
mkdir -p $subreddit
|
||||
while : ; do
|
||||
|
@ -23,11 +34,10 @@ while : ; do
|
|||
wget -T $timeout -U "$useragent" --no-check-certificate -nv -nc -P down -O "$subreddit/$newname" $url &>/dev/null &
|
||||
a=$(($a+1))
|
||||
done
|
||||
after=$(echo -n "$content"| jq -r '.data.after')
|
||||
after=$(echo -n "$content"| jq -r '.data.after//empty')
|
||||
if [ -z $after ]; then
|
||||
break
|
||||
fi
|
||||
url="https://www.reddit.com/r/$subreddit/.json?count=200&after=$after&raw_json=1"
|
||||
url="https://www.reddit.com/r/$subreddit/$sort/.json?count=200&after=$after&raw_json=1&t=$top_time"
|
||||
content=`wget -T $timeout -U "$useragent" --no-check-certificate -q -O - $url`
|
||||
#echo -e "$urls"
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue