Advertisement
Guest User

magnetLinkTransfer.sh

a guest
Feb 8th, 2017
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. # magenetLinkTransfer.sh
  3. # slapped together as a more controlled method of passing magnet urls to transmission-daemon
  4. # when the transgui and transmission-remote apps failed to do so.
  5. #
  6. # retreive argument(s) as $LINK
  7. LINK=("$1")
  8.  
  9. # if no argument is given, error out.
  10. if [ -z "$LINK" ]; then
  11.   echo "ERROR: need magnet link"
  12.   exit 1
  13. fi
  14.  
  15. # DEBUG purposes, dump the argument passed into a log file.
  16. echo $LINK >> /tmp/magnetlinktransfer.log
  17.  
  18. # transmission-daemon connection information.  [sensored for pastebin]
  19. HOST=127.0.0.1
  20. PORT=9091
  21. USER="username"
  22. PASS="password"
  23.  
  24. # gather authentication session identifier from transmission-daemon rpc
  25. SESSID=$(curl --silent --anyauth --user $USER:$PASS "http://$HOST:$PORT/transmission/rpc" | sed 's/.*<code>//g;s/<\/code>.*//g')
  26.  
  27. # DEBUG purposes, show in terminal (the .desktop called for magnet links will show terminal when calling this)
  28. echo ${LINK}
  29.  
  30. # send request to add torrent to the transmission-daemon
  31. curl --silent --anyauth --user $USER:$PASS --header "$SESSID" "http://$HOST:$PORT/transmission/rpc" -d "{\"method\":\"torrent-add\",\"arguments\":{\"filename\":\"${LINK}\"}}"
  32.  
  33. # DEBUG purposes, pause the script before finishing to allow review of the terminal window.
  34. read -n1 -r -p 'Press any key to continue...' key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement