Main menu

howtos, tutorials and tech-porn

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.

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:

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.

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.

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.

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?

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?

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.

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..

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.

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!

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!”

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.

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):

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.