/*
* Shoutcast checker by KnickLighter
* Version: 1.0b
* Please let me know about any bugs!
* irc.knicklighter.nl / #home
*/
;Shoutcast menu on right-click
menu * {
;Display button
Shoutcast Check:dialog -m shoutcast shoutcast
}
;Dialog
dialog shoutcast {
title "Shoutcast Info"
size -1 -1 150 168
option dbu
list 1, 10 10 90 70, size vsbar
box "Servers", 2, 1 1 148 85
button "Add", 3, 105 11 37 12
button "Delete", 4, 105 25 37 12
button "Check", 5, 105 68 37 12
box "Stream information", 6, 1 90 148 60
text "Song:", 7, 5 101 25 8
text "Listeners:", 8, 5 113 25 8
edit "", 9, 35 100 110 10, read autohs
text "%listen", 10, 35 113 25 8
text "Unique:", 11, 70 113 25 8
text "%unique", 12, 100 113 25 8
text "Peak:", 13, 5 125 25 8
text "%peak", 14, 35 125 25 8
text "Max:", 15, 70 125 25 8
text "%max", 16, 100 125 25 8
text "Bitrate:", 17, 5 137 25 8
text "%bitrate", 18, 35 137 25 8
text "", 19, 105 50 37 8, center
button "Copy", 20, 3 153 37 12
button "Close", 21, 110 153 37 12
}
;Dialog event
on *:dialog:shoutcast:*:*:{
if ($devent == init) {
;Commands to when dialog has opened
did -ra $dname 9
did -ra $dname 10
did -ra $dname 12
did -ra $dname 14
did -ra $dname 16
did -ra $dname 18
unset %shout.*
shout.reloadlist
halt
}
if ($devent == sclick) {
;Single click on a button
if ($did == 3) {
;When clicking the add button
var %sname = $input(Please enter the stream name $crlf $crlf $+ e.g. MyStream,qecd,Stream Name)
if (%sname == $null) { var %err = $input(You have not entered a stream name!,hod,Error!) | goto canceladd }
var %surl = $input(Please enter the stream URL $crlf $crlf $+ e.g. stream.mydomain.com:8000,qecd,Stream Name)
if (%surl == $null) { var %err = $input(You have not entered a stream URL!,hod,Error!) | goto canceladd }
writeini sservers.ini streams $replace(%sname,$chr(32),_) %surl
shout.reloadlist
:canceladd
halt
}
if ($did == 4) {
;When clicking the delete button
if ($did(1).seltext == $null) { var %err = $input(You have not selected a stream name to delete!,hod,Error!) | halt }
if ($readini(sservers.ini,streams,$replace($did(1).seltext,$chr(160),_)) == $null) { var %err = $input(Error deleting stream name!,hod,Error!) | halt }
remini sservers.ini streams $replace($did(1).seltext,$chr(160),_)
var %msg = $input(Stream successfully deleted.,iod,Delete successful)
shout.reloadlist
halt
}
if ($did == 5) {
;When clicking the Check button
if ($did(1).seltext == $null) { var %err = $input(You have not selected a stream name to check!,hod,Error!) | halt }
if ($sock(shoutcheck) != $null) { var %err = $input(Please wait until the other connection is closed!,hod,Error!) | halt }
set %sc.url $gettok($readini(sservers.ini,streams,$replace($did(1).seltext,$chr(160),_)),1,58)
set %sc.port $gettok($readini(sservers.ini,streams,$replace($did(1).seltext,$chr(160),_)),2,58)
if (%sc.port !isnum 0-65535) { var %err = $input(This stream has an invalid port!,hod,Error!) | halt }
set %sc.streamname $did(1).seltext
sockopen shoutcheck %sc.url %sc.port
}
if ($did == 20) { clipboard $chr(91) $+ %sc.streamname $+ $chr(93) $+ : Playing " $+ %sc.song $+ " to %sc.current ( $+ %sc.unique unique) listeners at %sc.bitrate $+ . (Peak: %sc.peak Max: %sc.max $+ ) | halt }
if ($did == 21) { .sockclose shoutcheck | dialog -x shoutcast | halt }
}
;Check when double clicking @ list menu
if ($devent == dclick) && ($did == 1) {
;When clicking the Check button
if ($did(1).seltext == $null) { var %err = $input(You have not selected a stream name to check!,hod,Error!) | halt }
if ($sock(shoutcheck) != $null) { var %err = $input(Please wait until the other connection is closed!,hod,Error!) | halt }
set %sc.url $gettok($readini(sservers.ini,streams,$replace($did(1).seltext,$chr(160),_)),1,58)
set %sc.port $gettok($readini(sservers.ini,streams,$replace($did(1).seltext,$chr(160),_)),2,58)
if (%sc.port !isnum 0-65535) { var %err = $input(This stream has an invalid port!,hod,Error!) | halt }
set %sc.streamname $did(1).seltext
sockopen shoutcheck %sc.url %sc.port
}
}
alias shout.reloadlist {
;Listing stream aliases in dialog
set %sload.temp 1
did -r shoutcast 1
:loadservers
inc %sload.temp 1
if (%sload.temp > $lines(sservers.ini)) { goto endload }
did -a shoutcast 1 $replace($gettok($read(sservers.ini,%sload.temp),1,61),_,$chr(160))
goto loadservers
:endload
halt
}
on *:sockopen:shoutcheck:{
;Socket has been opened...
if ($sockerr > 1) { var %err = $input(Could not connect to the stream!,hod,Error!) | sockclose $sockname | halt }
sockwrite -n $sockname GET /7 HTTP/1.0
sockwrite -n $sockname User-Agent:Mozilla
sockwrite -n $sockname
}
on *:sockread:shoutcheck:{
;Gathering stream information
sockread &stream
set %stream $remove($gettok($bvar(&stream,1-).text,5,62),</body)
set %sc.current $gettok(%stream,1,44)
set %sc.peak $gettok(%stream,3,44)
set %sc.max $gettok(%stream,4,44)
set %sc.unique $gettok(%stream,5,44)
set %sc.bitrate $gettok(%stream,6,44) $+ kbps
set %sc.song $gettok(%stream,7-,44)
;Processing stream info to dialog
did -ra shoutcast 9 %sc.song
did -ra shoutcast 10 %sc.current
did -ra shoutcast 12 %sc.unique
did -ra shoutcast 14 %sc.peak
did -ra shoutcast 16 %sc.max
did -ra shoutcast 18 %sc.bitrate
sockclose $sockname
halt
}