Jump to content



Photo

Shoutcast 977 Player


  • Please log in to reply
9 replies to this topic

#1 Foxhound

Foxhound

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 28 August 2010 - 02:39 AM

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:
AutoIt         
#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 = "<a href='http://www.shoutcast.com/shoutcast-cdn/flash/popupPlayer_V19.swf?stationid=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1280356&play_status=1' class='bbc_url' title='External link' rel='nofollow external'>http://www.shoutcast.com/shoutcast-cdn/flash/popupPlayer_V19.swf?stationid=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1280356&play_status=1"</a>     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 <a href='http://205.188.215.230:8002/index.html' class='bbc_url' title='External link' rel='nofollow external'>http://205.188.215.230:8002/index.html</a>     If IsObj($metaObj) == 0 Then         $metaObj = _IECreate("<a href='http://205.188.215.230:8002/index.html' class='bbc_url' title='External link' rel='nofollow external'>http://205.188.215.230:8002/index.html"</a>, 0, 0)     EndIf     _IENavigate($metaObj, "<a href='http://205.188.215.230:8002/index.html' class='bbc_url' title='External link' rel='nofollow external'>http://205.188.215.230:8002/index.html"</a>)     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: <a href='http://www.autoitscript.com/forum/index.php?sho' class='bbc_url' title=''>http://www.autoitscript.com/forum/index.php?sho</a> 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 = "<a href='http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=' class='bbc_url' title='External link' rel='nofollow external'>http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist="</a> & $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
Attached File  SC 977 Player.au3   5.83K   367 downloads

Edited by Foxhound, 06 September 2010 - 06:25 PM.






#2 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 28 August 2010 - 07:52 AM

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

#3 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,481 posts

Posted 28 August 2010 - 10:59 AM

Thanks, it works fine !

I have try with "http://www.bigrradio.com/flash/radioPlayer2.php?id=40"

and it works too ! Posted Image

you should put your hotkeyset at the top of script and add several radio Posted Image

Edited by wakillon, 28 August 2010 - 11:01 AM.

  AutoIt Version : 3.3.8.1/3.3.9.4 SciTE 3.3.0 Language:040C OS:WIN_7/ CPU:X64 OS:X64 

  Last updated Scripts and executables with full embedded files are available on : GoogleCode 


#4 Foxhound

Foxhound

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 28 August 2010 - 03:42 PM

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!

#5 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,481 posts

Posted 30 August 2010 - 08:26 AM

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 Version : 3.3.8.1/3.3.9.4 SciTE 3.3.0 Language:040C OS:WIN_7/ CPU:X64 OS:X64 

  Last updated Scripts and executables with full embedded files are available on : GoogleCode 


#6 Foxhound

Foxhound

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 30 August 2010 - 08:34 PM

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.

#7 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,481 posts

Posted 30 August 2010 - 09:52 PM

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 Version : 3.3.8.1/3.3.9.4 SciTE 3.3.0 Language:040C OS:WIN_7/ CPU:X64 OS:X64 

  Last updated Scripts and executables with full embedded files are available on : GoogleCode 


#8 Foxhound

Foxhound

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 31 August 2010 - 01:08 AM

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



The only solution is to use ProcessClose() ;)

#9 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,481 posts

Posted 31 August 2010 - 10:13 AM

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, 31 August 2010 - 10:24 AM.

  AutoIt Version : 3.3.8.1/3.3.9.4 SciTE 3.3.0 Language:040C OS:WIN_7/ CPU:X64 OS:X64 

  Last updated Scripts and executables with full embedded files are available on : GoogleCode 


#10 Foxhound

Foxhound

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 06 September 2010 - 06:58 AM

Ok I finally fixed the opened objects issue. _IEQUit worked. I also updated the lyrics GUI.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users