Shoutcast status script

From Scriptwiki
Revision as of 20:33, 27 November 2005 by Albie (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Do you have an aspiring web-radio? You can use this script to tell your listeners what song they're currently listening to and how many other users are enjoying your show.

; Using this on TEXT event we can react to users who
; write !status in your channel. Do not forget to replace #your-channel
; with your actual channel
on *:text:!status:#your-channel:{
  ; We store the channel's name in a variable so we know where to send
  ; the replies to.
  set %radiochan $chan

  ; Open a connection to the radio's web-server.
  ; Replace 'your-radio.example.org' with your radio's host
  ; and 8000 with its actual port.
  sockopen getsong your-radio.example.org 8000
}

; The webserver has accepted our connection attempt.
on *:SOCKOPEN:getsong: {
  ; We will now send a simple HTTP request to collect statistics about the radio.
  sockwrite -n $sockname GET /7 HTTP/1.0
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8a2) Gecko
  sockwrite -n $sockname
}

; This gets triggered when the webserver replies to our HTTP request.
on *:SOCKREAD:getsong: {
  ; Read a single line from the response and store it in %sctext
  sockread %sctext

  ; While there's still remaining data in the response...
  while ($sockbr) {
    ; ... read it ...
    sockread -f %sctext
    ; and append it to %a
    var %a = %a %sctext
  }

  ; Check whether we've found the right line in the response
  ; The line should be like <html><body>information about the stream</body></html>
  if (<body> isin %a) {
    ; Extract the information from %a
    ; .echo -q will tell mirc not to show the result of $regex
    .echo -q $regex(%a, /<body>(.*)</body>/)

    ; Use /msg to tell the users about the stream's status.
    if (%radiochan) { msg %radiochan $regml(1) }
  }
}