Archived

This topic is now archived and is closed to further replies.

Lord Alderaan

mIRC script

Recommended Posts

Original incarnation: 2006-10-17 12:45 UTC

Current incarnation: 2010-03-04 17:00 UTC

[h]Major changes over the years:[/h]

  • Total Downloaded/Uploaded info over the currently loaded torrents (this does not and can not equal the stats in the µTorrent statusbar or Help Show Statistics)
  • Channel commands off by default.
  • Channel commands set per channel.
  • Added token support
  • Added GUID support
  • Regex to support both 2.0 and 2.1 format

[h]Install[/h]

In µTorrent press ctrl+P

Goto Web UI section

Enable Web UI

Fill in Username and Password.

Goto Connection

Write down the Port.

Press Ok

In mirc press alt+r

Goto the Remote tab

Choose File -> New

Paste the content of the codebox below in the script editor.

Goto the line var %ut_username guest and replace guest with the username you set in µTorrent.

Do the same for password and port.

If µtorrent does NOT run on the same computer as the mirc script do the same with the url line and fill in the IP or hosname of the computer running µTorrent.

Optional: There is a r-click menu script by memosis you could paste at the bottom.

Choose File -> Save

Press Ok

Type /uthelp

[h]Code[/h]

; type /uthelp for info

alias ut_getinfo {

; Incarnation: 2010-03-04 17:00

; -============================ CHANGE THE VALUES BELOW ============================- ;

; the username for the webui:
var %ut_username guest

; the password for the webui:
var %ut_password guest

; the hostname or ip of the machine running µtorrent, if µtorrent + webui is running on the same computer leave it at localhost:
set -n %ut_url localhost

; µtorrent port (or the alternative webui port if activated):
set -n %ut_port 32459

; OPTIONAL! maximum number of displayed torrentlines (not counting header and footer):
set %ut_flood_max 5

; -============================ CHANGE THE VALUES ABOVE ============================- ;

var %continue $false
if ( $sock(ut_info).to ) {
if ( $sock(ut_info).to > 25 ) {
ut_getinfo_end
%continue = $true
}
}
else {
%continue = $true
}
if ( %continue == $true && $1 && $2 ) {
set %ut_activechan $1
set %ut_action $2
if ( %ut_action == find && $3 ) {
set %ut_find_string $3-
; msg %ut_activechan 12[µT] Showing the first %ut_flood_max torrents containing $3-
}
elseif ( %ut_action == downloading ) {
; msg %ut_activechan 12[µT] Showing the first %ut_flood_max torrents downloading.
}
elseif ( %ut_action == seeding ) {
; msg %ut_activechan 12[µT] Showing the first %ut_flood_max torrents seeding.
}
set %ut_credentials $encode(%ut_username $+ : $+ %ut_password,m)
set %ut_download 0
set %ut_downloadingcount 0
set %ut_err_torrents 0
set %ut_flood_count 0
set %ut_ratio_sum 0
set %ut_remaining 0
set %ut_seedingcount 0
set %ut_sockerr 0
set %ut_torrentcount 0
set %ut_upload 0
set %ut_downloaded
set %ut_uploaded
.timerut_getinfo_end 1 20 ut_getinfo_end
sockopen ut_token %ut_url %ut_port
}
}


on 1:SOCKOPEN:ut_token:{
if ( $sockerr > 0 ) {
%ut_sockerr = $sockerr
ut_getinfo_end
return
}
sockwrite -n $sockname GET /gui/token.html HTTP/1.1
sockwrite -n $sockname Host: $+(%ut_url,:,%ut_port)
sockwrite -n $sockname Authorization: Basic %ut_credentials
sockwrite -n $sockname $crlf
}

