torrent-add.sh 746 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. magnet2torrent(){
  4. notify-send "Started aria2c" "$1"
  5. aria2c -d "${HOME}/Downloads/" --bt-metadata-only=true --bt-save-metadata=true "$1"
  6. }
  7. hostname="192.168.0.72"
  8. add_torrent(){
  9. # # NOT WORKS (IT WORKED FOR RTORRENT)
  10. # [[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
  11. # echo "d10:magnet-uri${#1}:${1}e" >
  12. # "${HOME}/Downloads/meta-${BASH_REMATCH[1]}.torrent"
  13. if ping -c3 -w5 "$hostname"; then
  14. transmission-remote "$hostname" -a "$1"
  15. else
  16. hostname="aria2c"
  17. aria2c --daemon "$1"
  18. fi
  19. }
  20. notification(){
  21. notify-send "Torrent added to ${hostname}" "$torrent"
  22. }
  23. for torrent in "$@"; do
  24. add_torrent "$torrent" && notification
  25. done