Advertisement
anon

utorrent

Apr 2nd, 2012
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 13.71 KB | None | 0 0
  1.     ; type /uthelp for info
  2.      
  3.     alias ut_getinfo {
  4.      
  5.       ; Incarnation: 2010-03-04 17:00
  6.      
  7.       ; -============================ CHANGE THE VALUES BELOW ============================- ;
  8.      
  9.       ; the username for the webui:
  10.       var %ut_username USERNAME
  11.      
  12.       ; the password for the webui:
  13.       var %ut_password PASSWORD
  14.      
  15.       ; the hostname or ip of the machine running µtorrent, if µtorrent + webui is running on the same computer leave it at localhost:
  16.       set -n %ut_url localhost
  17.      
  18.       ; µtorrent port (or the alternative webui port if activated):
  19.       set -n %ut_port PORT
  20.      
  21.       ; OPTIONAL! maximum number of displayed torrentlines (not counting header and footer):
  22.       set %ut_flood_max 0
  23.      
  24.       ; -============================ CHANGE THE VALUES ABOVE ============================- ;
  25.      
  26.       var %continue $false
  27.       if ( $sock(ut_info).to ) {
  28.         if ( $sock(ut_info).to > 25 ) {
  29.           ut_getinfo_end
  30.           %continue = $true
  31.         }
  32.       }
  33.       else {
  34.         %continue = $true
  35.       }
  36.       if ( %continue == $true && $1 && $2 ) {
  37.         set %ut_activechan $1
  38.         set %ut_action $2
  39.         if ( %ut_action == find && $3 ) {
  40.           set %ut_find_string $3-
  41.           ;      msg %ut_activechan 4[µT] Showing the first %ut_flood_max torrents containing $3-
  42.         }
  43.         elseif ( %ut_action == downloading ) {
  44.           ;      msg %ut_activechan 4[µT] Showing the first %ut_flood_max torrents downloading.
  45.         }
  46.         elseif ( %ut_action == seeding ) {
  47.           ;      msg %ut_activechan 4[µT] Showing the first %ut_flood_max torrents seeding.
  48.         }
  49.         set %ut_credentials $encode(%ut_username $+ : $+ %ut_password,m)
  50.         set %ut_download 0
  51.         set %ut_downloadingcount 0
  52.         set %ut_err_torrents 0
  53.         set %ut_flood_count 0
  54.         set %ut_ratio_sum 0
  55.         set %ut_remaining 0
  56.         set %ut_seedingcount 0
  57.         set %ut_sockerr 0
  58.         set %ut_torrentcount 0
  59.         set %ut_upload 0
  60.         set %ut_downloaded
  61.         set %ut_uploaded
  62.         .timerut_getinfo_end 1 20 ut_getinfo_end
  63.         sockopen ut_token %ut_url %ut_port
  64.       }
  65.     }
  66.      
  67.      
  68.     on 1:SOCKOPEN:ut_token:{
  69.       if ( $sockerr > 0 ) {
  70.         %ut_sockerr = $sockerr
  71.         ut_getinfo_end
  72.         return
  73.       }
  74.       sockwrite -n $sockname GET /gui/token.html HTTP/1.1
  75.       sockwrite -n $sockname Host: $+(%ut_url,:,%ut_port)
  76.       sockwrite -n $sockname Authorization: Basic %ut_credentials
  77.       sockwrite -n $sockname $crlf
  78.     }
  79.      
  80.     on 1:SOCKREAD:ut_token:{
  81.       if ( $sockerr > 0 ) {
  82.         %ut_sockerr = $sockerr
  83.         echo ow: $sockerr
  84.         ut_getinfo_end
  85.         return
  86.       }
  87.       var %i 1
  88.       while (%i > 0 ) {
  89.         sockread -f %temp
  90.         if ( Set-Cookie: isin %temp ) {
  91.           if ( $regex(ut_re_c,%temp,/GUID=([^; ]*)/) > 0 ) {
  92.             set %ut_cookie $regml(ut_re_c,1)
  93.           }
  94.         }
  95.         if ( $+(id,$chr(61),$chr(34),token,$chr(34)) isin %temp || $+(id,$chr(61),$chr(39),token,$chr(39)) isin %temp ) {
  96.           if ( $regex(ut_re,%temp,/<div[^>]*id=["\']token["\'][^>]*>([^<]*)</div>/) > 0 ) {
  97.             set %ut_token $regml(ut_re,1)
  98.             sockopen ut_info %ut_url %ut_port
  99.             sockclose ut_token
  100.           }
  101.         }
  102.         %i = $sockbr
  103.       }
  104.     }
  105.      
  106.     on 1:SOCKOPEN:ut_info:{
  107.       if ( $sockerr > 0 ) {
  108.         %ut_sockerr = $sockerr
  109.         ut_getinfo_end
  110.         return
  111.       }
  112.       sockwrite -n $sockname GET /gui/?list=1&token= $+ %ut_token HTTP/1.1
  113.       sockwrite -n $sockname Host: $+(%ut_url,:,%ut_port)
  114.       sockwrite -n $sockname Cookie: GUID= $+ %ut_cookie
  115.       sockwrite -n $sockname Authorization: Basic %ut_credentials
  116.       sockwrite -n $sockname $crlf
  117.       unset %ut_credentials
  118.       unset %ut_url
  119.     }
  120.      
  121.     on 1:SOCKREAD:ut_info:{
  122.       if ( $sockerr > 0 ) {
  123.         %ut_sockerr = $sockerr
  124.         ut_getinfo_end
  125.         return
  126.       }
  127.       sockread %temp
  128.       if ( $left(%temp,12) == ,"torrentc": ) {
  129.         ut_getinfo_end
  130.       }
  131.       else {
  132.         var %pattern = \["(\w*)",(\d*),"(.*)",(\d*),(\d*),(\d*),(\d*),(\d*),(\d*),(\d*),(-?\d*),"(.*)",(\d*),(\d*),(\d*),(\d*),(\d*),(-?\d*),(\d*)[\]|,]
  133.         if ( $regex(tor,%temp,%pattern) ==  1 ) {
  134.           var %hash = $regml(tor,1)
  135.           var %status $regml(tor,2)
  136.           var %torrentname = $regml(tor,3)
  137.           var %progress $regml(tor,5)
  138.           var %label = $regml(tor,12)
  139.           inc %ut_torrentcount
  140.           inc %ut_remaining $regml(tor,19)
  141.           inc %ut_download $regml(tor,10)
  142.           inc %ut_upload $regml(tor,9)
  143.           inc %ut_downloaded $regml(tor,6)
  144.           inc %ut_uploaded $regml(tor,7)
  145.           inc %ut_ratio_sum $regml(tor,8)
  146.           if ( $isbit(%status,1) == 1 && $isbit(%status,6) == 0 ) {
  147.             if ( %progress == 1000 ) {
  148.               inc %ut_seedingcount
  149.             }
  150.             else {
  151.               inc %ut_downloadingcount
  152.             }
  153.           }
  154.           if ( %ut_action == find ) {
  155.             if ( %ut_find_string isin %torrentname ) {
  156.               if ( %ut_flood_count < %ut_flood_max ) {
  157.                 if ( %progress == 1000 ) {
  158.                   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) $+ )
  159.                 }
  160.                 else {
  161.                   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) )
  162.                 }
  163.                 msg %ut_activechan %temp
  164.               }
  165.               inc %ut_flood_count
  166.             }
  167.           }
  168.           elseif ( %ut_action == downloading && %progress < 1000 && $isbit(%status,1) == 1 && $isbit(%status,6) == 0) {
  169.             if ( %ut_flood_count < %ut_flood_max ) {
  170.               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) )
  171.               msg %ut_activechan %temp
  172.             }
  173.             inc %ut_flood_count
  174.           }
  175.           elseif ( %ut_action == seeding && %progress == 1000 && $isbit(%status,1) == 1 && $isbit(%status,6) == 0 ) {
  176.             if ( %ut_flood_count < %ut_flood_max ) {
  177.               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) $+ )
  178.               msg %ut_activechan %temp
  179.             }
  180.             inc %ut_flood_count
  181.           }
  182.         }
  183.       }
  184.       unset %temp
  185.     }
  186.      
  187.     alias ut_getinfo_end {
  188.       sockclose ut_token
  189.       sockclose ut_info
  190.       if ( %ut_sockerr == 0 ) {
  191.         if ( %ut_action == find || %ut_action == downloading || %ut_action == seeding ) {
  192.           ;      msg %ut_activechan 12[µT] Found %ut_flood_count torrents.
  193.         }
  194.         if ( %ut_action == stats ) {
  195.           if ( %ut_err_torrents > 0 ) {
  196.             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
  197.           }
  198.           else {
  199.             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
  200.           }
  201.           msg %ut_activechan %temp
  202.         }
  203.       }
  204.       else {
  205.         ;    msg %ut_activechan 12[µT] Error: webui is not responding (socket error).
  206.       }
  207.       unset %ut_action
  208.       unset %ut_activechan
  209.       unset %ut_credentials
  210.       unset %ut_download
  211.       unset %ut_downloadingcount
  212.       unset %ut_err_torrents
  213.       unset %ut_find_string
  214.       unset %ut_flood_max
  215.       unset %ut_flood_count
  216.       unset %ut_ratio_sum
  217.       unset %ut_remaining
  218.       unset %ut_seedingcount
  219.       unset %ut_sockerr
  220.       unset %ut_torrentcount
  221.       unset %ut_url
  222.       unset %ut_upload
  223.       unset %temp
  224.       unset %ut_cookie
  225.       unset %ut_token
  226.       unset %ut_uploaded
  227.       unset %ut_downloaded
  228.       unset %ut_port
  229.       .timerut_getinfo_end off
  230.     }
  231.      
  232.     alias ut_convert_status {
  233.       if ( $1 isnum && $2 isnum ) {
  234.         if ( $isbit( $1, 1) == 1 ) {
  235.           if ( $isbit( $1, 6) == 1 ) {
  236.             return Paused
  237.           }
  238.           else {
  239.             if ( $isbit( $1, 7) == 1 ) {
  240.               if ( $2 == 1000 ) {
  241.                 return Seeding
  242.               }
  243.               else {
  244.                 return Downloading
  245.               }
  246.             }
  247.             else {
  248.               if ( $2 == 1000 ) {
  249.                 return Seeding [F]
  250.               }
  251.               else {
  252.                 return Downloading [F]
  253.               }
  254.             }
  255.           }
  256.         }
  257.         elseif ( $isbit( $1 , 2 ) == 1 ) {
  258.           return Checking
  259.         }
  260.         elseif ( $isbit( $1 , 5 ) == 1 ) {
  261.           return Error
  262.         }
  263.         elseif ( $isbit( $1 , 7 ) == 1 ) {
  264.           if ( $2 == 1000 ) {
  265.             return Queued Seeding
  266.           }
  267.           else {
  268.             return Queued
  269.           }
  270.         }
  271.         if ( $2 == 1000 ) {
  272.           return Finished
  273.         }
  274.         else {
  275.           return Stopped
  276.         }
  277.       }
  278.       return Invalid
  279.     }
  280.     alias uthelp {
  281.       echo Command -=- Workings (Make sure you have filled in the username, password, hostname and port of µtorrent in the script first)
  282.       echo /uthelp -=- Shows this info
  283.       echo /utstats -=- Shows overall µtorrent stats
  284.       echo /utdl -=- Shows torrents currently downloading
  285.       echo /utul -=- Shows torrents currently seeding
  286.       echo /utfind string -=- Shows torrents containing the string
  287.       echo /utchan enable/disable -=- Enables/Disables the channel commands (disabled by default). (eg: !utstats)
  288.       echo People in a channel can request your info using a ! instead of a / in the command (eg: !utstats)
  289.      
  290.     }
  291.     alias utchan {
  292.       if ( $1 == enable ) {
  293.         set %ut_perm_nochan_ $+ $chan 0
  294.         echo uTorrent channel commands enabled for $chan
  295.       }
  296.       else {
  297.         set %ut_perm_nochan_ $+ $chan 1
  298.         echo uTorrent channel commands disabled for $chan
  299.       }
  300.     }
  301.     on *:TEXT:!dt*:#:{
  302.       if ( $eval( $var( ut_perm_nochan_ $+ $chan, 1 ), 2 ) == 0 ) {
  303.         if ( $1 == !dtstats ) {
  304.           ut_getinfo $chan stats
  305.         }
  306.         elseif ( $1 == !dtdl ) {
  307.           ut_getinfo $chan downloading
  308.         }
  309.         elseif ( $1 == !dtul ) {
  310.           ut_getinfo $chan seeding
  311.         }
  312.         elseif ( $1 == !dtfind ) {
  313.           ut_getinfo $chan find $2-
  314.         }
  315.       }
  316.     }
  317.     on *:TEXT:!dt*:?:{
  318.       if ( $1 == !dtstats ) {
  319.         ut_getinfo $nick stats
  320.       }
  321.       elseif ( $1 == !dtdl ) {
  322.         ut_getinfo $nick downloading
  323.       }
  324.       elseif ( $1 == !dtul ) {
  325.         ut_getinfo $nick seeding
  326.       }
  327.       elseif ( $1 == !dtfind ) {
  328.         ut_getinfo $nick find $2-
  329.       }
  330.     }
  331.     alias utstats {
  332.       if ( $chan == $null ) {
  333.         ut_getinfo $nick stats
  334.       }
  335.       else {
  336.         ut_getinfo $chan stats
  337.       }
  338.     }
  339.     alias utdl {
  340.       if ( $chan == $null ) {
  341.         ut_getinfo $nick downloading
  342.       }
  343.       else {
  344.         ut_getinfo $chan downloading
  345.       }
  346.     }
  347.     alias utul {
  348.       if ( $chan == $null ) {
  349.         ut_getinfo $nick seeding
  350.       }
  351.       else {
  352.         ut_getinfo $chan seeding
  353.       }
  354.     }
  355.     alias utfind {
  356.       if ( $chan == $null ) {
  357.         ut_getinfo $nick find $1-
  358.       }
  359.       else {
  360.         ut_getinfo $chan find $1-
  361.       }
  362.     }
  363.      
  364.     ; -================================ RIGHT-CLICK MENU ===============================- ;
  365.      
  366.     Menu Channel {
  367.       -
  368.       µTorrent
  369.       .$iif($menu != Menu Channel,Stats): /utstats
  370.       .$iif($menu != Menu Channel,Download): /utdl
  371.       .$iif($menu != Menu Channel,Upload): /utul
  372.       .$iif($menu != Menu Channel,Find): { /utfind $$?="Enter Search String" }
  373.       .Channels
  374.       ..$iif($menu != Menu Channel,Enable Channel): { /utchan enable }
  375.       ..$iif($menu != Menu Channel,Disable Channel): { /utchan disable }
  376.       .$iif($menu != Menu Channel,Help): /uthelp
  377.       -
  378.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement