karman Posted September 3, 2006 Posted September 3, 2006 Hey, I've written a cool irc bot in AutoIt and I have only one problem now. I want it to read the current song from my SHOUTCast server. My first idea was to use InetGet() and get the htmlsource and read it from there. But it does NOT work. It says: ICY 404 Resource Not Found icy-notice1:<BR>SHOUTcast Distributed Network Audio Server/win32 v1.9.7<BR> icy-notice2:The resource requested was not found<BR> Any ideas how to get around this? Thanks :-)
karman Posted September 3, 2006 Author Posted September 3, 2006 (edited) After some "Googling" and lot's of tries with different errors and shit, i got this code together: func getsong($host, $port = 8000, $timeout = 300) $timer = TimerInit() $shoutcast = TCPConnect($host, $port) if $shoutcast = -1 Then return 0 ; unable to connect endif TCPSend($shoutcast, "GET / HTTP/1.0" & @CRLF & "Icy-MetaData:1" & @CRLF & @CRLF) while(1) $recv = TCPRecv($shoutcast, 1024) Sleep(1) If StringInStr($recv, "StreamTitle=") Then $title = StringSplit($recv, "StreamTitle=", 1) $title = StringSplit($title[2], ";StreamUrl=",1) TCPCloseSocket($shoutcast) return $title[1] EndIf if TimerDiff($timer) > $timeout Then Return "N/A" ; no song playing / timeout TCPCloseSocket($shoutcast) EndIf WEnd EndFunc It will return the current song played on the Shoutcast server you specify =) Have fun (if anyone will ever use this) Edited October 4, 2007 by karman
wakillon Posted December 30, 2010 Posted December 30, 2010 It will return the current song played on the Shoutcast server you specify =) Have fun (if anyone will ever use this) Old Topic but always interesting ! I wanted to use it but you forget BinaryToString func ! So Updated : Func _GetCurrentSong ( $_Host, $_Port=8000, $_TimeOut=1500 ) TCPStartUp ( ) Local $_Timer = TimerInit ( ), $_Shoutcast = TCPConnect ( $_Host, $_Port ) If $_Shoutcast = -1 Then TCPShutdown ( ) Return 0 EndIf TCPSend ( $_Shoutcast, "GET / HTTP/1.0" & @CRLF & "Icy-MetaData:1" & @CRLF & @CRLF ) While 1 $_Recv = BinaryToString ( TCPRecv ( $_Shoutcast, 1024 ) ) If $_Recv <> '' Then If StringInStr ( $_Recv, "StreamTitle=" ) Then $_CurrentSong = StringSplit ( $_Recv, "StreamTitle=", 1 ) $_CurrentSong = StringSplit ( $_CurrentSong[2], ";StreamUrl=", 1 ) TCPCloseSocket ( $_Shoutcast ) TCPShutdown ( ) Return _StringProper ( StringReplace ( $_CurrentSong[1], "'", "" ) ) EndIf EndIf If TimerDiff ( $_Timer ) > $_TimeOut Then TCPCloseSocket ( $_Shoutcast ) TCPShutdown ( ) Return "N/A" EndIf WEnd EndFunc ;==> _GetCurrentSong ( ) or with more infos : expandcollapse popupFunc _GetShoutcastRadioInfos ( $_Host, $_Port=8000, $_TimeOut=1500 ) TCPStartUp ( ) Local $_Timer = TimerInit ( ), $_Shoutcast = TCPConnect ( $_Host, $_Port ) Dim $_ArrayInfo[7] If $_Shoutcast = -1 Then TCPShutdown ( ) Return 0 EndIf TCPSend ( $_Shoutcast, "GET / HTTP/1.0" & @CRLF & "Icy-MetaData:1" & @CRLF & @CRLF ) While 1 $_Recv = BinaryToString ( TCPRecv ( $_Shoutcast, 1024 ) ) If $_Recv <> '' Then If StringInStr ( $_Recv, "icy-name:" ) Then $_Info = _StringBetween ( $_Recv, "icy-name:", @CR ) If Not @error And Not $_ArrayInfo[1] Then $_ArrayInfo[1]=$_Info[0] EndIf If StringInStr ( $_Recv, "icy-genre:" ) Then $_Info = _StringBetween ( $_Recv, "icy-genre:", @CR ) If Not @error And Not $_ArrayInfo[2] Then $_ArrayInfo[2]=$_Info[0] EndIf If StringInStr ( $_Recv, "icy-url:" ) Then $_Info = _StringBetween ( $_Recv, "icy-url:", @CR ) If Not @error And Not $_ArrayInfo[3] Then $_ArrayInfo[3]=$_Info[0] EndIf If StringInStr ( $_Recv, "content-type:" ) Then $_Info = _StringBetween ( $_Recv, "content-type:", @CR ) If Not @error And Not $_ArrayInfo[4] Then $_ArrayInfo[4]=$_Info[0] EndIf If StringInStr ( $_Recv, "icy-br:" ) Then $_Info = _StringBetween ( $_Recv, "icy-br:", @CR ) If Not @error And Not $_ArrayInfo[5] Then $_ArrayInfo[5]=$_Info[0] EndIf If StringInStr ( $_Recv, "StreamTitle=" ) Then $_CurrentSong = StringSplit ( $_Recv, "StreamTitle=", 1 ) $_CurrentSong = StringSplit ( $_CurrentSong[2], ";StreamUrl=", 1 ) TCPCloseSocket ( $_Shoutcast ) $_ArrayInfo[6]=StringReplace ( $_CurrentSong[1], "'", "" ) $_ArrayInfo[0]=UBound ( $_ArrayInfo ) -1 TCPShutdown ( ) Return $_ArrayInfo EndIf EndIf If TimerDiff ( $_Timer ) > $_TimeOut Then TCPCloseSocket ( $_Shoutcast ) TCPShutdown ( ) Return 0 EndIf WEnd EndFunc ;==> _GetShoutcastRadioInfos ( ) AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
jvanegmond Posted December 30, 2010 Posted December 30, 2010 (edited) wakilon, the post is from 2006. BinaryToString wasn't added until halfway 2007, and even then it was unnecessary because TCPRecv did not return in Binary form. So not "forgotten". Edited December 30, 2010 by Manadar github.com/jvanegmond
wakillon Posted December 30, 2010 Posted December 30, 2010 wakilon, the post is from 2006. BinaryToString wasn't added until halfway 2007, and even then it was unnecessary because TCPRecv did not return in Binary form. So not "forgotten". Ok, so it's the update that was forgotten ! Now works well ! AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now