on 1:SOCKREAD:ut_token:{
if ( $sockerr > 0 ) {
%ut_sockerr = $sockerr
echo ow: $sockerr
ut_getinfo_end
return
}
var %i 1
while (%i > 0 ) {
sockread -f %temp
if ( Set-Cookie: isin %temp ) {
if ( $regex(ut_re_c,%temp,/GUID=([^; ]*)/) > 0 ) {
set %ut_cookie $regml(ut_re_c,1)
}
}
if ( $+(id,$chr(61),$chr(34),token,$chr(34)) isin %temp || $+(id,$chr(61),$chr(39),token,$chr(39)) isin %temp ) {
if ( $regex(ut_re,%temp,/<div[^>]*id=["\']token["\'][^>]*>([^<]*)</div>/) > 0 ) {
set %ut_token $regml(ut_re,1)
sockopen ut_info %ut_url %ut_port
sockclose ut_token
}
}
%i = $sockbr
}
}

on 1:SOCKOPEN:ut_info:{
if ( $sockerr > 0 ) {
%ut_sockerr = $sockerr
ut_getinfo_end
return
}
sockwrite -n $sockname GET /gui/?list=1&token= $+ %ut_token HTTP/1.1
sockwrite -n $sockname Host: $+(%ut_url,:,%ut_port)
sockwrite -n $sockname Cookie: GUID= $+ %ut_cookie
sockwrite -n $sockname Authorization: Basic %ut_credentials
sockwrite -n $sockname $crlf
unset %ut_credentials
unset %ut_url
}

on 1:SOCKREAD:ut_info:{
if ( $sockerr > 0 ) {
%ut_sockerr = $sockerr
ut_getinfo_end
return
}
sockread %temp
if ( $left(%temp,12) == ,"torrentc": ) {
ut_getinfo_end
}
else {
var %pattern = \["(\w*)",(\d*),"(.*)",(\d*),(\d*),(\d*),(\d*),(\d*),(\d*),(\d*),(-?\d*),"(.*)",(\d*),(\d*),(\d*),(\d*),(\d*),(-?\d*),(\d*)[\]|,]
if ( $regex(tor,%temp,%pattern) == 1 ) {
var %hash = $regml(tor,1)
var %status $regml(tor,2)
var %torrentname = $regml(tor,3)
var %progress $regml(tor,5)
var %label = $regml(tor,12)
inc %ut_torrentcount
inc %ut_remaining $regml(tor,19)
inc %ut_download $regml(tor,10)
inc %ut_upload $regml(tor,9)
inc %ut_downloaded $regml(tor,6)
inc %ut_uploaded $regml(tor,7)
inc %ut_ratio_sum $regml(tor,8)
if ( $isbit(%status,1) == 1 && $isbit(%status,6) == 0 ) {
if ( %progress == 1000 ) {
inc %ut_seedingcount
}
else {
inc %ut_downloadingcount
}
}
if ( %ut_action == find ) {
if ( %ut_find_string isin %torrentname ) {
if ( %ut_flood_count < %ut_flood_max ) {
if ( %progress == 1000 ) {
var %temp = 12[µT]14 $left(%torrentname,40) $+ $ut_convert_status( %status , %progress ) UP: $+ $bytes( $regml(tor,7) ).suf SIZE: $+ $bytes( $regml(tor,4) ).suf R: $+ $calc( $regml(tor,8) / 1000) UL: $+ $bytes( $regml(tor,9) ).suf $+ /s P: $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) S: $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ )
}
else {
var %temp = 12[µT]14 $left(%torrentname,40) $+ $ut_convert_status( %status , %progress ) DOWN: $+ $bytes( $regml(tor,6) ).suf SIZE: $+ $bytes( $regml(tor,4) ).suf P: $+ $calc( %progress / 10) $+ $chr(37) DL: $+ $bytes( $regml(tor,10) ).suf $+ /s P: $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) S: $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ ) ETA: $+ $duration( $regml(tor,11) )
}
msg %ut_activechan %temp
}
inc %ut_flood_count
}
}
elseif ( %ut_action == downloading && %progress < 1000 && $isbit(%status,1) == 1 && $isbit(%status,6) == 0) {
if ( %ut_flood_count < %ut_flood_max ) {
var %temp = 12[µT]14 $left(%torrentname,40) $+ $ut_convert_status( %status , %progress ) DOWN: $+ $bytes( $regml(tor,6) ).suf SIZE: $+ $bytes( $regml(tor,4) ).suf P: $+ $calc( %progress / 10) $+ $chr(37) DL: $+ $bytes( $regml(tor,10) ).suf $+ /s P: $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) S: $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ ) ETA: $+ $duration( $regml(tor,11) )
msg %ut_activechan %temp
}
inc %ut_flood_count
}
elseif ( %ut_action == seeding && %progress == 1000 && $isbit(%status,1) == 1 && $isbit(%status,6) == 0 ) {
if ( %ut_flood_count < %ut_flood_max ) {
var %temp 12[µT]14 $left(%torrentname,40) $+ $ut_convert_status( %status , %progress ) UP: $+ $bytes( $regml(tor,7) ).suf SIZE: $+ $bytes( $regml(tor,4) ).suf R: $+ $calc( $regml(tor,8) / 1000) UL: $+ $bytes( $regml(tor,9) ).suf $+ /s P: $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) S: $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ )
msg %ut_activechan %temp
}
inc %ut_flood_count
}
}
}
unset %temp
}

