Monday, March 5, 2012

Launching magnet links in Transmission remotely

This applescript will allow you to click magnet links in your browser to launch them in an instance of Transmission running on a remote server instead of a local instance. Be sure to fill in the user/pass and the address of your torrent box.

Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. on open location this_URL
  2.     set USER_PASS to "user:pass"
  3.     set TRANSMISSION_HOST to "addr:port"
  4.     do shell script "LINK='" & this_URL & "'; SESSID=$(curl --silent --anyauth --user " & USER_PASS & " 'http://" & TRANSMISSION_HOST & "/transmission/rpc' | sed 's/.*<code>//g;s/<\\/code>.*//g'); curl --silent --anyauth --user " & USER_PASS & " --header \"$SESSID\" \"http://" & TRANSMISSION_HOST & "/transmission/rpc\" -d \"{\\\"method\\\":\\\"torrent-add\\\",\\\"arguments\\\":{\\\"paused\\\":\\\"false\\\",\\\"filename\\\":\\\"${LINK}\\\"}}\""
  5. end open location


Save this script as an application, then navigate to the application and show package contents. Add the following to the main in info.plist:

Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.     <key>CFBundleIdentifier</key>
  2.     <string>com.apple.AppleScript.MagentLinkLauncher</string>
  3.     <key>CFBundleURLTypes</key>
  4.         <array>
  5.             <dict>
  6.                 <key>CFBundleURLName</key>
  7.                 <string>Magnet Link</string>
  8.                 <key>CFBundleURLSchemes</key>
  9.                 <array>
  10.                     <string>magnet</string>
  11.                 </array>
  12.             </dict>
  13.         </array>