Sign in to follow this  
Followers 0
karman

Getting current song from a SC server

6 posts in this topic

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 :-)

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by karman

Share this post


Link to post
Share on other sites

t.t updated it a little bit. enjoy..

Share this post


Link to post
Share on other sites

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 : Posted Image

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 :

Func _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.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#5 ·  Posted (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". :x

Edited by Manadar

Share this post


Link to post
Share on other sites

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". :x

Ok, so it's the update that was forgotten ! Posted Image

Now works well !


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0