alias ut_getinfo_end {
sockclose ut_token
sockclose ut_info
if ( %ut_sockerr == 0 ) {
if ( %ut_action == find || %ut_action == downloading || %ut_action == seeding ) {
; msg %ut_activechan 12[µT] Found %ut_flood_count torrents.
}
if ( %ut_action == stats ) {
if ( %ut_err_torrents > 0 ) {
var %temp = 12[µT] Torrents: $calc( %ut_torrentcount + %ut_err_torrents ) (Seed: $+ %ut_seedingcount $+ , Leech: $+ %ut_downloadingcount $+ , Inactive: $+ $calc( %ut_torrentcount - %ut_seedingcount - %ut_downloadingcount ) $+ , Unknown: $+ %ut_err_torrents $+ ). $bytes(%ut_download).suf $+ /s down, $bytes(%ut_upload).suf $+ /s up. Ratio: $round($calc($calc(%ut_ratio_sum / 1000) / %ut_torrentcount),2) Remaining: $bytes( %ut_remaining ).suf Downloaded: $bytes( %ut_downloaded ).suf Uploaded: $bytes( %ut_uploaded ).suf
}
else {
var %temp = 12[µT] Torrents: %ut_torrentcount (Seed: $+ %ut_seedingcount $+ , Leech: $+ %ut_downloadingcount $+ , Inactive: $+ $calc( %ut_torrentcount - %ut_seedingcount - %ut_downloadingcount ) $+ ). $bytes(%ut_download).suf $+ /s down, $bytes(%ut_upload).suf $+ /s up. Ratio: $round($calc($calc(%ut_ratio_sum / 1000) / %ut_torrentcount),2) Remaining: $bytes( %ut_remaining ).suf Downloaded: $bytes( %ut_downloaded ).suf Uploaded: $bytes( %ut_uploaded ).suf
}
msg %ut_activechan %temp
}
}
else {
; msg %ut_activechan 12[µT] Error: webui is not responding (socket error).
}
unset %ut_action
unset %ut_activechan
unset %ut_credentials
unset %ut_download
unset %ut_downloadingcount
unset %ut_err_torrents
unset %ut_find_string
unset %ut_flood_max
unset %ut_flood_count
unset %ut_ratio_sum
unset %ut_remaining
unset %ut_seedingcount
unset %ut_sockerr
unset %ut_torrentcount
unset %ut_url
unset %ut_upload
unset %temp
unset %ut_cookie
unset %ut_token
unset %ut_uploaded
unset %ut_downloaded
unset %ut_port
.timerut_getinfo_end off
}

