A Greasemonkey script for adding torrents to the uTorrent WebUI
Since I download torrents on my server and browse for them on my desktop machine, I have always had to copy the links from the browser, open up a remote desktop connection to the server and paste the links to µTorrent. This procedure can get quite tedious after a while, so I was wondering if there could be an easier way.
For the impatient:
Install the script for µTorrent 1.x
Install the script for µTorrent 2.x (with token authentication – thanks to BaK)
For some time now, µTorrent has had a web interface with lots of functionality including the ability to add torrents. This gave me an idea of how to automate adding torrents remotely. Before writing my own Greasemonkey script, I googled around a bit to see if anyone else has come to the same idea before I have, and has perhaps already written such a script. I found the script Add Torrents To uTorrent by Julien Couvreur which appeared to be doing just that. The script works fine in itself, but I wanted something more of it. Firstly, that script opens a new window for each torrent you click and I wanted to get rid of that. Secondly, I wanted to use the script on private trackers as well, the problem being that they require login.
At first I just intended to make some changes to Julien’s script, but as I started adding more and more features, I decided to completely rewrite the script, keeping only a couple of lines of code from the original script (the icon and the µTorrent url). It now supports user-configurable hostname, cookies, url transformations and proxies. I will go into more details about these features in the next few paragraphs.
After installing the script and opening a page (any page), you will be prompted to enter the address of your µTorrent WebUI. This will happen only once, after which the script will remember your setting. If you make a mistake or change the WebUI address later, you can modify this setting by pressing CTRL+ALT+SHIFT+U on any page.
You can then start using the script without any more configuration. However if you wish, you can customize it further by opening the script in a text editor. You can do this by going to “Manage User Scripts”, selecting the script and clicking “Edit”. There are 5 variables in there you can modify, all at the beginning of the script.
The most important variable is sites, without which, the script will not work at all.
sites: {
'isohunt' : 'isohunt\\.com/download/',
'bt-chat' : 'bt-chat\\.com/download1\\.php\\?',
'torrentreactor' : 'dl\\.torrentreactor\\.net/download.php\\?',
'mininova' : 'mininova\\.org/get/',
'mininova-tor' : 'mininova\\.org/tor/',
'torrentspy' : 'torrentspy\\.com/download.asp\\?',
'mybittorrent' : 'mybittorrent\\.com/dl/',
'bushtorrent' : 'bushtorrent\\.com/download\\.php\\?',
'partis' : 'partis\\.si/torrent/prenesi/',
'thebox' : 'thebox\\.bz/download.php/',
'general' : '\\.torrent$',
},
This is an associative array (or a hash table) defining the patterns to which a link must conform to be recognised as a torrent link. The key is the name of the site the links can be found on, and the value is a regular expression describing the link. The entries are processed from top to bottom, the first one having the highest precedence. The last entry matches all links directly to torrent files and should not be removed.
The variable cookies defines which cookies should be sent when adding the link. This can be used to log into private trackers.
cookies: {
'partis' : { 'auth_token': null },
'thebox' : { 'uid': null, 'pass': null },
},
This is a hash table, where each key must correspond to a key in the sites array. With this syntax you can define as many cookies as you like for each site. List them as a hash table, the key being the name of the cookie, while the value should be the value of the cookie, or null if you wish the script to read the cookie from the browser (this only works if you click a torrent link pointing at the same domain as you are currently on).
The next variable is transforms. This can be useful for instance to transform links that point to a torrent details page, if a direct download link can be derived from it.
transforms: {
'mininova-tor': { '/tor/' : '/get/' },
},
The keys should again correspond to the ones in the sites variable, while the values should be hash tables, where the key/value pairs should be the from/to for a string replace operation.
The final hash table defines proxies. This can be used to transform links, when the direct link cannot be derived from the torrent details link. This feature loads the page to which a link is pointing and parses it to find the download link in it.
proxies: {
'bt-chat\\.com/download\\.php\\?': '(http://www\\.bt-chat\\.com/download1\\.php\\?[^"]+)',
'fulldls\\.com/get_': '(download-[^"]+\\.torrent)',
'fulldls\\.com/torrent-': '(download-[^"]+\\.torrent)',
},
This array is independent of the sites variable. The key is a regular expression that matches the links in the page you are browsing, while the value is a regular expression that should match the direct link in the torrent details page.
The proxy feature is turned off by default, as it may use a lot of bandwidth and/or slow down your browsing. If you wish to use it, you first have to enable it by setting the proxiesEnabled varuable to true.
That’s it! Click on one of the following links to install the script:
Install the script for µTorrent 1.x
Install the script for µTorrent 2.x (with token authentication – thanks to BaK)
Please report any problems you may encounter with the script in the comments section below.
Tagged with: greasemonkey script torrent javascript