A Greasemonkey script for adding torrents to the uTorrent WebUI

10 03 2008

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.

Tags: , ,

Related posts


Actions

Informations

52 responses to “A Greasemonkey script for adding torrents to the uTorrent WebUI”

13 12 2008
Januz (16:51:21) :

Hi there,

great skript! But I tried to extend the functionality to sites like Demonoid or Torrent.to and I don´t understand how to do it…

Could you please help me?

Thanks,

Januz

13 12 2008
Jure Merhar (18:38:24) :

Hi, Januz,

For demonoid, I know exactly, because I’ve added it to my own script, after publishing this article.
To the ’sites’ variable, you have to add the following line:
'demonoid' : 'demonoid\\.com/files/download/HTTP/',
And to the ‘cookies’ variable, this:
'demonoid' : { 'uid': null, 'uhsh': null },

Since I’m not familiar with torrent.to, I cannot tell you exactly what you need for that site, but it should be something similar. Add a regular expression that matches the url of the torrents to the ’sites’ variable and a list of cookies needed to the ‘cookies’ variable (if the site requires login).

Hope that helps,
Jure

26 12 2008
Patrick (11:57:47) :

Great plugin! However, have a little problem from this script that didnt show up on the other one -

the utorrent icon shows just to the left of the torrent text, but the normal mininova one shows up on the line underneath for normal download. is tere any way of getting them on the same line to save space? The other plugin doeesnt seem to have this issue and was trying to go through the code to try and sort it, but its way about my head!

Thanks! :D

28 12 2008
Jure Merhar (15:10:46) :

Hi, Patrick,

This other plugin you mentioned, where can I find it? I was not aware there had already existed a plugin like this, when I was writing this one.

As for the display issue with mininova, I never really thought of it as a bug, at least not one that needed fixing. :)
All this script does is it inserts a link with no styling (css), next to the torrent link. So, there are bound to be display issues on some sites, where there is no space for a new link. I don’t see a way of fixing this in a generic way. I guess a hack could be added specifically for mininova, but I think that’s just too much hassle for such a minor issue. :)

If you provide me with a link to the other plugin though, I could skim through the code to see how they’ve fixed this.

25 01 2009
Stork66 (23:51:40) :

Dude, that has to be one of the best, most useful scripts for me because my University blocks .torrent files and it becomes quite difficult to get the torrent files to my seedbox so thanks a lot for your great work!

2 02 2009
Kumar (18:27:56) :

This is very good plugin. But i have question. Why when i click on the picture (utorrent) it say that “torrent added to utorrent” but i do not have it on utorrent. Must i write something to script? I tried it on TL.

2 02 2009
Jure Merhar (18:57:06) :

Hi, Kumar,

The script shows this message whenever it gets a response from the WebUI, regardless of whether the torrent was added successfully or not. This is because there is no way of knowing it from the response.

That aside, there are a few possibilities why the torrent was not added. Firstly, check if you have specified the correct host for your uTorrent WebUI. You can display the current value and change it by pressing Ctrl+Alt+Shift+U. If the URL to your WebUI is for example “http://host:123/gui”, type just “host:123″ into the box that pops up.

Once you’re sure you have the right host, check whether this or a similar torrent is already loaded in uTorrent. If you are already downloading the same torrent (albeit from a different tracker), uTorrent usually informs you of this when you try to add it, and gives you the option to just load the trackers from the new torrent. However, this is not the case with the WebUI. Here, the new torrent simply gets ignored and therefore not added to uTorrent again.

Hope this helps. Can’t think of any other reasons at the moment.

Jure

2 02 2009
Kumar (19:08:29) :