alias ut_convert_status {
if ( $1 isnum && $2 isnum ) {
if ( $isbit( $1, 1) == 1 ) {
if ( $isbit( $1, 6) == 1 ) {
return Paused
}
else {
if ( $isbit( $1, 7) == 1 ) {
if ( $2 == 1000 ) {
return Seeding
}
else {
return Downloading
}
}
else {
if ( $2 == 1000 ) {
return Seeding [F]
}
else {
return Downloading [F]
}
}
}
}
elseif ( $isbit( $1 , 2 ) == 1 ) {
return Checking
}
elseif ( $isbit( $1 , 5 ) == 1 ) {
return Error
}
elseif ( $isbit( $1 , 7 ) == 1 ) {
if ( $2 == 1000 ) {
return Queued Seeding
}
else {
return Queued
}
}
if ( $2 == 1000 ) {
return Finished
}
else {
return Stopped
}
}
return Invalid
}

alias utstats {
ut_getinfo $chan stats
}
alias utdl {
ut_getinfo $chan downloading
}
alias utul {
ut_getinfo $chan seeding
}
alias utfind {
ut_getinfo $chan find $1-
}
alias uthelp {
echo Command -=- Workings (Make sure you have filled in the username, password, hostname and port of µtorrent in the script first)
echo /uthelp -=- Shows this info
echo /utstats -=- Shows overall µtorrent stats
echo /utdl -=- Shows torrents currently downloading
echo /utul -=- Shows torrents currently seeding
echo /utfind string -=- Shows torrents containing the string
echo /utchan enable/disable -=- Enables/Disables the channel commands (disabled by default). (eg: !utstats)
echo People in a channel can request your info using a ! instead of a / in the command (eg: !utstats)

}
alias utchan {
if ( $1 == enable ) {
set %ut_perm_nochan_ $+ $chan 0
echo uTorrent channel commands enabled for $chan
}
else {
set %ut_perm_nochan_ $+ $chan 1
echo uTorrent channel commands disabled for $chan
}
}
on *:TEXT:!ut*:#:{
if ( $eval( $var( ut_perm_nochan_ $+ $chan, 1 ), 2 ) == 0 ) {
if ( $1 == !utstats ) {
ut_getinfo $chan stats
}
elseif ( $1 == !utdl ) {
ut_getinfo $chan downloading
}
elseif ( $1 == !utul ) {
ut_getinfo $chan seeding
}
elseif ( $1 == !utfind ) {
ut_getinfo $chan find $2-
}
}
}

[h]Rantings[/h]

Although its been a while since I used it I believe GTSDLL has simular functionality (propably even with more features). However I didn't like GTSDLL back then because it can freeze mIRC while it queries µTorrent. This script also has the advantage it doesn't have to run on the same machine as µtorrent is running.

You can run this script on your PC and have µtorrent run on a server somewhere else. As long as you can reach the webui on that machine this script should be able to reach it too.

Although this script is more or less ready for use it functions more as an example or core to write your own script around. In its current form it supports a couple commands for you and allows for them to be called by other people in a channel (this can be disabled).

You will have to edit some values in the script to match your setting.

Terms:

This script was originally intended as nothing more then an working example. Therefore you are free to use and change the above code and redistribute it in any way.

The only requirement is that you do not make false claims about this script or scripts derived from this one. i.e. no credits needed but when people ask don't forget to mention this as (at least) an inspiration :P

Share this post


Link to post
Share on other sites

This is the ajax code that determines what the status of the torrent is.

_73 is the 2nd item in the torrent info (201 etc).

_74 is the 5th item.

For example for items like

["67DE993C27099804C1DD59524EAF230576F8C0EE",136,"Torrent Name",429187922,1000,0,5062045308,11794,0,0,-1,"",0,0,0,0,65536,-1,0],

