downloader.sh 872 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # TODO: Scripts stops working after some time( long one) and needs restart, Fix this.
  4. # Automatifally downloads files in clipboard
  5. memes="${HOME}/Documents/memes"
  6. misc="${HOME}/Downloads/misc"
  7. mkdir -p "$memes" "$misc"
  8. # sep="/"
  9. delay='3s'
  10. while :; do
  11. url=$(xclip -selection clipboard -o)
  12. [[ $url == $old || $url != 'http'* ]] && sleep "$delay" && continue
  13. case "$url" in
  14. *.4cdn.org*[0-9].*) dir="$memes" ;;
  15. *.png | *.jpg | *.jpeg | *.gif | *.webm | *.mp4 | *.pdf | *.zip | *.7z | *.tar* | *.rar) dir="$misc" ;;
  16. *) sleep "$delay" && continue ;;
  17. esac
  18. # aria2c --allow-overwrite -d "$dir" "$url"
  19. $(detach.sh) \
  20. wget -nc -P "$dir" "$url" && \
  21. recent="${dir}/${url##*/}" && \
  22. notify-send -i "$recent" "Saving as ${recent}"
  23. old="$url"
  24. done