Utorrent Info Grabber

By joelp53 on Oct 17, 2010

Hey all this is a script i found to be very usefull however it looked terible, so I have edited the layout a little and think it looks really nice, I take no credit for this script and the origianl is here:
http://forum.utorrent.com/viewtopic.php?id=15387
Feel free to do your own thing with it as always,

To use:
It's rather simple realy, First of all open your setting in utorrent and goto the Webui Tab,
When there turn it on And set a username and password, Also On that page there will be a setting called: Alternative listening port, Set that to 8080.

Now paste the script into a new remote and look at the top of it, As you can see there are 4 settings, So Put your Username In the first (Replace username Here)
Put your Pass in the seccond (again replace Pass here)
And leave the port at 8080 as that is already set in utorrent.
The Last setting is for limmiting the ammount of things the script will display, (Id leave it at 3) But it's totally up to you.

Now save and click ok:
To use just type the following comands for the result shown:
/utdl (will display your top 3 Downlaading files)
/utul (will display your top 3 uploads)
/utfind (will find the torrent you search for)
/utstats (Will show a what happening onn your utorrent as a whole, so how many torrents are running what there doing I.E Download,Upload,Idle, Also what your total download upload ect.)

for more info type /uthelp

Please note i have not totally finished editing this script so expect a few updates for other things,

Enjoy :-)

; 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 Here
  ; the password for the webui:
  var %ut_password Password Here
  ; 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 8080

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

  ; -============================ 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 = 10[µT]14 $left(%torrentname,40) 10Status:14 $+ $ut_convert_status( %status , %progress ) 
              var %temp1 = 10Uploaded:14 $+ $bytes( $regml(tor,7) ).suf 10Size:14 $+ $bytes( $regml(tor,4) ).suf 10Ratio:14 $+ $calc( $regml(tor,8) / 1000) 10Upload Speed:14 $+ $bytes( $regml(tor,9) ).suf $+ /s P: $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) S: $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ )
            }
            else {
              var %temp = 10[µT]14 $left(%torrentname,40) 10Status:14 $+ $ut_convert_status( %status , %progress ) 
              var %temp1 = 10Downloaded14: $+ $bytes( $regml(tor,6) ).suf 10Size:14 $+ $bytes( $regml(tor,4) ).suf 10Complete:14 $+ $calc( %progress / 10) $+ $chr(37) 10Download Speed:14 $+ $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
            msg %ut_activechan %temp1
          }
          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 = 10[µT] $left(%torrentname,40) [: $+ $ut_convert_status( %status , %progress )  
          var %temp1 = 10Downloaded:14  $+ $bytes( $regml(tor,6) ).suf :: Uploaded: $+ $bytes( $regml(tor,7) ).suf
          var %temp2 = 10SIZE:14  $+ $bytes( $regml(tor,4) ).suf 10Total Complete:14 $+ $calc( %progress / 10) $+ $chr(37) 
          var %temp3 = 10Upload Speed:14 $+ $bytes( $regml(tor,9) ).suf $+ /s76 
          var %temp4 = 10Download Speed:14  $+ $bytes( $regml(tor,10) ).suf $+ /s 10Peers:14 $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ )  10Seeds:14 $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ ) 10ETA:14 $+ $duration( $regml(tor,11) ) 
          msg %ut_activechan %temp
          msg %ut_activechan %temp1
          msg %ut_activechan %temp2
          msg %ut_activechan %temp3
          msg %ut_activechan %temp4
        }
        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 = 10[µT] $left(%torrentname,40)   
          var %temp4 = 14Upload Speed:10 $+ $bytes( $regml(tor,9) ).suf $+ /s 14Peers:10 $+ $regml(tor,13) $+ ( $+ $regml(tor,14) $+ ) 14Seeders:10 $+ $regml(tor,15) $+ ( $+ $regml(tor,16) $+ )
          msg %ut_activechan %temp
          msg %ut_activechan %temp4
        }
        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 = 10[µT] Total Torrents:14 %ut_torrentcount (10Seeding:14 $+ %ut_seedingcount $+ , 10Leeching:14 $+ %ut_downloadingcount $+ , 10Inactive:14 $+ $calc( %ut_torrentcount - %ut_seedingcount - %ut_downloadingcount ) $+ )
        var %temp1 = 10Download Speed Total:14 $bytes(%ut_download).suf $+ /s ,10Upload Speed Total:14 $bytes(%ut_upload).suf $+ /s up. 10Ratio:14 $round($calc($calc(%ut_ratio_sum / 1000) / %ut_torrentcount),2) , 10Total Remaining:14 $bytes( %ut_remaining ).suf , 10Total Downloaded:14 $bytes( %ut_downloaded ).suf , 10Total Uploaded:14 $bytes( %ut_uploaded ).suf 
      }
      msg %ut_activechan %temp
      msg %ut_activechan %temp1
    }
  }
  else {
        msg %ut_activechan 12[µT] Error: $sock($sockname).wsmsg

  }
  unset %ut_*
  unset %temp* 

  .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

}

Comments

Sign in to comment.
MashhitDK   -  Mar 27, 2012

What you mean ? @ARGGG

 Respond  
ARGGG   -  Jun 30, 2011

this is not reporting stats right what do to fix this?

 Respond  
joelp53   -  Oct 18, 2010

Yeah nice idea bud, i will update it know

Thankyou :-)

 Respond  
Jeroenz0r   -  Oct 18, 2010

The 'unset %ut*' is too generic, this will unset all variables starting with 'ut'
Since all vars have 'ut_' I would suggest:

unset %ut_*
 Respond  
joelp53   -  Oct 17, 2010

Ok i think i sorted it Thanks again :-)

 Respond  
_Teen_   -  Oct 17, 2010

no problem =)

by the way u forgot to unset %temp
on this line

unset %ut*

  .timerut_getinfo_end off
}

and dont need the ; before the message

 Respond  
joelp53   -  Oct 17, 2010

lol Chill man, You sound like your kinda pist of at this haha, i will test the edits first then edit them if it works :-)

Edit: Works like a charm nice adition to the script thankyou.

 Respond  
_Teen_   -  Oct 17, 2010

look dont need type all this

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 %ut_cookie
  unset %ut_token
  unset %ut_uploaded
  unset %ut_downloaded
  unset %ut_port

just put

unset %ut*

by the way its important to ppl know whats the error message

else {
       msg %ut_activechan 12[µT] Error: webui is not responding (socket error).
  }

try use this

else {
      msg %ut_activechan 12[µT] Error: $sock($sockname).wsmsg
  }

it will return the last message error

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.