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.

5 replies on “Opening magnet links with xdg-open on a remote transmission daemon…”

it still opens transmission-gtk when i click the links? am i doing something wrong? does nothing to the remote client or remote web client
im using arch btw

If that is the case your browser does not know yet which application to invoke upon a click of a magnet link. You need to make your browser forget about transmission-gtk before you can continue sending the magnet link to a remote transmission daemon. your browser just needs to call the script.

hth
ps: I myself recently had issues with my setup when I tried it on Ubuntu 13.10. I have to look into that.

I think that you need to tell xdg-open that magnet links will be open with your new magnet.destop with the following command:
xdg-mime default magnet.desktop x-scheme-handler/magnet

Tested on Ubuntu 14.04 and works perfect.

BTW, thanks a lot for the magnet.desktop, I had my custom script for rtorrent but I didn’t know how to link it with the xdg 🙂

Hi,

I have this link into my bookmarks and it’s always very useful

Just a suggestion: restart chrome or whatever browser you are using and install curl if it is not.

Leave a Reply

Your email address will not be published. Required fields are marked *

verify you\'re human: * Time limit is exhausted. Please reload CAPTCHA.