3

How do I configure firefox such that a clicked bittorent link is automatically added to a transmission daemon that runs on a remote machine?

The transmission daemon is available via ssh/transmission-remote-control port.

I can easily instruct firefox to open a torrent file with a shell script of my choice but then firefox downloads the torrent file to /var/tmp and supplies the temporary file path to the script.

This is not exactly what I want - I need firefox to just call the shell script and supply the (original) URL as parameter.

Bonus points for a setup where firefox even gives feedback in case the shell script's exit status is unequal 0.

(I am mentioning shell scripts here, but don't hesitate other scripting solutions if they are more convenient for that purpose)

  • I wrote this up on my blog: lamolabs.org/blog/7949/…. Feel free to post it as an answer to your question, I'm off to bed. – slm Sep 15 '13 at 10:28
  • @slm, your blog post is about magnet links - but I need a setup that works with plain-old .torrent-links. Have a look at my answer ... – maxschlepzig Sep 15 '13 at 12:06
  • sorry skimmed your Q, didn't realize it was for the non magnet variety. Glad to see you solved it though. – slm Sep 15 '13 at 18:25
1

Very surprisingly, out-of-the-box, Firefox does not offer a way to directly open URLs of certain mime-type (or containing certain file extensions) with external programs.

Another usecase for this would be calling external programs for streaming.

There are even a few old bug reports for Firefox (dating back a decade ago). The developers seem to acknowledge the general issue, but they are still open - sometimes principal architectural issues are mentioned. Other browsers like Opera/Internet-Explorer support such open-URL-with-external-program feature. A few comments mention different addons to work-around this - but they are all seem to be discontinued/not-working.

I've come up with following solution:

part 1: addon

Install the Firefox addon URL Relay. With that you can configure URL patterns that are opened with an external program.

part 2: shell script

Use a shell script like this:

#!/usr/bin/bash

set -e
set -u
# for testing
set -x

if [ $# -lt 1 ] ; then
  cat <<EOF
call: $0 TORRENT_URL_1 TORRENT_URL_2 ...

Adds torrent URLs to a remote transmission daemon.

EOF
  exit 1
fi

function quote()
{
  for i in "$@"; do
    echo --add "'"$i"'"
  done
}

HOST=example.org
AUTH="--auth juser:geheim"
ADDR=transmissiond.example.org:5432
TRANSMISSION_REMOTE=transmission-remote

ssh $HOST $TRANSMISSION_REMOTE $ADDR $AUTH  `quote "$@"`  # "'$1'"

The quoting scheme is used to protect against whitespace/shell-meta-characters in URLs, allthough firefox is probably sane enough not to include those.

part 3: configure URL relay

Use something like \.torrent$ as URL pattern, the script location as executable and just %URL% as parameter.

additional notes

The addon URL Relay does not seem to give feedback on erroneous exit status. Thus, one can wrap the above script with at now such that an email is sent in the error case.

  • “Very surprisingly, Firefox does not out-of-the-box offer a way to open certain file extensions/mime types with external programs.” Er, it doesn't (by mime type, not by file name)? Isn't that Edit → Preferences → Applications? – Gilles Sep 15 '13 at 22:56
  • @Gilles, to clarify: You can associate mime-types with external programs, but then Firefox downloads the URL to a temporary location and calls the external program on that downloaded file. This is what 'Edit/Preferences/Apps' is about. You can't tell stock-Firefox to call an external program for a certain mime-type without downloading the file in question and instead supplying the original URL to it. I'll try to reword the paragraph of my answer. And, it seems, you can't make Firefox to just look at file-extension (and ignoring the mime-type), either. – maxschlepzig Sep 16 '13 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.