my dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

45 lines
859 B

  1. #!/usr/bin/env bash
  2. if [[ $# -ne 3 ]]; then
  3. echo "please provide <server> <download_dir> <link>" >&2
  4. exit 1
  5. fi
  6. server="$1"
  7. download_dir="$2"
  8. link="$3"
  9. notify_file="$(mktemp)"
  10. username="$(secret transmission_"${server}"_username)"
  11. password="$(secret transmission_"${server}"_password)"
  12. url="$(secret transmission_"${server}"_rpc_url)"
  13. notify() {
  14. notify-send.sh --replace-file "$notify_file" "$@"
  15. }
  16. request() {
  17. curl --silent --anyauth --user "$username:$password" "$url" "$@"
  18. }
  19. get_key() {
  20. grep -Po "X-Transmission-Session-Id\: \w+"
  21. }
  22. notify "adding torrent" "$link"
  23. read -r -d '' request_data <<EOF
  24. {
  25. "method": "torrent-add",
  26. "arguments": {
  27. "filename": "$link",
  28. "download-dir": "$download_dir"
  29. }
  30. }
  31. EOF
  32. request \
  33. --header "$(request | get_key)" \
  34. --data-binary "$request_data"
  35. notify "adding torrent" "done"