Chrome extension to remotely add torrents to WebUIs

It has been an entire year since I’ve last posted an article, and what better opportunity than the one year anniversary of that last post could there possibly be to present the offspring of my latest surge in productivity? None, i tell you!

About Chrome

Google Chrome, the up and coming web browser draws people toward itself in very much the same way that moths are drawn to the corona of a watchtower, exceeding the 10% mark in terms of total browser market share and thereby bringing the WebKit HTML rendering engine to almost double as many people as Apple’s Safari has been able to.

As a relatively new browser (2.5 years old), and similar to most popular applications that permit the development of plug-ins, it has always had a flourishing community of developers that try and augment its capabilities to the best of their abilities (to the extent that Chrome allows them), and today I’m taking the time to introduce one that in its current form isn’t yet known to the Chrome platform.

The idea came up when I switched to Chrome over from Firefox and tried finding an extension that implemented the functionality of Bittorrent WebUI. There were a couple of extensions, mostly for one Bittorrent client (e.g. uTorrent, Transmission) at a time, and all of them seemed to work in one particular way: They produced a context menu entry over links that would send the underlying link’s URI to a pre-configured web interface – a pretty trivial implementation.

And this works fine – however only in a pretty confined scope: Sites that require any sort of authentication won’t work, as the URI that is passed to the WebUI can neither contain cookies (except uTorrent’s WebUI), nor does HTTP Basic Authentication information get passed along. And while the latter is pretty uncommon for most sites, the former renders these extensions pointless to use for any register-to-download tracker.

Firefox’ Bittorrent WebUI performed its task differently: If the linked file resulted in a file ending in “.torrent”, it downloaded said file into a temporary directory and then upload the file to a WebUI of one’s choosing. This made the life of people who have their torrent client on a machine other than 127.0.0.1 a lot easier, and i’ll say that it was one of my top 3 most favorite addons for Firefox.

As Chrome’s extension API (the sum of things you can do using the browser’s programming interface itself) is extremely limited, most extensions have to rely solely on things you can accomplish using only JavaScript.

But let’s get down and dirty.

Remote Torrent Adder

This extension allows you to add torrents from your Browser to your favorite Bittorrent client’s WebUI. This works in such a way that it utilizes the Browser’s authentication information transparently – it downloads the torrent file into memory and then uploads it to the WebUI, rather than just sending a URI that the client may not get anything useful from.

Since Chrome does not let any extension manipulate or look at downloaded files, the way in which this extension catches download links of .torrent files is that it scans every page’s links for specific patterns that would indicate that when you click them, you’re downloading a .torrent file. Due to the fact that there is a myriad of torrent trackers out there that employ any arbitrary link format, it doesn’t make sense to scour the web and write patterns for every page. Instead, this extension makes it possible to add your own “filters” to recognize potential links.

As of the time of the writing of this article, it supports the following Bittorrent clients’ WebUIs:
– uTorrent & uTorrent server (& uTorrent for Mac?) (using the built-in WebUIs)
– Vuze (using the Swing WebUI & HTML WebUI plugins)
– Transmission (using the built-in WebUI)
– Torrentflux
– rtorrent (using the ruTorrent extension)

Support for further clients is usually comparably easy to implement, so if you’re missing your favorite client in that list, give me a shout and i’ll see what i can whip up.

The extension has two routes of facilitating the adding of torrents – you can either right click on a link to bring up a context menu and use the extension’s entry to send the torrent behind the link to the WebUI, or use the click interception function that prevents a link from being downloaded and instead carries out the same functionality as the context menu entry.

Filters

Since the click interception function is perhaps the most important aspect of this extension – it makes adding a torrent to the WebUI a one click operation as opposed to two or more – the possibility to add custom filters is an equally important part of the extension’s preferences.

For maximum adaptivity, this extension uses regular expressions to match download links. What follows is a brief explanation for the regexp newbie on how to get a working regular expression from a sample link:

Consider this link: “https://ssl.somesite.com/torrents.php?action=download&id=12345678&authkey=0a1b2c3d4e5f6g7h8i9j”

We don’t care about the protocol itself – merely the site’s domain name itself should be kept in the pattern, so we strip the protocol and subdomain.

We get: “somesite.com/torrents.php?action=download&id=12345678&authkey=0a1b2c3d4e5f6g7h8i9j”

The most interesting part after the domain name should be the name of the script that delivers the .torrent files for downloading, in this case it’s “torrents.php”, so we leave that in. The parameter “action=download” identifies exactly what we want – to download a torrent – so that too is one that we won’t touch. Next up is an ID – this is a number identifying the torrent on the tracker’s side. Since we want to download other torrents as well that don’t have this unique ID, we’ll replace it with a placeholder that will match any kind of ID. Since those are numbers only, we use \d+. This catches any and all strings of numbers, and nothing but numbers.

Therefore: “somesite.com/torrents.php?action=download&id=\d+&authkey=0a1b2c3d4e5f6g7h8i9j”

