-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscrap_subreddit.sh
More file actions
25 lines (19 loc) · 794 Bytes
/
Copy pathscrap_subreddit.sh
File metadata and controls
25 lines (19 loc) · 794 Bytes
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
#!/bin/bash
# By Nicola Malizia https://unnikked.ga under MIT License
USER_AGENT="User-Agent: cli:bash:v0.0.0 (by /u/codesharer)"
if [ $# -ne 1 ]; then
echo "USE: $0 subreddit"
exit 1
fi
# Get the first page
DATA="$(curl -s -H $USER_AGENT https://www.reddit.com/r/$1/.json)"
AFTER="$(echo "$DATA" | jq '.data.after')"
# Parallel download all the links
echo "$DATA" | jq '.data.children[].data.url' | xargs -P 0 -n 1 -I {} bash -c 'curl -s -O {}'
# Iterate over listing and get all links
while [[ $AFTER != "null" ]]; do
DATA="$(curl -s -H $USER_AGENT https://www.reddit.com/r/$1/.json?after=${AFTER:1:-1})"
# Parallel download all the links
echo "$DATA" | jq '.data.children[].data.url' | xargs -P 0 -n 1 -I {} bash -c 'curl -s -O {}'
AFTER="$(echo "$DATA" | jq '.data.after')"
done