4chan-scrap.sh 716 B

1234567891011121314151617181920
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. url="$1"
  4. tag=$(echo "$url" | awk -F "/" '{print $(NF-1)}')
  5. dir="/tmp/thread${tag}"
  6. [[ ! -d $dir ]] && mkdir "$dir"
  7. wget -O "/tmp/temp.html" "$url" >/dev/null 2>/dev/null
  8. posts=$(grep -o '"//\(is2.4chan.org\|i.4cdn.org\)[^" ]\+[^s].\(jpg\|png\|jpeg\|gif\)"' /tmp/temp.html | sed 's|"||g' | sed "s|^|https:|g")
  9. declare -A s
  10. for post in $posts; do
  11. post_num=$(echo "$post" | grep -o "[0-9]\+\.")
  12. [[ ${s[$post_num]} ]] && continue
  13. s[$post_num]=1
  14. wget -nc -P "$dir" "$post" >/dev/null 2>/dev/null &
  15. done
  16. wait
  17. chosenimages=$(sxiv -to "$dir" 2>/dev/null)
  18. [[ -n $chosenimages ]] && cp "$chosenimages" "$(find "${HOME}/Documents/memes" -type d | fzf)"