Advertisement
Guest User

earthporn.sh

a guest
Aug 19th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Download images from reddit.com/r/earthporn
  4. # Needs "jq" and "wget" to run correctly
  5. # wget can be replaced with curl too
  6.  
  7. # Size limit of 2MB
  8. # Use size as a proxy for resolution
  9. SIZELIMIT=$((2*1024*1024))
  10.  
  11. # Destination folder
  12. WPDIR=~/Pictures/Wallpapers
  13. [ -d $WPDIR ] || mkdir -p $WPDIR
  14. cd $WPDIR
  15.  
  16. for type in hot new top; do
  17.     curl -s \
  18.       -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:69.0) Gecko/20100101 Firefox/69.0' \
  19.       https://www.reddit.com/r/earthporn/${type}.json?limit=100 | \
  20.     /usr/local/bin/jq '.data.children[].data.url' | \
  21.     tr -d '"' | \
  22.     grep jpg | \
  23.     while read url; do
  24.       /usr/local/bin/wget -q -c $url
  25.     done
  26. done
  27.  
  28. # Delete if smaller than $SIZELIMIT bytes
  29. find . -type f -name '*jpg' | while read i; do
  30.   if [ ! -s "$i" ]; then
  31.     rm -f -- "$i"
  32.     continue
  33.   fi
  34.   size=$(wc -c < "$i")
  35.   if [ "$size" -lt $SIZELIMIT ]; then
  36.     rm -f -- "$i"
  37.     continue
  38.   fi
  39. done
  40.  
  41. # Only keep the latest 1000 images
  42. # ls -1t | tail +1001 | xargs rm -f
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement