Update reddit_downloader.sh
This commit is contained in:
+19
-54
@@ -1,65 +1,30 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Check if username is provided
|
apk add curl wget
|
||||||
if [ -z "$1" ]; then
|
|
||||||
echo "Usage: $0 <reddit_username> <destination_folder>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
USER="$1"
|
#dowload from https://www.pornpics.com/pornstars/eiby-shine/
|
||||||
DEST_FOLDER="${2:-./${USER}_images}"
|
DESTINATION_FOLDER="/data"
|
||||||
USER_AGENT="Mozilla/5.0 (compatible; RedditImageDownloader/1.0)"
|
BASE_URL="https://www.pornpics.com/pornstars/eiby-shine/"
|
||||||
|
pornstars="eiby-shine"
|
||||||
|
|
||||||
mkdir -p "$DEST_FOLDER"
|
#BASE_URL="https://www.pornpics.com/pornstars/chloe-camilla/"
|
||||||
|
#pornstars="chloe-camilla"
|
||||||
|
|
||||||
AFTER=""
|
|
||||||
BASE_URL="https://www.reddit.com/user/$USER/submitted/.json"
|
|
||||||
|
|
||||||
echo "Fetching all image posts from user $USER..."
|
#clear files beforehand
|
||||||
|
echo "" > $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt
|
||||||
|
echo "" > $DESTINATION_FOLDER/$pornstars-image_to_download.txt
|
||||||
|
|
||||||
while true; do
|
mkdir -p $DESTINATION_FOLDER/$pornstars
|
||||||
# Build URL with pagination
|
curl -s $BASE_URL | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep "https://www.pornpics.com/galleries/" |sort -u >> $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt
|
||||||
if [ -z "$AFTER" ]; then
|
|
||||||
URL="${BASE_URL}?limit=100"
|
|
||||||
else
|
|
||||||
URL="${BASE_URL}?limit=100&after=${AFTER}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fetch posts
|
for f in $(cat $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt ); do
|
||||||
RESPONSE=$(curl -s -A "$USER_AGENT" "$URL")
|
curl $f | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep "https://cdni.pornpics.com/" >> $DESTINATION_FOLDER/$pornstars-image_to_download.txt
|
||||||
|
echo $f
|
||||||
# Validate JSON
|
|
||||||
if ! echo "$RESPONSE" | jq empty 2>/dev/null; then
|
|
||||||
echo "Error: Failed to fetch or parse JSON. Exiting."
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Extract image URLs
|
|
||||||
IMAGE_URLS=$(echo "$RESPONSE" | jq -r '.data.children[] | select(.data.url | test("\\.(jpg|jpeg|png|gif)$")) | .data.url')
|
|
||||||
|
|
||||||
# Exit if no more images found
|
|
||||||
if [ -z "$IMAGE_URLS" ]; then
|
|
||||||
echo "No more images found on this page."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Download images
|
|
||||||
echo "$IMAGE_URLS" | while read -r image_url; do
|
|
||||||
[ -z "$image_url" ] && continue
|
|
||||||
FILENAME=$(basename "$image_url")
|
|
||||||
if [ ! -f "$DEST_FOLDER/$FILENAME" ]; then
|
|
||||||
echo "Downloading $FILENAME..."
|
|
||||||
curl -s -A "$USER_AGENT" -o "$DEST_FOLDER/$FILENAME" "$image_url"
|
|
||||||
else
|
|
||||||
echo "Skipping existing file $FILENAME"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Get 'after' token for pagination
|
|
||||||
AFTER=$(echo "$RESPONSE" | jq -r '.data.after')
|
|
||||||
if [ "$AFTER" == "null" ] || [ -z "$AFTER" ]; then
|
|
||||||
echo "Reached end of posts."
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Download complete. Images saved to $DEST_FOLDER"
|
for g in $(cat $DESTINATION_FOLDER/$pornstars-image_to_download.txt ); do
|
||||||
|
wget $g -P $DESTINATION_FOLDER/$pornstars
|
||||||
|
echo $g
|
||||||
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user