not working yet

This commit is contained in:
pierre geeraert
2025-04-03 23:11:50 +01:00
parent 4351a7c0a4
commit f71062147f
2 changed files with 52 additions and 0 deletions
+5
View File
@@ -1,2 +1,7 @@
# Stash # Stash
usage :
./reddit_downloader.sh Countem1a
+47
View File
@@ -0,0 +1,47 @@
#!/bin/bash
# Check if user has provided a Reddit username
if [ -z "$1" ]; then
echo "Usage: $0 <reddit-username>"
exit 1
fi
USERNAME=$1
USER_AGENT="reddit-image-downloader"
OUTPUT_DIR="${USERNAME}_images"
# Create a directory to save images
mkdir -p "$OUTPUT_DIR"
# Reddit API URL to fetch user submissions
REDDIT_API_URL="https://www.reddit.com/user/$USERNAME/submitted.json?limit=100"
# Function to download images
download_images() {
echo "Fetching images from user: $USERNAME"
# Loop through pages of user submissions (pagination handled)
while :; do
# Fetch data from Reddit
JSON=$(curl -s -A "$USER_AGENT" "$REDDIT_API_URL")
# Get image URLs from the media_metadata field (looking for 's' key for highest quality image)
IMAGE_URLS=$(echo "$JSON" | jq -r '.data.children[] | select(.data.media_metadata != null) | .data.media_metadata | to_entries[] | .value.s.u')
# Check if we found any image URLs
if [ -z "$IMAGE_URLS" ]; then
echo "No more images found."
break
fi
# Download each image URL
for IMAGE_URL in $IMAGE_URLS; do
echo "Downloading $IMAGE_URL..."
wget -q -P "$OUTPUT_DIR" "$IMAGE_URL"
done
# Check if there's a next page of submissions
NEXT_PAGE=$(echo "$JSON" | jq -r '.data.after')
# if [ "$NEXT_PAGE" != "null" ]; then
# REDDIT_API_URL="https://www.reddit.com/user/$USERNAME/submitted.json?limit=
done