; 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 USERNAME             ; the password for the webui:       var %ut_password PASSWORD             ; 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 PORT             ; OPTIONAL! maximum number of displayed torrentlines (not counting header and footer):       set %ut_flood_max 0             ; -============================ 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 4[µT] Showing the first %ut_flood_max torrents containing $3-         }         elseif ( %ut_action == downloading ) {           ;      msg %ut_activechan 4[µT] Showing the first %ut_flood_max torrents downloading.         }         elseif ( %ut_action == seeding ) {           ;      msg %ut_activechan 4[µ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,/]*id=["\']token["\'][^>]*>([^<]*)/) > 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 = 3[µT]14 $left(%torrentname,40) $ut_convert_status( %status , %progress ) 4UP: $+ $bytes( $regml(tor,7) ).suf 11SIZE: $+ $bytes( $regml(tor,4) ).suf 11R: $+ $calc( $regml(tor,8) / 1000) 11UL: $+ $bytes( $regml(tor,9) ).suf $+ /s 11P: $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) 11S: $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ )                 }                 else {                   var %temp = 3[µT]14 $left(%torrentname,40)  $ut_convert_status( %status , %progress ) 4DOWN: $+ $bytes( $regml(tor,6) ).suf 4SIZE: $+ $bytes( $regml(tor,4) ).suf 11P: $+ $calc( %progress / 10) $+ $chr(37) 11DL: $+ $bytes( $regml(tor,10) ).suf $+ /s 11P: $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) 11S: $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ ) 4ETA: $+ $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 = 3[µT]14 $left(%torrentname,40) $ut_convert_status( %status , %progress ) 4DOWN: $+ $bytes( $regml(tor,6) ).suf 11SIZE: $+ $bytes( $regml(tor,4) ).suf 11P: $+ $calc( %progress / 10) $+ $chr(37) 4DL: $+ $bytes( $regml(tor,10) ).suf $+ /s 11P: $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) 11S: $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ ) 4ETA: $+ $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 = 4[µ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 = 3[µT] 8Torrents: %ut_torrentcount (Seeding: %ut_seedingcount $+ , Leeching: %ut_downloadingcount $+ , Inactive: $calc( %ut_torrentcount - %ut_seedingcount - %ut_downloadingcount ) $+ ). 4Download Speed: $bytes(%ut_download).suf $+ /s 4Upload Speed: $bytes(%ut_upload).suf $+ /s up. 11Downloaded: $bytes( %ut_downloaded ).suf 11Uploaded: $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 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:!dt*:#:{       if ( $eval( $var( ut_perm_nochan_ $+ $chan, 1 ), 2 ) == 0 ) {         if ( $1 == !dtstats ) {           ut_getinfo $chan stats         }         elseif ( $1 == !dtdl ) {           ut_getinfo $chan downloading         }         elseif ( $1 == !dtul ) {           ut_getinfo $chan seeding         }         elseif ( $1 == !dtfind ) {           ut_getinfo $chan find $2-         }       }     }     on *:TEXT:!dt*:?:{       if ( $1 == !dtstats ) {         ut_getinfo $nick stats       }       elseif ( $1 == !dtdl ) {         ut_getinfo $nick downloading       }       elseif ( $1 == !dtul ) {         ut_getinfo $nick seeding       }       elseif ( $1 == !dtfind ) {         ut_getinfo $nick find $2-       }     }     alias utstats {       if ( $chan == $null ) {         ut_getinfo $nick stats       }       else {         ut_getinfo $chan stats       }     }     alias utdl {       if ( $chan == $null ) {         ut_getinfo $nick downloading       }       else {         ut_getinfo $chan downloading       }     }     alias utul {       if ( $chan == $null ) {         ut_getinfo $nick seeding       }       else {         ut_getinfo $chan seeding       }     }     alias utfind {       if ( $chan == $null ) {         ut_getinfo $nick find $1-       }       else {         ut_getinfo $chan find $1-       }     }           ; -================================ RIGHT-CLICK MENU ===============================- ;           Menu Channel {       -       µTorrent       .$iif($menu != Menu Channel,Stats): /utstats       .$iif($menu != Menu Channel,Download): /utdl       .$iif($menu != Menu Channel,Upload): /utul       .$iif($menu != Menu Channel,Find): { /utfind $$?="Enter Search String" }       .Channels       ..$iif($menu != Menu Channel,Enable Channel): { /utchan enable }       ..$iif($menu != Menu Channel,Disable Channel): { /utchan disable }       .$iif($menu != Menu Channel,Help): /uthelp       -     }