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!
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.
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)
– 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.
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:
This will match any link that follows the naming pattern of the original link.
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.
for newer ones, please consult the Google Code page
– fixed SSL support for transmission
– added support for the Vuze Remote plugin (self-signed SSL certificates must be imported/accepted manually!)
– fixed bug introduced in previous release
– added support for bittorrent links behind html buttons – please report if this breaks anything (like regular buttons).
– added support for Buffalo’s Bittorrent WebUI
– added support for Vuze’s HTML WebUI plugin
– bugfix for rutorrent
– added default label and directory settings to the rutorrent client.
– made options more aesthetically pleasing, added more information
– fixed an issue that would silently make urls without “.torrent” in them fail to load
– (hopefully) fixed rutorrent and torrentflux support
– added SSL support for Torrentflux and ruTorrent web interfaces
– fix to support for newer versions of chrome (due to this)
– simplified uTorrent handling
– added Torrentflux support (please test and report, people)
– added ruTorrent support (no SSL (yet?))
– fixed an options display bug with the regex filters (thanks Curtis)
– added an option to hide the new address bar indicator
– prettied up the options page
– added an icon to the address bar to indicate that torrent links have been found
– a bit of code cleanup and resource bug fixing