Hi Jure.. Thanks for your answer. But it still no work :-( My WebUI URL is good and i tried add new torrents but no work. It works only at Mininova.org……Why? :-( I tried other script but it also no work.
(http://userscripts.org/scripts/show/12452)

2 02 2009
Jure Merhar (19:14:33) :

I’m afraid I cannot help you further, without a little more info. Are you using it on a private tracker? If so, which one? What is the exact url to the torrent that doesn’t work?

2 02 2009
Kumar (19:23:14) :
2 02 2009
Jure Merhar (19:28:45) :

Private trackers need to be added to the script. Some of the ones I’m using are already in there, but not these two.

Check your e-mail. I can help you add these trackers via e-mail.

6 02 2009
BK (10:56:41) :

Hi!
I am having problems adding a private tracker (TL) to this script. I am able to add the site, but as soon as I add the cookies the webUI icon disappears from the site.

Please advise.

6 02 2009
Jure Merhar (11:00:34) :

You probably have a syntax error in your script. Paste your cookies array here, so I can take a look.

7 02 2009
Patrick (11:26:35) :

Sorry for the delay - here is the link : http://userscripts.org/scripts/show/12452

just retested it and it works - but prefer yours! :D also noted on your script, if you use it as default, there are 2 utorrent logos on mininova (i always delete the mininova tor part on the script to solve this).

Cheers! :D

7 02 2009
Jure Merhar (20:08:36) :

Yes, the double icon is indeed there because of the mininova-tor transform. The intention of this transform is to have uTorrent icons on external sites and search engines, pointing to mininova. The reason I left it in is that I like this functionality more than I dislike the double icons on the site itself. :)

15 04 2009
b.w. (16:51:01) :

Jure,

Thanks for the awesome script, it’s very handy! However, I’m having a bit of a problem. When I click on the small button to add a torrent, it gives the messagebox confirming that the torrent has been added, but it doesn’t actually add it. I tried copying the link and pasting it into the tab I have the webUI open in. The result was a blank page with nothing but {”build”:14458} in fixed-width font.

I would try the other script mentioned in the article, but the portal in question is Demonoid (which requires login of course).

Am I doing something wrong here? Any help would be greatly appreciated. Thanks.

15 04 2009
b.w. (17:01:55) :

Lol, sorry, disregard my last comment. I wasn’t logged in! (facepalm.jpg)

26 04 2009
Stephen (00:31:25) :

I have tried the greasemonkey tool but prefer to use utorrent handler for uploading my torrents.

Seedbox Hosting

26 04 2009
kaooo (15:39:49) :

Hi,
Thanks for this great script!!
Could you please tell me how to adapt with snowtigers.net tracker please? if possible…

Thanks for your help ;)

26 04 2009
Jure Merhar (15:52:31) :

Hi, kaooo,

Sorry, but I can’t help you with that particular tracker, since I’m not a member there. I suggest, you read the instructions above. Also, look at the examples that are present in the script already. Basically, you’ll have to add a line to the sites array, and one to the cookies array.

Good luck!

29 04 2009
esquilax (03:32:47) :

great idea!! thank you very much!!

5 05 2009
Andi (18:40:23) :

Very cool, I am trying to get it to work. I can’t seem to add my seedbox with the username and password to it. Is there a format to it?
Also do you know how to link up the Russian site Megashara?

5 05 2009
Jure Merhar (19:04:44) :

Hi, Andi,

There is no special format for the hostname. Just make sure that you specify the hostname and port only, without http:// or /gui (e.g. 10.0.0.10:1234). Essentially, if you can access the WebUI in your browser, it should work.

As far as I can see (I don’t speak russian), you have to use the following regex for megashara.com:
'megashara' : 'megashara\\.com/get/'

Can’t help you with the cookies though, if the site requires registration, because I’m not a member.

6 05 2009
Andi (07:01:22) :

Thanks, I got the host name all set.
It works on all the hosts you set up. I can’t get either the demoniod, or the megashara to load to my Webui.
I get the little icon and click it, it tells me it works then when I check my server, it isn’t there?
I have megashara set up like mininova, I have tried with a cookie like demoniod and one like the box.
Thank you for all your input. This is a great script!
Watch it is my Gui.

6 05 2009
Jure Merhar (07:44:46) :

For demonoid, please read my first comment. It’s working fine for me, with those settings.

To see which cookies megashara.com uses, open up preferences in firefox, go to Privacy and click on “Show cookies…”. Then, type megashara in the search box. You’ll see all the cookies it uses, in the box below. Look for something like user id and password, or a session id. You’ll need to be logged in for the script to work, as well as to see the cookies.

6 05 2009
Andi (12:34:27) :

I added the Demoniod just like you have it, and every thing you have done it working great. Which is why I think it is my seedbox.
Thanks again!

3 07 2009
Rhonlith (15:40:23) :

Thanks for the script,
Although I can’t get the one of the websites I visit to work properly, typo maybe?

Does this look alright?
’somewebsite’ : ’somewebsite\.us/dlwin2\.php\?’,
’somewebsite’ : { ‘uid’: null, ‘pass’: null },
’somewebsite’ : { ‘www’ : ‘download’, ‘dlwin2′ : ‘download’ },

icons appear and the transform is working but the url being sent to utorrent doesn’t have the cookie information at the end.

4 07 2009
Jure Merhar (17:19:47) :

Hi, Rhonlith,

I have had the same problem with one site only. I’m sorry to tell you that I couldn’t figure out what the problem was. The only solution that worked for me, was to specify the actual values of the cookies instead of null. You can try to do that, it might help.

5 07 2009
Rhonlith (08:20:30) :

Thanks for the help,
Specifying the actual values for the sites uid and pass did work.

29 07 2009
Ustice (20:46:14) :

I installed the script in GM, but when I click on one of the generated links, nothing happens. I have tried this on a few sites. I’m not sure what info you would need to diagnose the issue, but if you can contact me, I will provide it. Thanks in any case.

30 07 2009
Jure Merhar (00:29:22) :

If by “nothing happens”, you really mean nothing (not even a password prompt), then the script failed to connect to uTorrent. Here’s a few possible reasons, off the top of my head:
1. You’ve entered the hostname incorrectly. Press CTRL+ALT+SHIFT+U and check the value is correct (and without http://)
2. Your computer does not have access to the uTorrent WebUI, because of a firewall or similar. Try opening the WebUI in the browser to see if it works.
3. You have not enabled WebUI in uTorrent. See here: µTorrent WebUI Guide.
4. uTorrent is not running. I think this one’s obvious. :)

I can’t think of any other reason at the moment. Please, let me know if this helps.

Jure

30 07 2009
Ustice (22:49:10) :

I just realized that I have SSH on for it, and was directing it to port 80. Therefore I need to go through 443. Does your script support https? (I suppose I could just check the code)

BTW, thanks. :)

