alias radyo.kanal {
  return #radyo
}
alias radyo.host {
  return 84.16.253.231
}
alias radyo.port {
  return 8364
}
alias radyo.adminpass {
  return benimradyom
}
alias radyo.sock {
  return shoutcast
}
alias getxmltext {
  var %tag.open = $+(<, $1, >)
  var %tag.close = $+(</, $1, >)
  if $pos($2-,%tag.open) {
    var %start = $ifmatch + $len(%tag.open)
    var %length  = $calc($pos($2-, %tag.close) - %start)
    return $mid($2-, %start, %length)
  }
  return $null
}
on 1:SOCKOPEN:$($radyo.sock): {
  sockwrite -n $sockname GET $+(/admin.cgi?pass=,$radyo.adminpass,&mode=viewxml HTTP/1.1)
  sockwrite -n $sockname Host: $+($radyo.host, :, $radyo.port)
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040614 Firefox/0.8
  sockwrite -n $sockname *.*, */*
  ; sockwrite -n $sockname Accept-Language: en-us,en;q=0.5
  sockwrite -n $sockname Accept-Language: tr,tr;q=0.5
  sockwrite -n $sockname Accept-Encoding: gzip,deflate
  sockwrite -n $sockname Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  sockwrite -n $sockname Keep-Alive: 300
  sockwrite -n $sockname Connection: keep-alive
  sockwrite -n $sockname $crlf
}
on 1:SOCKREAD:$($radyo.sock): {
  var %data
  sockread -f %data
  while $sockbr > 0 && $sockerr == 0 {
    if $getxmltext(SERVERTITLE, %data) != $null {
      set %servertitle $remove($ifmatch,&#xFF;,&#x26;)
    }
    if $getxmltext(CURRENTLISTENERS, %data) != $null {
      set %currentlisteners $ifmatch
    }
    if $getxmltext(SONGTITLE, %data) != $null {
      set %songtitle $remove($ifmatch,&#xFF;,&#x26;)
    }
    if $getxmltext(BITRATE, %data) != $null {
      set %bitrate $ifmatch
    }
    if $getxmltext(PEAKLISTENERS, %data) != $null {
      set %peaklisteners $ifmatch
    }
    if $getxmltext(SERVERGENRE, %data) != $null {
      set %genre $remove($ifmatch,&#xFF;,&#x26;)
    }
    sockread -f %data
  }
}
on 1:SOCKCLOSE:$($radyo.sock): {
  if %songtitle != %lastsong {
    set %lastsong %songtitle
    var %msg = 0,4 %genre su anda online 0,2 Siradaki parca: %songtitle 0,6 Su anda %currentlisteners kisi dinliyor (rekor: %peaklisteners $+ ) 
    set %msg2 0,4 %genre su anda online 0,2 Siradaki parca: %songtitle 0,4<< 0,5 Radyomuzu dinlemek icin tiklayin 0,4 >>  http://84.16.253.231:8364/listen.pls
    msg $radyo.kanal Yayinda su an << $+ %genre $+ >> bulunmakta. * Yayin turu: %servertitle * Calan parca: >>>>> %songtitle <<<<<
    msg $radyo.kanal %msg
  }
}
alias shout {
  if $sock(shoutcast) {
    sockclose $ifmatch
  }
  sockopen $radyo.sock $radyo.host $radyo.port
}
on 1:text:*:#radyo:{
  if *!durum* iswm $1- {
    set -u10 %durum 1
    unset %lastsong
    shout
  }
}
