Categories
english OnlineLife Net Webapps Software

Opening magnet links with xdg-open on a remote transmission daemon…

chromium asks for permission to open a magnet link
i posted a how to on a similar solution about one and a half years ago. this time we configure xdg-open to do the same.

note: if you are using ubuntu you might want to try the solution of the previous post. the approach discussed here was needed for a gentoo system, which comes with xdg-open part of xdg-utils.

the setup is as follows:
we have a remote server that runs transmission. the desktop system runs gnome.

the use case: we click a magnet link on the desktop system and the torrents starts downloading on the remote transmission server.

first we need to make a default application that we can hand our magnet link to:
we use the script we know from my previous post:

#!/bin/bash
test -z $1 && echo "need magnet link!
$0 <magnet link>" && exit -1

HOST=127.0.0.1 #YourRemoteHostNameOrIP
PORT=9091 #YourPort(default is 9091)
USER=User
PASS=pass

LINK="$1"
# set true if you want every torrent to be paused initially
#PAUSED="true"
PAUSED="false"
SESSID=$(curl --silent --anyauth --user $USER:$PASS "http://$HOST:$PORT/transmission/rpc" | sed 's/.*<code>//g;s/<\/code>.*//g')
curl --silent --anyauth --user $USER:$PASS --header "$SESSID" "http://$HOST:$PORT/transmission/rpc" -d "{\"method\":\"torrent-add\",\"arguments\":{\"paused\":${PAUSED},\"filename\":\"${LINK}\"}}"

put this script where you like, we will refer here to /home/user/Scripts/magnetLinkTransfer.sh, make it executable, and configure it according to your transmission setup on your remote machine. you might also need to install ‘curl’, which is used by this script.

second we need to define this new ‘application’ in /usr/share/applications/:
add the file “magnet.desktop” in the folder /usr/share/applications/ with the following content:

[Desktop Entry]
Name=Magnet
Type=Application
Comment=Open a magnet link remotly with the help of a script
Exec=/home/user/Scripts/magnetLinkTransfer.sh %U
Categories=Network;WebBrowser;
MimeType=x-scheme-handler/magnet;

lastly we need to add our new ‘application’ in “.local/share/applications/mimeapps.list”. add ‘x-scheme-handler/magnet=magnet.desktop’ to the default applications in that file, like this:

[Default Applications]
# there might be more other default applications defined, leave them unchanged.
x-scheme-handler/magnet=magnet.desktop

that should be it! now when you click a link in your browser it should either work, or ask you if it is ok to start “xdg-open magnet:…”, as seen in the picture. you may set the check box to avoid future confirmations.