Now what we have left is the parameter containing the authkey. Since our pattern before that parameter already contains a lot of information that will prevent it from matching links it shouldn’t, we might as well just cut it off entirely. Alternatively, we could replace the value of authkey to accept a string containing anything, and this anything may be of arbitrary length.

Thus: “somesite.com/torrents.php?action=download&id=\d+”

Alternatively: “somesite.com/torrents.php?action=download&id=\d+&authkey=.+?”

As a last step, we will have to make this pattern actually work: some of the characters that were part of the original url are characters that have a very specific meaning in regular expressions, those are for the most part “.” (dot), “/” (forward slash) and “?” (question mark). To render them inert, we place a “\” (backslash) in front of them – we “escape” them:

Finally: “somesite\.com\/torrents\.php\?action=download&id=\d+”

This will match any link that follows the naming pattern of the original link.

Juicy Bits

Remote Torrent Adder in the Chrome web store

Feel free to ask for patterns, as long as you provide sample links, as well as support for further bittorrent clients that have a WebUI.

CHANGELOG

for newer ones, please consult the Google Code page

v1.0.21:
– fixed SSL support for transmission
– added support for the Vuze Remote plugin (self-signed SSL certificates must be imported/accepted manually!)

v1.0.20:
– fixed bug introduced in previous release

v1.0.19:
–  added support for bittorrent links behind html buttons – please report if this breaks anything (like regular buttons).

v1.0.18:
–  added support for Buffalo’s Bittorrent WebUI

v1.0.17:
– added support for  Vuze’s HTML WebUI plugin

v1.0.16:
– bugfix for rutorrent

v1.0.15:
– added default label and directory settings to the rutorrent client.

v1.0.14:
– made options more aesthetically pleasing, added more information

v1.0.13:
– fixed an issue that would silently make urls without “.torrent” in them fail to load

v1.0.12:
– (hopefully) fixed rutorrent and torrentflux support

v1.0.11:
– added SSL support for Torrentflux and ruTorrent web interfaces

v1.0.10:
–  fix to support for newer versions of chrome (due to this)

v1.0.9:
– simplified uTorrent handling
– added Torrentflux support (please test and report, people)

v1.0.8:
– added ruTorrent support (no SSL (yet?))

v1.0.6-v1.0.7:
– fixed an options display bug with the regex filters (thanks Curtis)

v1.0.5:
– added an option to hide the new address bar indicator
– prettied up the options page

v1.0.4:
– added an icon to the address bar to indicate that torrent links have been found

v1.0.0-v1.0.3:
– a bit of code cleanup and resource bug fixing

