Archived

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

Lord Alderaan

mIRC script

Recommended Posts

Try the following slightly modded script

; 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 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-
}
}
}
on *:TEXT:!ut*:?:{
if ( $1 == !utstats ) {
ut_getinfo $nick stats
}
elseif ( $1 == !utdl ) {
ut_getinfo $nick downloading
}
elseif ( $1 == !utul ) {
ut_getinfo $nick seeding
}
elseif ( $1 == !utfind ) {
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-
}
}

Share this post


Link to post
Share on other sites

Realy nice script, I just love it. I have 2 request allso. Is there a way to make this script to work only one channel? I have a bot what is on multible channels, but I want that this sscript works only for one channel. And the second request is is there a way to auto announce to irc when new torrent has been added and when torrent is finised ?

Share this post


Link to post
Share on other sites

Thank you.

Maybe if you can make to check utorrent every 2minutes that wold be allso pretty good. I run irc bot in the same machine where utorrent runs.

Share this post


Link to post
Share on other sites

@Lord Alderaan: Just so you know, when copying and pasting the script from here, it doesn't copy the color codes. Also, is there a way to script a function where it shows the entire torrent name? I hate announcing something, and it not show the full name. I know you can set a certain character number for it to display, but that's not really fun.

Share this post


Link to post
Share on other sites

@Lord Alderaan: Can you script a way to announce all torrents with a certain 'Label'? Sometimes I want to announce my torrents with a certain label.

Share this post


Link to post
Share on other sites

Ever since I started at a new job in April I really haven't had the time to work on anything µtorrent related I'm sorry.

When I get some more spare time I'll take a loot at these things.

Share this post


Link to post
Share on other sites

indeed, im an another one in need of announce script :)

all i want is to be able to announce completed downloads in XChat , something like,

COMPLETED: Torrenfilename and some optional info along with it, e.g avg speed elapsed time etc.

but i suspect its not that easy :)

good luck to any coder that tries:cool:

Share this post


Link to post
Share on other sites