Added download path argument
As with the other parameters, it works as long as all the previous ones are provided
This commit is contained in:
parent
f1b7bb1e07
commit
476d11635d
15
rid
15
rid
|
@ -5,9 +5,9 @@
|
||||||
timeout=60
|
timeout=60
|
||||||
|
|
||||||
usage() { printf "%s" "\
|
usage() { printf "%s" "\
|
||||||
Usage: rid SUBREDDIT [hot|new|rising|top|controversial] [number] [all|year|month|week|day]
|
Usage: rid SUBREDDIT [hot|new|rising|top|controversial] [number] [all|year|month|week|day] [path]
|
||||||
Examples: rid starterpacks new 10
|
Examples: rid starterpacks new 10
|
||||||
rid funny top 50 month
|
rid funny top 50 month ~/Pictures/
|
||||||
"; exit 0;
|
"; exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ subreddit=$1
|
||||||
sort=$2
|
sort=$2
|
||||||
number=$3
|
number=$3
|
||||||
top_time=$4
|
top_time=$4
|
||||||
|
path=$5
|
||||||
|
|
||||||
if [ "$1" == "-h" ] || [ -z $subreddit ]; then
|
if [ "$1" == "-h" ] || [ -z $subreddit ]; then
|
||||||
usage
|
usage
|
||||||
|
@ -32,9 +33,15 @@ if [ -z $number ]; then
|
||||||
number=200
|
number=200
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z $path ]; then
|
||||||
|
path=$(pwd)
|
||||||
|
else
|
||||||
|
mkdir -p $path
|
||||||
|
fi
|
||||||
|
|
||||||
url="https://www.reddit.com/r/$subreddit/$sort/.json?raw_json=1&t=$top_time"
|
url="https://www.reddit.com/r/$subreddit/$sort/.json?raw_json=1&t=$top_time"
|
||||||
content=$(wget -T $timeout -q -O - $url)
|
content=$(wget -T $timeout -q -O - $url)
|
||||||
mkdir -p $subreddit
|
mkdir -p $path/$subreddit
|
||||||
i=1
|
i=1
|
||||||
while : ; do
|
while : ; do
|
||||||
urls=$(echo -n "$content" | jq -r '.data.children[]|select(.data.post_hint|test("image")?) | .data.preview.images[0].source.url')
|
urls=$(echo -n "$content" | jq -r '.data.children[]|select(.data.post_hint|test("image")?) | .data.preview.images[0].source.url')
|
||||||
|
@ -48,7 +55,7 @@ while : ; do
|
||||||
ext=$(echo -n "${url##*.}" | cut -d '?' -f 1)
|
ext=$(echo -n "${url##*.}" | cut -d '?' -f 1)
|
||||||
newname="$subreddit"_"$sort""$top_time"_"$(printf "%04d" $i)"_"$name"_$id.$ext
|
newname="$subreddit"_"$sort""$top_time"_"$(printf "%04d" $i)"_"$name"_$id.$ext
|
||||||
printf "$i/$number : $newname\n"
|
printf "$i/$number : $newname\n"
|
||||||
wget -T $timeout --no-check-certificate -nv -nc -P down -O "$subreddit/$newname" $url &>/dev/null &
|
wget -T $timeout --no-check-certificate -nv -nc -O "$path/$subreddit/$newname" $url &>/dev/null &
|
||||||
((a=a+1))
|
((a=a+1))
|
||||||
((i=i+1))
|
((i=i+1))
|
||||||
if [ $i -gt $number ] ; then
|
if [ $i -gt $number ] ; then
|
||||||
|
|
Loading…
Reference in New Issue