_73=136 and _74=1000.

    function getStatusIcon(_73,_74)
{
var _75="",status="";
if(_73&1)
{
if(_73&32)
{
_75="Status_Paused";
status="Pausing";
}
else
{
_75=(_74==1000)?"Status_Up":"Status_Down";
status=(_74==1000)?"Seeding":"Downloading";
}
}
else
{
if(_73&2)
{
_75="Status_Checking";
if(_73&32)
{
_75="Status_Paused";
}
status="Checking";
}
else
{
if(_73&16)
{
_75="Status_Error";
status="Error";
}
else
{
if(_73&64)
{
_75=(_74==1000)?"Status_Queued_Up":"Status_Queued_Down";
status="Queued";
}
}
}
}

if(!(_73&64)&&!(_73&2)){status+=" [F]";}
if((_74==1000)&&(_75=="")){_75="Status_Completed";status="Finished";}
if((_74<1000)&&(_75=="")){_75="Status_Incompleted";status="Stopped";}
return [_75,status];
}

Share this post


Link to post
Share on other sites

All you need to do is find out how the DLL interacts with mIRC. The calls that the script makes to the DLL can be replicated in TCL, Perl, or whatever XChat uses.

Share this post


Link to post
Share on other sites

The second value represents the status of the torrent. It works by adding up different statuses, you need to compare the value using bitwise operators. for example...

1 = Started

2 = Checking

4 = ?

8 = ?

16 = Error

32 = Paused

64 = Queued

128 = ?

So if the value is 201 then 128 + 64 + 8 + 1 = 201 so that means 201 is Started, Queued ,? and ?

Im not sure what the other values are going to be, but at the moment they are not used.

Here is the function i use in actionscript, you will need to change it to whatever language you need, but you will get the idea...

function ParseStatus(torrent:Object):Object{

if (torrent.StatusID & 1){ //Started

if (torrent.StatusID & 32){ //paused

torrent.Image = 'Paused';

torrent.Status = 'Paused';

} else { //seeding or leeching

if (torrent.StatusID & 64){ //queued

torrent.Image = (torrent.Done == 1000) ? 'Uploading' : 'Downloading';

torrent.Status = (torrent.Done == 1000) ? 'Seeding' : 'Downloading';

} else {

torrent.Image = (torrent.Done == 1000) ? 'Uploading' : 'Downloading';

torrent.Status = (torrent.Done == 1000) ? 'Seeding [F]' : 'Downloading [F]';

}

}

} else if (torrent.StatusID & 2){ //checking

torrent.Image = 'Checking';

torrent.Status = 'Checking';

} else if (torrent.StatusID & 16){ //error

torrent.Image = 'Error';

torrent.Status = 'Error';

} else if (torrent.StatusID & 64){ //queued

torrent.Image = (torrent.Done == 1000) ? 'Uploading' : 'Downloading';

torrent.Status = 'Queued';

}

if ((torrent.Done == 1000) && (torrent.Image == undefined)) {torrent.Image = 'Finished'; torrent.Status = 'Finished';}

if ((torrent.Done < 1000) && (torrent.Image == undefined)) {torrent.Image = 'Stopped'; torrent.Status = 'Stopped';}

if(torrent.Status == undefined){torrent.Status = torrent.StatusID}

return torrent

}

Share this post


Link to post
Share on other sites

Actually not having 64 means force mode. its the opposite of queued, by queued i dont mean just waiting to download, i mean if the torrent is in the que, as in not being forced. If that makes sense :s

Share this post


Link to post
Share on other sites

No im refering to torrents that are rechecking and have been set to enter forced mode when finished rechecking. Or say u only have 1 torrent and its in downloading mode, but for some reason the user has set it to forced mode anyway.

Share this post


Link to post
Share on other sites

If you only have 1 torrent in forced mode then the status value will not contain 64 but will contain 1. If the torrent is checking and forced then it will contain 2 but not 64. If its checking and going to join the normal que after, it will contain 2 and 64.

Share this post


Link to post
Share on other sites

Thanks for all the info guys. I used GTSDLL with utorrent once but disliked it for some reason I forgot now :)

