Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
REG 11.18 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 admin
  11.  
  12.   ; the password for the webui:
  13.   var %ut_password admin
  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 40004
  20.  
  21.   ; OPTIONAL! maximum number of displayed torrentlines (not counting header and footer):
  22.   set %ut_flood_max 5
  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 12[µT] Showing the first %ut_flood_max torrents containing $3-
  42.     }
  43.     elseif ( %ut_action == downloading ) {
  44.       ;      msg %ut_activechan 12[µT] Showing the first %ut_flood_max torrents downloading.
  45.     }
  46.     elseif ( %ut_action == seeding ) {
  47.       ;      msg %ut_activechan 12[µ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 = 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) $+ )
  159.             }
  160.             else {
  161.               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) )
  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 = 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) )
  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 = 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
  197.       }
  198.       else {
  199.         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
  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.  
  281. alias utstats {
  282.   ut_getinfo $chan stats
  283. }
  284. alias utdl {
  285.   ut_getinfo $chan downloading
  286. }
  287. alias utul {
  288.   ut_getinfo $chan seeding
  289. }
  290. alias utfind {
  291.   ut_getinfo $chan find $1-
  292. }
  293. alias uthelp {
  294.   echo Command -=- Workings (Make sure you have filled in the username, password, hostname and port of µtorrent in the script first)
  295.   echo /uthelp -=- Shows this info
  296.   echo /utstats -=- Shows overall µtorrent stats
  297.   echo /utdl -=- Shows torrents currently downloading
  298.   echo /utul -=- Shows torrents currently seeding
  299.   echo /utfind string -=- Shows torrents containing the string
  300.   echo /utchan enable/disable -=- Enables/Disables the channel commands (disabled by default). (eg: !utstats)
  301.   echo People in a channel can request your info using a ! instead of a / in the command (eg: !utstats)
  302.  
  303. }
  304. alias utchan {
  305.   if ( $1 == enable ) {
  306.     set %ut_perm_nochan_ $+ $chan 0
  307.     echo uTorrent channel commands enabled for $chan
  308.   }
  309.   else {
  310.     set %ut_perm_nochan_ $+ $chan 1
  311.     echo uTorrent channel commands disabled for $chan
  312.   }
  313. }
  314. on *:TEXT:!ut*:#:{
  315.   if ( $eval( $var( ut_perm_nochan_ $+ $chan, 1 ), 2 ) == 0 ) {
  316.     if ( $1 == !utstats ) {
  317.       ut_getinfo $chan stats
  318.     }
  319.     elseif ( $1 == !utdl ) {
  320.       ut_getinfo $chan downloading
  321.     }
  322.     elseif ( $1 == !utul ) {
  323.       ut_getinfo $chan seeding
  324.     }
  325.     elseif ( $1 == !utfind ) {
  326.       ut_getinfo $chan find $2-
  327.     }
  328.   }
  329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement