All pastes #1822190 Raw Edit

lol

public text v1 · immutable
#1822190 ·published 2010-03-04 02:47 UTC
rendered paste body
on *:text:*:#scc-announce: {
  tokenize 32 $strip($1-)
  if (!$readini(scc.ini,options,enabled)) || (NEW in *: -> * !iswm $1-) || ($nick != SCC) || ($site != csops.sceneaccess.org) { halt }
  var %section = $replace($mid($3-,0,$calc($pos($3,:)-1)),$chr(32),_)
  var %rls = $gettok($mid($1-,$pos($1-,->)),2,32)
  var %t = $findtok($1-,KB $+ $chr(41),1,32) $+ $findtok($1-,MB $+ $chr(41),1,32) $+ $findtok($1-,GB $+ $chr(41),1,32)
  var %size = $left($right($gettok($1-,$calc(%t - 1) - %t,32),-1),-1)
  var %url = $left($right($mid($1-,$pos($1-,$chr(40) $+ http://)),-1),-1)

  if (!$readini(scc.ini,%section,filters)) { halt }
  var %x = 1
  while ($gettok($readini(scc.ini,%section,filters),%x,59)) {
    if ($v1 iswm %rls) {
      if ($readini(scc.ini,%section,sizefilter)) {
        if ($left($readini(scc.ini,%section,sizefilter),1) == <) && ($convert2mb(%size) < $right($readini(scc.ini,%section,sizefilter),-2)) {
          dltorrent %url %rls
        }
        if ($left($readini(scc.ini,%section,sizefilter),1) == >) && ($convert2mb(%size) > $right($readini(scc.ini,%section,sizefilter),-2)) {
          dltorrent %url %rls
        }
        halt
      }
      dltorrent %url %rls
      halt
    }
    inc %x
  }
}

alias convert2mb {
  tokenize 32 $1-
  if (!$2) { return }
  if ($2 == KB) { return $calc($1 / 1024) }
  if ($2 == MB) { return $1 }
  if ($2 == GB) { return $calc($1 * 1024) }
  else { return 0 }
}

alias dltorrent {
  if (!$window(@SCC)) { window -k0n @SCC }
  if (!$dir($readini(scc.ini,options,torrentdir))) { mkdir $readini(scc.ini,options,torrentdir) }
  var %url = sceneaccess.org /download2.php/ $+ $gettok($1,2,61) $+ / $+ $readini(scc.ini,options,passkey) $+ / $+ $2 $+ .torrent
  aline @SCC $time(hh:nn:ss TT) $+ : downloading %url

  if ($readini(scc.ini,webui,enabled)) {
    utorrent.add $readini(scc.ini,webui,ip) $readini(scc.ini,webui,port) $readini(scc.ini,webui,username) $readini(scc.ini,webui,password) $remove(http:// $+ %url,$chr(32))
    return
  }

  if ($file($readini(scc.ini,options,torrentdir) $+ \ $+ $2 $+ .torrent)) {
    aline @SCC $time(hh:nn:ss TT) $+ : $2 $+ .torrent already exists
    return
  }

  tr.download %url
}

alias utorrent.add {
  if (!$5) { return }
  var %sockname ut.add. $+ $rand(1,999999)
  sockopen %sockname $1 $2
  sockmark %sockname $3-
}

on *:sockopen:ut.add.*:{
  if ($sockerr) {
    aline @SCC $time(hh:nn:ss TT) $+ : Error connecting to WebUI
    halt
  }
  sockwrite -t $sockname GET /gui/?action=add-url&s= $+ $gettok($sock($sockname).mark, 3-, 32) HTTP/1.1
  sockwrite -t $sockname Host: $sock($sockname).addr $+ : $+ $sock($sockname).port $+ $crlf
  sockwrite -t $sockname Authorization: Basic $encode($replace($gettok($sock($sockname).mark, 1-2, 32), $chr(32), :), m) $+ $crlf
  sockwrite -t $sockname $crlf
  sockclose $sockname
}

; /download <HOST> <FILE>
;  Downloads a file from the Internet
;  By oMri^^ - v1.1
alias tr.download {
  var %socket $left($+(dl,$chr(46),$nopath($2)),90)
  if (!$sock(%socket)) {
    sockopen %socket $1 80
    sockmark %socket HEAD $1 $2
    ; You'd have to parse the SOCKMARK like this:
    ; $1 = GET|HEAD - When using head, you sockread the data header. Choosing get, downloads.
    ; $2 = HOST     - File name you're downloading.
    ; $3 = FILE     - Host to download from.
  }
}

on *:SOCKOPEN:dl.*:{
  if ($sockerr) { 
    aline @scc $time(hh:nn:ss TT) $+ : Error: $sock($sockname).wsmsg 
    return
  }
  hadd -m ticks $sockname $ticks
  var %file = $nopath($gettok($sock($sockname).mark,3,32)), %fullfile = $+(",$readini(scc.ini,options,torrentdir) $+ \,%file,"), %sckr = sockwrite -n $sockname, %^ = $gettok($sock($sockname).mark,3,32)
  write -c %fullfile
  %sckr GET $iif(left(%^,1) != $chr(47),$chr(47) $+ %^,%^) HTTP/1.0
  %sckr HOST: $gettok($sock($sockname).mark,2,32)
  %sckr ACCEPT: *.*
  %sckr $crlf
}

on *:SOCKREAD:dl.*:{
  if ($sockerr) {
    aline @scc $time(hh:nn:ss TT) $+ : Error: $sock($sockname).wsmsg
    return
  }
  var %a
  :begin
  if ($gettok($sock($sockname).mark,1,32) == head) { sockread %a }
  else { sockread &b }
  if ($sockbr) {
    tokenize 32 $sock($sockname).mark
    if ($1 == HEAD) {
      if (%a) {
        if ($gettok(%a,1,32) == Content-Length:) { var %totsize = $gettok(%a,2,32) }
      }
      else {
        sockmark $sockname GET $2- %totsize
      }
    }
    elseif ($1 == GET) {
      var %file = $+(",$readini(scc.ini,options,torrentdir) $+ \,$nopath($3),"), %cursize = $file(%file).size
      var %totsize = $gettok($sock($sockname).mark,4,32)
      bwrite %file -1 &b
    }
    goto begin
  }
}

on *:SOCKCLOSE:dl.*:{
  var %ticks = $calc(($ticks - $hget(ticks,$sockname)) /1000)
  aline @SCC $time(hh:nn:ss TT) $+ : downloaded $nopath($gettok($sock($sockname).mark,3,32)) in %ticks seconds.
  run $readini(scc.ini,options,torrentdir) $+ \ $+ $nopath($gettok($sock($sockname).mark,3,32))
}