Jump to content

Shoutcast 977 Player


Foxhound
 Share

Recommended Posts

977 The Hitz Player

This is a little player I wrote that connects to the .977 Hitz Internet Radio

A lot of the functions can be cleaned up a bit but this will have to do for now.

You are welcome to edit and redistribute this source as much as you like.

Posted Image

Features:

  • Automatically fetches and displays lyrics and cover art using Chart Lyrics API
  • Custom lyric search. New

Controls:

  • ESC - Exit
  • F5 - Refresh now playing song
  • F6 - Display cover art and lyrics if available

Issues:

  • The song updates slowly because of Shoutcast's website updates their current song music slowly as well Fixed
  • the ieObj and LyricObj may linger in some cases(iexplore.exe)Fixed
  • My display wrong cover art/lyric information. There is nothing I can do about that.
  • Issue with passing variables to lyrics chart url Fixed

This is one of the first "serious" scripts that I have done in AutoIT so go easy on me. ;)

Suggestions and comments are welcome!

Source:

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.3.6.1
    Author:          Foxhound
    
    Script Function:
    Shoutcast player.
    This is a little player I wrote that connects to the .977 Hitz Internet Radio
    Station and fetches the artist name and song as well as lyrics and cover art using Chart Lyrics API (if it exists)
    A lot of the functions can be cleaned up a bit but this will have to do for now.
    You are welcome to edit and redistribute this source as much as you like.
    
    
#ce ----------------------------------------------------------------------------
AutoItSetOption("TrayAutoPause", 0)
HotKeySet("{ESC}", "abort")
HotKeySet("{F5}", "refresh")
HotKeySet("{F6}", "_lyricGUI")
Global $lyricData, $coverData, $ieObj, $author, $song, $metaObj, $lyricGUIData[2]
#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#Region ### START Koda GUI section ### Form=c:\users\homepc\desktop\lyricgui.kxf
$Form1_1 = GUICreate("Lyrics", 640, 370)
;$Group1 = GUICtrlCreateGroup("lol - wtf", 8, 72, 401, 273)
$Pic1 = GUICtrlCreatePic("", 32, 88, 345, 241, BitOR($SS_NOTIFY, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS, $GUI_ONTOP))
$Label1 = GUICtrlCreateLabel("No Image Available", 150, 176, 200, 36)
$Label2 = GUICtrlCreateLabel("", 8, 40, 150, 17)
$Edit1 = GUICtrlCreateEdit("", 432, 77, 177, 265, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_CENTER, $ES_READONLY))
$Button1 = GUICtrlCreateButton("Close", 240, 32, 75, 25, $WS_GROUP)
GUICtrlSetState($Label1, $GUI_HIDE)
#EndRegion ### END Koda GUI section ###
MsgBox(0, ".977 Player", "Press ESC to exit," & @CRLF & "Press F5 to refresh song title." & @CRLF & "Press F6 to fetch lyrics to current song." & @CRLF & "Note: The lyric function is imperfect and you may get the wrong lyrics or none at all")
TrayTip("", "Loading player...please wait", 10)
play()
Func play()
    $url = "http://www.shoutcast.com/shoutcast-cdn/flash/popupPlayer_V19.swf?stationid=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1280356&play_status=1"
    If IsObj($ieObj) == 0 Then
        $ieObj = _IECreate($url, 0, 0, 0) ;song stream
        TrayTip(".977 Player", "Current Song: " & getTitle(), 10, 1)
    EndIf
    While 1
        Sleep(60000)
    WEnd
EndFunc   ;==>play
Func abort()
    _IEQuit($ieObj)
    _IEQuit($metaObj)
    Exit
EndFunc   ;==>abort
Func getTitle()
    ;Fetch the title of the song playing embedded deep inside the html source code of Shoutcasts home page.
    ;The alternative was pulling this information from their Flash Object, but seeing as I can't figure out how to
    ;pull text from flash, this will have to do. This method also explains why the song info updates a lot slower.
    ;UPDATE: This issue has now been fixed by using http://205.188.215.230:8002/index.html
    If IsObj($metaObj) == 0 Then
        $metaObj = _IECreate("http://205.188.215.230:8002/index.html", 0, 0)
    EndIf
    _IENavigate($metaObj, "http://205.188.215.230:8002/index.html")
    While 1
        $source = _IEBodyReadText($metaObj) ;FIXME
        $tar = _StringBetween2($source, "Current Song: ", "Written")
        If StringLen($tar) <> 0 Then ExitLoop
    WEnd

    Return ($tar)
EndFunc   ;==>getTitle
Func _StringBetween2($s, $from, $to)
    ;This helpful function taken from: http://www.autoitscript.com/forum/index.php?sho wtopic=89554
    $x = StringInStr($s, $from) + StringLen($from)
    $y = StringInStr(StringTrimLeft($s, $x), $to)
    Return StringMid($s, $x, $y)
EndFunc   ;==>_StringBetween2
Func refresh()
    TrayTip(".977 Player", "Updating", 10, 1)
    TrayTip(".977 Player - Refreshed", "Current Song: " & getTitle(), 10, 1)
EndFunc   ;==>refresh

Func getLyrics()

    ;----------------Alter for correct song/title format (Artist - Song Name) ------------------------------------------------------------------
    TrayTip(".977 Player", "Fetching Lyrics", 10, 1)
    $lyricArray = StringSplit(getTitle(), "-")
    If @error = 1 Then
        MsgBox(16, "", "Error parsing lyrics data. Malformed Track/Song name")
        play()
        ;note $lyricArray[1] = Artist $lyricArray[2] = Song
    ElseIf IsArray($lyricArray) Then
        $author = $lyricArray[1]
        $song = $lyricArray[2]
    Else
        MsgBox(16, "", "Unable to retrieve lyrics/song name")
        play()
    EndIf
    ;---------------------------
    $lyricURL = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=" & $author & "&song=" & $song
    If IsObj($metaObj) == 0 Then
        $metaObj = _IECreate($lyricURL, 0, 0)
    EndIf
    _IENavigate($metaObj, $lyricURL)
    $lyricData = _StringBetween2(_IEBodyReadText($metaObj), "<Lyric>", "</Lyric>")
    $coverData = _StringBetween2(_IEBodyReadText($metaObj), "<LyricCovertArtUrl>", "</LyricCovertArtUrl>")
    If StringLen($lyricData) == 0 Then $lyricData = "Lyrics not found."
    $lyricGUIData[0] = $coverData
    $lyricGUIData[1] = $lyricData
    If IsArray($lyricGUIData) == 0 Then
        Return (999)
    Else
        Return ($lyricGUIData)
    EndIf
EndFunc   ;==>getLyrics
Func _lyricGUI()
    GUICtrlSetState($Label1, $GUI_HIDE)
    GUICtrlSetState($Label2, $GUI_ONTOP)
    GUICtrlSetData($Label2, getTitle())
    ;catch nonarray returns
    If getLyrics() == 999 Then
        MsgBox(0, "", "Error fetching lyrics")
        play()
    EndIf
    GUISetState(@SW_SHOW)
    ;array 0 = cover art url
    ;array 1 = lyrics
    If FileExists(@TempDir & "\coverData.jpg") Then FileDelete(@TempDir & "\coverData.jpg")
    GUICtrlSetData($Edit1, $lyricData)
    InetGet($coverData, @TempDir & "\coverData.jpg", 0, 0)
    If Not FileExists(@TempDir & "\coverData.jpg") Then
        GUICtrlSetState($Label1, $GUI_SHOW)
        ;MsgBox(0, "", "reached code - then")
    Else
        ;MsgBox(0, "", "reached code - else")
        GUICtrlSetImage($Pic1, @TempDir & "\coverData.jpg")
    EndIf
    While 1
        $nMsg = GUIGetMsg()
        If $nMsg == $GUI_EVENT_CLOSE Then
            GUICtrlSetState($Label1, $GUI_HIDE)
            GUISetState(@SW_HIDE)

            play()
        ElseIf $nMsg = $Button1 Then
            GUICtrlSetState($Label1, $GUI_HIDE)
            GUISetState(@SW_HIDE)
            play()
        EndIf
    WEnd
EndFunc   ;==>_lyricGUI

DOWNLOAD:

Last Updated 09/06/2010

SC 977 Player.au3

Edited by Foxhound
Link to comment
Share on other sites

Ah, you found it. Take a look into the General and Help support forum. I found a few things, not what you wanted though.

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Thanks guys!

AlmarM, the last address you listed connects to the Shoutcast 977 radio server which updates immediately. I pointed my script to that site now and now the songs should update faster.

Thank you!

Same problem that your lyrics finder !

"ProcessClose("iexplore.exe") ;use this if you have issues with song still playing after script closes."

And will you add several radio stations ? Posted Image

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

Link to comment
Share on other sites

Same problem that your lyrics finder !

"ProcessClose("iexplore.exe") ;use this if you have issues with song still playing after script closes."

And will you add several radio stations ? Posted Image

Yeah I'm planning to add more radio stations. As for the "close windows with string" function you gave me, it worked but there was still an iexplore process still open. I'll get back to you if I find a solution.

Link to comment
Share on other sites

Yeah I'm planning to add more radio stations. As for the "close windows with string" function you gave me, it worked but there was still an iexplore process still open. I'll get back to you if I find a solution.

You're right !

I have add _CloseWindowWithString ( 'shoutcast.com' ) at the abort function

then the windows is well close but the process exists !

It's strange Posted Image

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

Link to comment
Share on other sites

I find the error Posted Image

_CloseWindowWithString ( 'shoutcast.com' )
    _CloseWindowWithString ( 'SHOUTcast Administrator' )    
    _CloseWindowWithString ( 'api.chartlyrics.com' )

Add this to abort function and it works fine...

Do you know this shoutcast radio with differents styles http://www.shoutcast.com/Internet-Radio/big%20r

Edited by wakillon

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...