30 07 2009
Jure Merhar (23:45:34) :

I’m afraid it does not support https, but it’s extremely easy to change that, if you know a little javascript. Just look for the function getHref and change ‘http://’ to ‘https://’.

I might add support in a future version if there is much demand. I never thought of implementing it, since uTorrent’s WebUI does not support ssl (I think).

31 07 2009
Ustice (00:50:53) :

That’s what I figured. Ya, it isn’t a part of the install, but there are guides to pipe it through ssh. Thanks, I will make that change for my use.

If you DO decide to add it to the script, I might suggest that you just have the user paste in the URL for their WebUI, where you can parse out the protocol, domain, port, and path. That way it keeps things simple for users, and keeps your UI simplistic as well. (Not to mention, that is a simple problem to parse this out)

Thanks for pointing me in the right direction, and for the script. I can’t wait to try it out tomorrow at work.

2 08 2009
Jure Merhar (15:21:59) :

Since I agree with your reasoning regarding simplicity, Ustice, I have changed the script so that it now takes the entire URL instead of just the hostname. Thanks for the suggestion.

Please note that you will have to reconfigure the WebUI address if you upgrade the script. Do this by pressing CTRL+ALT+SHIFT+U.

3 08 2009
Ustice (03:16:55) :

Glad that I could help. :) thanks again.

6 11 2009
vhost (11:45:54) :

sorry for asking dumb question, but so far i can not understand this script and how to install it either.

where to press CTRL+ALT+SHIFT+U????

6 11 2009
Jure Merhar (12:13:19) :

Hi, vhost,

You can press it anywhere (on any page), as long as you have the script installed and enabled.

4 12 2009
Kyle (05:20:54) :

Hi There, I was hoping you could help me set this up with bitgamer.com

The URL structure is like this:

http://www.bitgamer.com/download.php?id=123123&name=NAME.torrent

4 12 2009
Kyle (07:09:06) :

Nevermind, I got it thanks. I had a typo in the cookies section.

29 12 2009
ruppo (15:00:28) :

Hi!

I have tried now to configure the script, but it doesn’t work for me!

For example I want to add TorrentLeech as one of the sites. If I have understand everything correctly I also need to add the site under cookies, and there replace null efter uid and pass with the information from the cookie-handler in FF?

The problem I have is to get the regular expression right. The links matchets the following:
http://www.torrentleech.org/download.php/idOfTorrent/nameOfTorrent.torrent

Hope u understand my problem and can help me out!

//ruppo

29 12 2009
Jure Merhar (15:16:37) :

Hi, ruppo,

Try using something like this in the sites array:
'torrentleech': 'torrentleech\\.org/download\\.php/',

And something like this in the cookies array:
'torrentleech': { 'uid': null, 'pass': null },

Make sure you add your rule before the general ‘\\.torrent$’ rule, since this rule will override yours because of the .torrent extension in your link.

In most cases you should be fine by specifying null in the cookies array, as this means the cookies will be read from the browser. If for some reason this doesn’t work for you, try specifying the actual values. It is very important though that the cookies’ names are correct, so please check that first.

29 12 2009
ruppo (15:50:30) :

How annoying, can’t get it to work… have both tried with null and the real values under the cookie settings. I have like follow:

‘torrentleech.org’ : ‘torrentleech\.org/download\.php/’,
‘torrentleech.org’ : { ‘uid’: null, ‘pass’: null },

I just get the response from WebUI, but then nothing happens. In the script setting I have set the server address to 192.168.0.2:8080 without anything else.

If I check the address that the utorrent-icon contains next to the real link it says:
http://www.torrentleech.org/192.168.0.2:8080?action=add-url&s=http://www.torrentleech.org/download.php/201029/WWE.Monday.Night.RAW.2009.12.28.WS.PDTV.XviD-433.torrent:COOKIE:uid=XXXXXXX;pass=XXXXXXXXXXXXXXXXXXXXXXX

[Edited by Jure - please don't include your login credentials in the comments]

is that right?

29 12 2009
Jure Merhar (16:04:18) :

Please, press CTRL+ALT+SHIFT+U in Firefox and enter the following in the box that pops up:
http://192.168.0.2:8080/gui/

Also, double check that the site does indeed use the cookies ‘uid’ and ‘pass’ for authentication.

20 02 2010
BaK (22:38:08) :

Being that uTorrent 2.0 WebUI supports only Token-authenticated comunication, i added Token-auth support to the script.

You can find it here.

To replace the old one go to greasemonkey’s icon, manage scripts, select the previous “Add Torrents to uTorrent WebUI” script and hit Edit. Copy the new script and paste it over the old one and save.

Note that this script wont work with previous versions of the uTorrent WebUI, just with Token-auth ones.

21 02 2010
Jure Merhar (04:54:28) :

Thank you very much for your contribution, BaK.

When I upgraded my uTorrent to 2.0, I just switched token authentication off, since I couldn’t be bothered to look it up and modify the script. I have now added your changes, while still providing the original script for older (1.x) clients.

The links to both scripts can now be found in the article above.

21 02 2010
BaK (13:29:45) :

Thanks for the integration and the restructuring of the code.
It is always messy trying to understand other’s scripts structure… and i’m new to GM too.

Just a note. I saw you added an alert() for when the token fetching fails. Consider though that when the WebUI is offline or unreachable the alerts might be quite annoying. I suggest providing an option to disable them (in the ctrl-alt-shift-u dialog?) or just getting rid of the alert() at all.

21 02 2010
Jure Merhar (13:50:15) :

You’re right. I hadn’t really thought of that. I’ve removed the alert. Thanks for pointing it out.

21 02 2010
BaK (13:58:34) :

What about this way? http://freetexthost.com/mwh1is6r6t
It could be extended to other kinds of alerts…

21 02 2010
Jure Merhar (14:12:47) :

Thanks for the suggestion, but I think I’ll just leave it as it is. I don’t think the alert would be of much value to the user anyway, since you can already see that something went wrong when the icons don’t appear. Besides, another configuration option would probably just confuse users more. :)

21 02 2010
BaK (14:22:15) :

Agreed :)

21 02 2010
Jure Merhar (17:07:08) :

Talking about these alerts got me thinking about the “added to utorrent” message, which is also quite annoying. So, I’ve come up with the idea of changing the icon on a successful request, instead of displaying an alert. I think this is a bit more user-friendly. Both scripts have now been updated to reflect this change.

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">