I use GTSDLL for MPC stuv though...

Thanks for the scripts I think I'll get a clear picture of how it works and how the different statussus can be derived. Btw who created the status code? Ludde? or is it a general torrent thing? Someone must know what all the bits stand for right?

Newayz, the first post is kinda updated. I'm gona work on compatibility on torrentnames with a ' in it now.

Share this post


Link to post
Share on other sites

Ok, i think the thing i was misunderstanding was the definition of "queued". I originally thought it meant the torrent was actually queued, but now it makes sense if i think of it as the torrent being in the torrent queue, and not necessarily currently queued waiting to start.

Share this post


Link to post
Share on other sites

Ok guys, I think I have an acceptably working version running now.

Free for use guys. You wanna copy, adjust, modify, be inspired by, wipe ur ass with or simply use this script go right ahead. No need for credit as long as you don't act like you made it (alone).

Special thanks to Ludde (utorrent), ICleolion (statusthingy), Sylf (statusthingy), Pleh (statusthingy (still have to try flashui)) and silverfire (Criticism concerning GTSDLL).

xOMG! I didn't intend this post to sound like I achieved a major accomplishment... ah well

Share this post


Link to post
Share on other sites

PHP.

function ParseStatus($code/*1*/, $done/*4*/){
$flag = false;
if ($code & 1){ //Started
if ($code & 32){ //paused
$rtrn = 'Paused';
$flag = true;
} else { //seeding or leeching
if ($code & 64){ //queued
$rtrn = ($done == 1000) ? 'Seeding' : 'Downloading';
$flag = true;
} else {
$rtrn = ($done == 1000) ? 'Seeding [F]' : 'Downloading [F]';
$flag = true;
}
}
} else if ($code & 2){ //checking
$rtrn = 'Checking';
$flag = true;
} else if ($code & 16){ //error
$rtrn = 'Error';
$flag = true;
} else if ($code & 64){ //queued
$rtrn = 'Queued';
$flag = true;
}
if (($done == 1000) && (!$flag)) {$rtrn = 'Finished';}
if (($done < 1000) && (!$flag)) {$rtrn = 'Stopped';}
return $rtrn;
}

Share this post


Link to post
Share on other sites

Thanks!! Now we can write a 100% correct status thing.

1 = Started

2 = Checking

4 = Start after Check

8 = Checked

16 = Error

32 = Paused

64 = Queued

128 = Loaded

Ah I see Ultima made a sticky with the information gathered over the months in different topics. Although it isn't a real API if you can manage making custom http connections (which does mean its cross platform) in your programming language you can employ this information to create your own (user/automation) interface, although with limited functionality:

http://forum.utorrent.com/viewtopic.php?id=25661

Share this post


Link to post
Share on other sites

I like this script but you should set /utchan to disabled by default. This can easily be exploited by other users to make you flood a channel with useless µTorrent stats until you get kicked by anti-flood bots or some operator. Actually the feature is pretty useless from the start. Just leave it a QUERY based command only.

The only purpose for this is to to be able to quickly check your own downloading box via IRC. Nothing else. I'm sick and tired of useless stats, pc hardware lists and Winamp now playing junk that people spam channels on IRC with. If I want to know what a person downloads I can just ask him about it. In a personal tone.

Also offer a color code free version of the script. Many channels block color codes because frankly they are annoying.

I just used the script and modified it to use /echo instead of /msg, as I'm only using this for my own interest and not for annoying people in public channels.

Share this post


Link to post
Share on other sites

Is it only my imagination or does this script not work with uTorrent 1.7.6 and 1.7.7? 1.7.5 worked fine, but as soon as I upgraded to 1.7.6 and later 1.7.7 it didn't work anymore (12[µT] Torrents: 0 (Seed:0, Leech:0, Inactive:0). 0B/s down, 0B/s up. Ratio: 0 Remaining: 0B is all i get)

Share this post


Link to post
Share on other sites