42 responses to “Chrome extension to remotely add torrents to WebUIs

  1. can you add buffalo’s torrent webui?

    its for a NAS…

    FF has an extension for it, but chrome does not.

    thanks!

  2. I am not sure where I need to click in order to answer you, (can’t read German).

    That FF extension supports Buffalo as well, but did not add it its description – I am certain 100% about it and checked it again, just in case…

    I can send you screen captures if necessary.

    Perhaps you will need more information about the buffalo torrent web interface?

    • nah, if it’s in there, i’ll likely be able to get all information i need from the ff extension.
      i’ll take a look at it come september.

    • hey again,
      i installed the above linked ff addon as well as its newer version with a +. neither of them contains a buffalo option. can you clarify exactly what version of which extension you’re using?

      • I have tried to emailed you, but no response.

        Actually, a friend of mine reminded me that he wrote the Buffalo part to that extension.

        I can forward you his addition to it, and he said that you will probably know exactly what to do with it.

        If it’s not a big bother, please email me to this email and I will be able to send you the file.

        Regards.

  3. This was working fine a couple of days ago, and suddenly stopped yesterday…Clicking on a torrent causing nothing to happen, not even the error message you get from incorrect configuration. Did a Chrome update break this?

    • i updated the plugin yesterday to include SSL support for torrentflux and ruTorrent.
      could you supply more information, i.e. which bittorrent client and any non-standard settings you’re using, so that i can try and reproduce the problem?

      • Same thing happened to me. Using ruTorrent 3.1 and none of the torrents I try to download are added.

      • if both of you could update to 1.0.12 and report on whether this fixes the issue, that would be lovely.

  4. Hi Julian,

    I am trying to get this extension working for ruTorrent, but I just can’t make it work…

    I’ve tried many permutations for the “host” and “relative path”, but I still just get a little pop up saying “sending the torrent failed”, no matter what I tried.

    The functionality this extension offers is potentially awesome, if only I could get it to connect to my server…

    Is it just me being retarded, or is there a bug in the extension?

    • Ok, I sorted my own problem out… I think I was typing my password in wrong :P. For others though, you remove the “http://” from the path to your server, and make sure you get the port number right!

      I am wondering if it would be possible to implement some sort of automatic folder selection, and torrent tagging when the upload occurs. This would help me out, given that I share a seedbox with others and we generally download to our own folder (and tag the torrent with our names). Is this something you could add, or is it not feasible?

  5. Hi. Does this add-on write a logfile anywhere? My ruTorrent uses ssl, and although I am sure I have the settings set correctly (port 443 etc) and tried all sorts in the path location I cannot get the add-on to work. I hope a log file might give me a clue

    • is the server’s ssl certificate self-signed, i.e. after starting up the browser and surfing to rutorrent, do you get a chrome warning message you have to click away? in that case, the extension may fail silently. this may be alleviated by adding the certificate to your local os’ certificate cache.

      others have this extension running with ssl, so i assume that the ssl support itself isn’t broken.

      if this isn’t the case, please follow these steps:
      1. open up chrome’s extensions page, start the developer mode and click on the “background.html” link below the extension’s name. this should open a developer tools window.
      2. in another tab, try adding a torrent through the extension’s functionality.
      3. back in the developer tools window, click the icon with the “>” to open up the javascript console and see if there’s an error message stemming from the extension. if so, please send it to me along with your settings.
      or better yet, create an issue on the above linked bitbucket issue tracker.

  6. I love the idea! I been trying to get rtorrent to work with this setup. I keep getting torrent sent failed. 😦

    i put in the ip in the host info and the specific port I am suppose to use. and the folder where the “php” folder is. The password and username is correct. I’m stumped. 😦 I tried public and private trackers..

    • Im getting an unauthorized for the reason why it cannot upload under the console tab.

      the greasemonkey script i been using would download the torrent

      rutorrentip:port/php/addtorrent.php? but the addon seems to be doing rutorrentip:port//php/ if it is not working correctly.

      http://user:rutorrentip:port//php/addtorrent.php? is what is on the console when I leave relative path empty.

      I think I just need that slash removed and it will work for me! 😀

  7. Hi,

    since update 10.0.15 i can’t use this extension with rutorrent GUI.

    got this error : [IMG]http://img33.imageshack.us/img33/8080/rutorrentextensionerror.jpg[/IMG]

    • hello,
      can you take a look at the options of the extension and re-do the settings in the bottom (i.e. delete directory/label if you don’t need it, set correct path)?
      this changed during the update and things may not have been moved properly.

    • i just found a small bug that’s responsible for your problem. you’ll notice that when you input a label in the options, it’ll work fine.

      i’ll push a bugfix version through the chrome webstore within the hour, you can forcibly update your extensions in an hour, or wait for it to update automatically.

  8. Hi Julian,
    would it be possible to support azureus / vuze HTML Web UI?
    I have Azureus (version 3.0.5.0) with HTML Web UI (version 0.7.6) running on a NAS. The above mentioned FF-Plugin (http://www.alexisbrunet.com/) works for the HTML Web UI, maybe it could give some hints. Thank You so much!

  9. I’m trying to send torrents to a NAS in my network, using the Transmission Webinterface thats running on the NAS.

    The webinterface can be found on:
    https://myipadress/transmission/web/ on port 443 (which is forwarded to the NAS).
    I’ve already added the self-signed certificate that the NAS is using to my OS, but I still can’t get the setup running, and keep getting the error:
    “Torrent fail
    Sending the torrent failed!”

    My settings:
    Client: Transmission web
    Host: myipadress/transmission/web/
    Port 443
    SSL: check
    Username: myusername
    Password: mypassword

    How can I get the setup to work properly?

    • edited my settings, and now I get a:

      “hurr durr derp?
      server didn’t accept data: 400 Bad Request Bad Request Your browser sent a request that this server could not understand. Reason: You’re speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please…… etc.”

      Current settings:

      Client: Transmission web
      Host: myipadress
      Port 443
      SSL: check
      Username: myusername
      Password: mypassword

      • that’s because the transmission module of the extension does not yet support https.
        i’ll look at it.

        for future bug report/request posters: instead of posting here, create an issue on the google code page. i tend to never look at the comments of this post, so leave only your praise here (if anything).

        edit: … and since you’ve only supplied a disposable email address, i’m not even gonna bother doing this as an official release. if you’re still interested, create an issue on the google code page.

  10. Hi there,
    I keep running into an error while trying to install the script (rutorrent webui). All the fields seem to be filled correct, however i keep getting this error when trying to download a torrent (on every tracker):

    log(theUILang.addTorrentFailed);

    http://imgur.com/VyFfy

    I have no idea what this error means. Can you help?
    thx

    • that’s an error coming from the server; that means at least the server received the torrent and the torrent add request itself succeeded.

      unfortunately, if the torrent isn’t added to the client, the server might have discarded the data sent by the extension for some reason, either because it was invalid (shouldn’t be because you tried multiple trackers), or for some other reason.

      let’s start with your chrome/extension version. also, would you mind creating an issue at the google code page linked near the changelog in the above blogpost? it’ll let me keep track of the case.

Leave a comment