Skip to content

Instantly share code, notes, and snippets.

@noodny
Created February 26, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save noodny/f5fe42f4f871bf9b4c804ddcbb09ccf9 to your computer and use it in GitHub Desktop.
Save noodny/f5fe42f4f871bf9b4c804ddcbb09ccf9 to your computer and use it in GitHub Desktop.
Link magnet files to a transmission deamon running rpc
on open location magnet_link
set hostname to "192.168.0.6"
set portname to "9091"
set rpc_url to "http://" & hostname & ":" & portname & "/transmission/rpc"
set cmd to "curl --silent " & rpc_url & " | sed 's/.*<code>//g;s/<\\/code>.*//g'"
set session_id to do shell script cmd
set add_cmd to "curl --silent --header \"" & session_id & "\" " & rpc_url & " -d \"{\\\"method\\\":\\\"torrent-add\\\",\\\"arguments\\\":{\\\"paused\\\":false,\\\"filename\\\":\\\"" & magnet_link & "\\\"}}\""
set response to do shell script add_cmd
set added_index to offset of "added" in response
set duplicate_index to offset of "duplicate" in response
if added_index is not 0 then
display notification "Torrent added succesfully"
delay 1
else if duplicate_index is not 0 then
display notification "Torrent is already on the list!"
delay 1
else
display dialog "Error adding the torrent: " & response
end if
end open location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment